Version Description
- Improved UI for better user experience
- Export/Import options: via a pre-saved template or a quick(standard columns) export/import
- Option to export/import selective columns
- Option to reorder columns during export
- Import: Support for different types of delimiters
- Export/Import options: Batch option with configurable batch count
- History of all the Import/Export process
- Dedicated logs for debugging failures
Download this release
Release Info
Developer | webtoffee |
Plugin | Order Export & Order Import for WooCommerce |
Version | 2.0.0 |
Comparing to | |
See all releases |
Code changes from version 1.7.6 to 2.0.0
- Sample_Coupon.csv +0 -2
- Sample_Order.csv +0 -7
- Sample_Subscription.csv +0 -3
- admin/class-wt-import-export-for-woo-admin.php +365 -0
- admin/classes/class-csvreader.php +252 -0
- admin/classes/class-csvwriter.php +160 -0
- admin/classes/class-log.php +105 -0
- admin/classes/class-logreader.php +113 -0
- admin/classes/class-logwriter.php +97 -0
- admin/css/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- admin/css/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- admin/css/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- admin/css/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- admin/css/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- admin/css/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- admin/css/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- admin/css/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- admin/css/images/ui-icons_222222_256x240.png +0 -0
- admin/css/images/ui-icons_2e83ff_256x240.png +0 -0
- admin/css/images/ui-icons_454545_256x240.png +0 -0
- admin/css/images/ui-icons_888888_256x240.png +0 -0
- admin/css/images/ui-icons_cd0a0a_256x240.png +0 -0
- admin/css/jquery-ui.css +470 -0
- admin/css/select2.css +1 -0
- admin/css/wt-import-export-for-woo-admin.css +445 -0
- admin/index.php +1 -0
- admin/js/dropzone.min.js +1 -0
- admin/js/select2.js +1 -0
- admin/js/tiptip.js +1 -0
- admin/js/wt-import-export-for-woo-admin.js +724 -0
- admin/modules/coupon/coupon.php +514 -0
- includes/exporter/data/data-wf-post-columns-coupon.php → admin/modules/coupon/data/data-coupon-post-columns.php +3 -3
- admin/modules/coupon/data/data/data-wf-reserved-fields-pair.php +29 -0
- admin/modules/coupon/export/export.php +265 -0
- admin/modules/coupon/import/import.php +893 -0
- admin/modules/export/assets/js/main.js +906 -0
- admin/modules/export/classes/class-export-ajax.php +707 -0
- admin/modules/export/export.php +814 -0
- admin/modules/export/views/_export_advanced_page.php +52 -0
- admin/modules/export/views/_export_filter_page.php +15 -0
- admin/modules/export/views/_export_footer.php +73 -0
- admin/modules/export/views/_export_header.php +15 -0
- admin/modules/export/views/_export_mapping_page.php +96 -0
- admin/modules/export/views/_export_mapping_tr_html.php +20 -0
- admin/modules/export/views/_export_meta_step_page.php +56 -0
- admin/modules/export/views/_export_method_export_page.php +90 -0
- admin/modules/export/views/_export_post_type_page.php +30 -0
- admin/modules/export/views/main.php +64 -0
- admin/modules/history/assets/js/main.js +196 -0
- admin/modules/history/history.php +857 -0
- admin/modules/history/views/_history_list.php +198 -0
- admin/modules/history/views/_log_list.php +74 -0
- admin/modules/history/views/_log_table.php +80 -0
- admin/modules/history/views/settings.php +46 -0
- admin/modules/import/assets/js/main.js +1453 -0
- admin/modules/import/classes/class-import-ajax.php +1215 -0
- admin/modules/import/import.php +1282 -0
- admin/modules/import/views/_import_advanced_page.php +25 -0
- admin/modules/import/views/_import_footer.php +73 -0
- admin/modules/import/views/_import_header.php +15 -0
- admin/modules/import/views/_import_mapping_page.php +281 -0
- admin/modules/import/views/_import_mapping_tr_html.php +20 -0
- admin/modules/import/views/_import_meta_step_page.php +43 -0
- admin/modules/import/views/_import_method_import_page.php +75 -0
- admin/modules/import/views/_import_post_type_page.php +31 -0
- admin/modules/import/views/main.php +70 -0
- includes/exporter/data/data-wf-post-columns.php → admin/modules/order/data/data-order-post-columns.php +4 -6
- admin/modules/order/data/data-wf-exclude-hidden-meta-columns.php +5 -0
- admin/modules/order/data/data-wf-hidden-meta-columns.php +5 -0
- admin/modules/order/data/data-wf-post-columns-coupon.php +35 -0
- admin/modules/order/data/data-wf-post-subscription-columns.php +87 -0
- admin/modules/order/data/data-wf-xml-default-meta.php +44 -0
- admin/modules/order/data/data/data-wf-reserved-fields-pair.php +54 -0
- admin/modules/order/export/export.php +911 -0
- admin/modules/order/import/import.php +2121 -0
- admin/modules/order/order.php +556 -0
- admin/partials/_form_field_generator.php +378 -0
- admin/partials/wt-import-export-for-woo-admin-display.php +73 -0
- admin/views/_save_template_popup.php +34 -0
- admin/views/admin-settings-advanced.php +20 -0
- admin/views/admin-settings-debug.php +8 -0
- admin/views/admin-settings-help.php +42 -0
- admin/views/admin-settings-save-button.php +20 -0
- assets/images/documentation.png +0 -0
- assets/images/drag_icon.png +0 -0
- assets/images/loading.gif +0 -0
- images/csv.png → assets/images/sample-csv.png +0 -0
- assets/images/support.png +0 -0
- helpers/class-wt-common-helper.php +287 -0
- helpers/class-wt-import-export-helper.php +223 -0
- helpers/class-wt-security-helper.php +209 -0
- images/Order-Import-Export-for-WooCommerce-Image.png +0 -0
- images/calendar.png +0 -0
- images/documentation.png +0 -0
- images/storefrog.png +0 -0
- images/webtoffee-logo_small.png +0 -0
- images/wf-ajax-loader.gif +0 -0
- images/wf-failed.png +0 -0
- images/wf-import.png +0 -0
- images/wf-notice.png +0 -0
- images/wf-success.png +0 -0
- includes/class-wf-cpnimpexpcsv-admin-screen.php +0 -94
- includes/class-wf-cpnimpexpcsv-ajax-handler.php +0 -20
- includes/class-wf-cpnimpexpcsv-system-status-tools.php +0 -55
- includes/class-wf-orderimpexp-plugin-review-request.php +0 -252
- includes/class-wf-orderimpexp-plugin-uninstall-feedback.php +1 -1
- includes/class-wf-orderimpexpcsv-admin-screen.php +0 -93
- includes/class-wf-orderimpexpcsv-ajax-handler.php +0 -25
- includes/class-wf-orderimpexpcsv-system-status-tools.php +0 -94
- includes/class-wt-import-export-for-woo-activator.php +160 -0
- includes/class-wt-import-export-for-woo-deactivator.php +38 -0
- includes/class-wt-import-export-for-woo-i18n.php +49 -0
- includes/class-wt-import-export-for-woo-loader.php +131 -0
- includes/class-wt-import-export-for-woo-remoteadapter.php +14 -0
- includes/class-wt-import-export-for-woo.php +331 -0
- includes/class-wt-non-apache-info.php +115 -0
- includes/class-wt-order-legacy-menu-moved.php +162 -0
- includes/exporter/class-wf-cpnimpexpcsv-exporter.php +0 -107
- includes/exporter/class-wf-orderimpexpcsv-exporter.php +0 -452
- includes/importer/class-wf-cpnimpexpcsv-coupon-import.php +0 -688
- includes/importer/class-wf-cpnimpexpcsv-importer.php +0 -41
- includes/importer/class-wf-csv-parser-coupon.php +0 -175
- includes/importer/class-wf-csv-parser.php +0 -782
- includes/importer/class-wf-orderimpexpcsv-importer.php +0 -41
- includes/importer/class-wf-orderimpexpcsv-order-import.php +0 -354
Sample_Coupon.csv
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
post_title,ID,post_excerpt,post_status,post_date,post_author,discount_type,coupon_amount,individual_use,product_ids,exclude_product_ids,usage_limit,usage_limit_per_user,limit_usage_to_x_items,expiry_date,free_shipping,exclude_sale_items,product_categories,exclude_product_categories,minimum_amount,maximum_amount,customer_email,date_expires,usage_count
|
2 |
-
coupon1003,502,Not so dummy,publish,2019-01-28 10:01:21,1,percent_product,57,yes,,,10,10,3,2019-03-28,no,yes,"8,9,6","2,10,7",70,80,"patra@gmail.com, patra@hotmail.com, patra@yahoo.co.in",1553731200,0
|
|
|
|
Sample_Order.csv
DELETED
@@ -1,7 +0,0 @@
|
|
1 |
-
order_id,order_number,order_date,status,shipping_total,shipping_tax_total,fee_total,fee_tax_total,tax_total,cart_discount,order_discount,discount_total,order_total,order_currency,payment_method,shipping_method,customer_id,customer_user,customer_email,billing_first_name,billing_last_name,billing_company,billing_email,billing_phone,billing_address_1,billing_address_2,billing_postcode,billing_city,billing_state,billing_country,shipping_first_name,shipping_last_name,shipping_company,shipping_address_1,shipping_address_2,shipping_postcode,shipping_city,shipping_state,shipping_country,customer_note,shipping_items,fee_items,tax_items,coupon_items,refund_items,order_notes,download_permissions,customer_ip_address,paid_date,completed_date,line_item_1,line_item_2,line_item_3
|
2 |
-
1001,1001,16-05-2018 07:32:06,completed,10,1.8,1,0.18,3.42,0,0,0,22.42,USD,cod,Express Delivery,3,3,lilly@example.com,Lilly,Gordon,,lilly@example.com,9898989898,20 Maple Avenue,,90731,San Pedro,CA,US,Lilly,Gordon,,20 Maple Avenue,"Door No,16",90731,San Pedro,CA,US,Deliver with a smile!,"item:Items|value:Formal shoe X 1
|
3 |
-
",name:Gift Wrap|total:1.00|tax:0.18,code:GST-1|total:3.42,,,Order status changed from Processing to Completed.|Formal shoe (A12) stock reduced from 20 to 19.|Payment to be made upon delivery. Order status changed from Pending payment to Processing.,1,::1,2020-03-19 06:40:32,2020-03-19 06:40:32,name:Formal shoe|product_id:13|sku:A12|quantity:1|total:8.00|tax:1.44,,
|
4 |
-
1002,1002,16-05-2018 07:25:28,on-hold,10,1.8,0,0,5.04,0,0,0,33.04,USD,paypal,Express Delivery,0,0,,John,Edward,,john@example.com,9999999,300 BOYLSTON AVE E,,98102,Seattle,WA,US,John,Edward,,300 BOYLSTON AVE E,,98102,Seattle,WA,US,,"item:Items|value:Washing machine X 1
|
5 |
-
",,code:GST-1|total:5.04,,amount:46.00|reason:refund|date:2019-06-19 12:13:48,Order status changed from Pending payment to Processing.|Washing machine (A15) stock reduced from 30 to 29.|IPN payment completed,1,::1,,,name:Washing machine|product_id:616773451|sku:A15|quantity:1|total:18.00|tax:3.24,,
|
6 |
-
1003,1003,16-05-2018 07:21:32,processing,10,1.8,0,0,8.99,10,10,10,58.98,USD,eh_stripe_pay,Express Delivery,2,2,mark@example.com,Mark,Xa,Xadapter,mark@example.com,9898989898,20 Maple Avenue,,90731,San Pedro,CA,US,Mark,Xa,Xadapter,20 Maple Avenue,,90731,San Pedro,CA,US,,"item:Items|value:LED TV X 1, Samsung Galaxy Ace Duos X 1, Men's Cotton T-Shirt - Red X 1
|
7 |
-
",,code:GST-1|total:8.99,code:flat20|amount:10.00,,"Order status changed from Pending payment to Processing.|LED TV (A13) stock reduced from 19 to 18.|Samsung Galaxy Ace Duos (A11) stock reduced from 10 to 9.|Men's Cotton T-Shirt - Red (B11V2)<span class=""description""></span> stock reduced from 9 to 8.|Payment Status : Succeeded [ 2018-05-16 12:51:06 ] . Source : Visa( credit ). Charge Status :Captured. Transaction ID : txn_1CSJwcJ91uK4qPibEmTjip6P:is_customer_note",1,::1,,,name:LED TV|product_id:616773447|sku:A13|quantity:1|total:23.19|tax:4.17,name:Samsung Galaxy Ace Duos|product_id:616773443|sku:A11|quantity:1|total:8.80|tax:1.58,name:Men's Cotton T-Shirt|product_id:616773455|sku:B11V2|quantity:1|total:8.00|color:Red|_variation_id:616773455|tax:1.44
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sample_Subscription.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
subscription_id,subscription_status,customer_id,customer_username,customer_email,start_date,trial_end_date,next_payment_date,last_payment_date,end_date,post_parent,billing_period,billing_interval,order_shipping,order_shipping_tax,fee_total,fee_tax_total,order_tax,cart_discount,cart_discount_tax,order_total,order_currency,payment_method,payment_method_title,payment_method_post_meta,payment_method_user_meta,shipping_method,billing_first_name,billing_last_name,billing_email,billing_phone,billing_address_1,billing_address_2,billing_postcode,billing_city,billing_state,billing_country,billing_company,shipping_first_name,shipping_last_name,shipping_address_1,shipping_address_2,shipping_postcode,shipping_city,shipping_state,shipping_country,shipping_company,customer_note,order_items,order_notes,coupon_items,fee_items,tax_items,download_permissions
|
2 |
-
87,wc-active,2,mark,mark@xadapter.com,2016-08-30 07:22:27,2016-09-04 07:22:27,2016-09-04 07:22:27,2016-08-30 07:22:32,2016-12-04 07:22:27,86,month,1,0,0,0,0,0,0,0,9,USD,stripe,Credit card (Stripe),,,,Mark,Wough,mark@xadapter.com,74747474,1st Ave,San Deigo,90001,Naples,AL,US,MarkCO LTD,Steve,Wough,1st Ave,San Deigo,90001,Naples,AL,US,MarkCO LTD,,product_id:10|name:Test Subscription Prdocut|quantity:1|total:9.00|meta:|tax:0.00,Payment received.,,,,1
|
3 |
-
89,wc-on-hold,9,elvin,elvin@wooforce.com,2016-08-25 19:28:19,2016-08-30 19:28:19,2016-08-30 19:28:19,2016-08-31 06:18:25,2016-11-30 19:28:19,88,month,1,0,0,0,0,0,0,0,9,USD,stripe,Credit card (Stripe),,,,Elvin,j,elvin@xadapter.com,74747474,1st Ave,Naples,90001,Naples,AL,US,MarkCO LTD,Mark,Wough,1st Ave,Naples,90001,Naples,AL,US,ElvinCO LTD,Just checking Elvin Placed the Order,product_id:10|name:Test Subscription Prdocut|quantity:1|total:9.00|meta:|tax:0.00,"Payment failed.;Order <a href=""http://localhost/latestpress/wp-admin/post.php?post=233&action=edit"">#233</a> created to record renewal.;Subscription renewal payment due: Status changed from Active to On hold.;Payment received.;Status changed from Pending to Active.",code:|description:|amount:0.00,,,0
|
|
|
|
|
|
admin/class-wt-import-export-for-woo-admin.php
ADDED
@@ -0,0 +1,365 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* The admin-specific functionality of the plugin.
|
5 |
+
*
|
6 |
+
* @link https://www.webtoffee.com/
|
7 |
+
* @since 1.0.0
|
8 |
+
*
|
9 |
+
* @package Wt_Import_Export_For_Woo
|
10 |
+
* @subpackage Wt_Import_Export_For_Woo/admin
|
11 |
+
*/
|
12 |
+
|
13 |
+
/**
|
14 |
+
* The admin-specific functionality of the plugin.
|
15 |
+
*
|
16 |
+
* Defines the plugin name, version, and two examples hooks for how to
|
17 |
+
* enqueue the admin-specific stylesheet and JavaScript.
|
18 |
+
*
|
19 |
+
* @package Wt_Import_Export_For_Woo
|
20 |
+
* @subpackage Wt_Import_Export_For_Woo/admin
|
21 |
+
* @author Webtoffee <info@webtoffee.com>
|
22 |
+
*/
|
23 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Admin_Basic')){
|
24 |
+
class Wt_Import_Export_For_Woo_Admin_Basic {
|
25 |
+
|
26 |
+
/**
|
27 |
+
* The ID of this plugin.
|
28 |
+
*
|
29 |
+
* @since 1.0.0
|
30 |
+
* @access private
|
31 |
+
* @var string $plugin_name The ID of this plugin.
|
32 |
+
*/
|
33 |
+
private $plugin_name;
|
34 |
+
|
35 |
+
/**
|
36 |
+
* The version of this plugin.
|
37 |
+
*
|
38 |
+
* @since 1.0.0
|
39 |
+
* @access private
|
40 |
+
* @var string $version The current version of this plugin.
|
41 |
+
*/
|
42 |
+
private $version;
|
43 |
+
|
44 |
+
/*
|
45 |
+
* module list, Module folder and main file must be same as that of module name
|
46 |
+
* Please check the `register_modules` method for more details
|
47 |
+
*/
|
48 |
+
public static $modules=array(
|
49 |
+
'history',
|
50 |
+
'export',
|
51 |
+
'import',
|
52 |
+
);
|
53 |
+
|
54 |
+
public static $existing_modules=array();
|
55 |
+
|
56 |
+
public static $addon_modules=array();
|
57 |
+
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Initialize the class and set its properties.
|
61 |
+
*
|
62 |
+
* @since 1.0.0
|
63 |
+
* @param string $plugin_name The name of this plugin.
|
64 |
+
* @param string $version The version of this plugin.
|
65 |
+
*/
|
66 |
+
public function __construct( $plugin_name, $version ) {
|
67 |
+
|
68 |
+
$this->plugin_name = $plugin_name;
|
69 |
+
$this->version = $version;
|
70 |
+
|
71 |
+
}
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Register the stylesheets for the admin area.
|
75 |
+
*
|
76 |
+
* @since 1.0.0
|
77 |
+
*/
|
78 |
+
public function enqueue_styles() {
|
79 |
+
if(Wt_Import_Export_For_Woo_Basic_Common_Helper::wt_is_screen_allowed()){
|
80 |
+
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wt-import-export-for-woo-admin.css', array(), $this->version, 'all' );
|
81 |
+
}
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Register the JavaScript for the admin area.
|
86 |
+
*
|
87 |
+
* @since 1.0.0
|
88 |
+
*/
|
89 |
+
public function enqueue_scripts()
|
90 |
+
{
|
91 |
+
if(Wt_Import_Export_For_Woo_Basic_Common_Helper::wt_is_screen_allowed()){
|
92 |
+
/* enqueue scripts */
|
93 |
+
if(!function_exists('is_plugin_active'))
|
94 |
+
{
|
95 |
+
include_once(ABSPATH.'wp-admin/includes/plugin.php');
|
96 |
+
}
|
97 |
+
if(is_plugin_active('woocommerce/woocommerce.php'))
|
98 |
+
{
|
99 |
+
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wt-import-export-for-woo-admin.js', array( 'jquery', 'jquery-tiptip'), $this->version, false );
|
100 |
+
}else
|
101 |
+
{
|
102 |
+
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wt-import-export-for-woo-admin.js', array( 'jquery'), $this->version, false );
|
103 |
+
wp_enqueue_script(WT_IEW_PLUGIN_ID_BASIC.'-tiptip', WT_O_IEW_PLUGIN_URL.'admin/js/tiptip.js', array('jquery'), WT_O_IEW_VERSION, false);
|
104 |
+
}
|
105 |
+
|
106 |
+
$params=array(
|
107 |
+
'nonces' => array(
|
108 |
+
'main' => wp_create_nonce(WT_IEW_PLUGIN_ID_BASIC),
|
109 |
+
),
|
110 |
+
'ajax_url' => admin_url('admin-ajax.php'),
|
111 |
+
'plugin_id' =>WT_IEW_PLUGIN_ID_BASIC,
|
112 |
+
'msgs'=>array(
|
113 |
+
'settings_success'=>__('Settings updated.'),
|
114 |
+
'all_fields_mandatory'=>__('All fields are mandatory'),
|
115 |
+
'settings_error'=>__('Unable to update Settings.'),
|
116 |
+
'value_empty'=>__('Value is empty.'),
|
117 |
+
'error'=>__('Error.'),
|
118 |
+
'success'=>__('Success.'),
|
119 |
+
'loading'=>__('Loading...'),
|
120 |
+
'sure'=>__('Are you sure?'),
|
121 |
+
'use_expression'=>__('Use expression as value.'),
|
122 |
+
'cancel'=>__('Cancel'),
|
123 |
+
)
|
124 |
+
);
|
125 |
+
wp_localize_script($this->plugin_name, 'wt_iew_basic_params', $params);
|
126 |
+
}
|
127 |
+
|
128 |
+
}
|
129 |
+
|
130 |
+
/**
|
131 |
+
* Registers menu options
|
132 |
+
* Hooked into admin_menu
|
133 |
+
*
|
134 |
+
* @since 1.0.0
|
135 |
+
*/
|
136 |
+
public function admin_menu()
|
137 |
+
{
|
138 |
+
$menus=array(
|
139 |
+
'general-settings'=>array(
|
140 |
+
'menu',
|
141 |
+
__('General Settings'),
|
142 |
+
__('General Settings'),
|
143 |
+
'manage_options',
|
144 |
+
WT_IEW_PLUGIN_ID_BASIC,
|
145 |
+
array($this,'admin_settings_page'),
|
146 |
+
'dashicons-controls-repeat',
|
147 |
+
56
|
148 |
+
)
|
149 |
+
);
|
150 |
+
$menus=apply_filters('wt_iew_admin_menu_basic',$menus);
|
151 |
+
|
152 |
+
$menu_order=array("export","export-sub","import","history","history_log");
|
153 |
+
$this->wt_menu_order_changer($menus,$menu_order);
|
154 |
+
|
155 |
+
$main_menu = reset($menus); //main menu must be first one
|
156 |
+
|
157 |
+
$parent_menu_key=$main_menu ? $main_menu[4] : WT_IEW_PLUGIN_ID_BASIC;
|
158 |
+
|
159 |
+
|
160 |
+
/* adding general settings menu */
|
161 |
+
$menus['general-settings-sub']=array(
|
162 |
+
'submenu',
|
163 |
+
$parent_menu_key,
|
164 |
+
__('General Settings'),
|
165 |
+
__('General Settings'),
|
166 |
+
"manage_options",
|
167 |
+
WT_IEW_PLUGIN_ID_BASIC,
|
168 |
+
array($this, 'admin_settings_page')
|
169 |
+
);
|
170 |
+
if(count($menus)>0)
|
171 |
+
{
|
172 |
+
foreach($menus as $menu)
|
173 |
+
{
|
174 |
+
if($menu[0]=='submenu')
|
175 |
+
{
|
176 |
+
/* currently we are only allowing one parent menu */
|
177 |
+
add_submenu_page($parent_menu_key,$menu[2],$menu[3],$menu[4],$menu[5],$menu[6]);
|
178 |
+
}else
|
179 |
+
{
|
180 |
+
add_menu_page($menu[1],$menu[2],$menu[3],$menu[4],$menu[5],$menu[6],$menu[7]);
|
181 |
+
}
|
182 |
+
}
|
183 |
+
}
|
184 |
+
if(function_exists('remove_submenu_page')){
|
185 |
+
//remove_submenu_page(WT_PIEW_POST_TYPE, WT_PIEW_POST_TYPE);
|
186 |
+
}
|
187 |
+
}
|
188 |
+
|
189 |
+
public function wt_menu_order_changer( &$arr, $index_arr ) {
|
190 |
+
$arr_t = array();
|
191 |
+
foreach ( $index_arr as $i => $v ) {
|
192 |
+
foreach ( $arr as $k => $b ) {
|
193 |
+
if ( $k == $v )
|
194 |
+
$arr_t[ $k ] = $b;
|
195 |
+
}
|
196 |
+
}
|
197 |
+
$arr = $arr_t;
|
198 |
+
}
|
199 |
+
|
200 |
+
public function admin_settings_page()
|
201 |
+
{
|
202 |
+
include(plugin_dir_path( __FILE__ ).'partials/wt-import-export-for-woo-admin-display.php');
|
203 |
+
}
|
204 |
+
|
205 |
+
/**
|
206 |
+
* Save admin settings and module settings ajax hook
|
207 |
+
*/
|
208 |
+
public function save_settings()
|
209 |
+
{
|
210 |
+
$out=array(
|
211 |
+
'status'=>false,
|
212 |
+
'msg'=>__('Error'),
|
213 |
+
);
|
214 |
+
|
215 |
+
if(Wt_Iew_Sh::check_write_access(WT_IEW_PLUGIN_ID_BASIC))
|
216 |
+
{
|
217 |
+
$advanced_settings=Wt_Import_Export_For_Woo_Basic_Common_Helper::get_advanced_settings();
|
218 |
+
$advanced_fields=Wt_Import_Export_For_Woo_Basic_Common_Helper::get_advanced_settings_fields();
|
219 |
+
$validation_rule=Wt_Import_Export_For_Woo_Basic_Common_Helper::extract_validation_rules($advanced_fields);
|
220 |
+
$new_advanced_settings=array();
|
221 |
+
foreach($advanced_fields as $key => $value)
|
222 |
+
{
|
223 |
+
$form_field_name = isset($value['field_name']) ? $value['field_name'] : '';
|
224 |
+
$field_name=(substr($form_field_name,0,8)!=='wt_iew_' ? 'wt_iew_' : '').$form_field_name;
|
225 |
+
$validation_key=str_replace('wt_iew_', '', $field_name);
|
226 |
+
if(isset($_POST[$field_name]))
|
227 |
+
{
|
228 |
+
$new_advanced_settings[$field_name]=Wt_Iew_Sh::sanitize_data($_POST[$field_name], $validation_key, $validation_rule);
|
229 |
+
}
|
230 |
+
}
|
231 |
+
Wt_Import_Export_For_Woo_Basic_Common_Helper::set_advanced_settings($new_advanced_settings);
|
232 |
+
$out['status']=true;
|
233 |
+
$out['msg']=__('Settings Updated');
|
234 |
+
do_action('wt_iew_after_advanced_setting_update_basic', $new_advanced_settings);
|
235 |
+
}
|
236 |
+
echo json_encode($out);
|
237 |
+
exit();
|
238 |
+
}
|
239 |
+
|
240 |
+
/**
|
241 |
+
Registers modules: admin
|
242 |
+
*/
|
243 |
+
public function admin_modules()
|
244 |
+
{
|
245 |
+
$wt_iew_admin_modules=get_option('wt_iew_admin_modules');
|
246 |
+
if($wt_iew_admin_modules===false)
|
247 |
+
{
|
248 |
+
$wt_iew_admin_modules=array();
|
249 |
+
}
|
250 |
+
foreach (self::$modules as $module) //loop through module list and include its file
|
251 |
+
{
|
252 |
+
$is_active=1;
|
253 |
+
if(isset($wt_iew_admin_modules[$module]))
|
254 |
+
{
|
255 |
+
$is_active=$wt_iew_admin_modules[$module]; //checking module status
|
256 |
+
}else
|
257 |
+
{
|
258 |
+
$wt_iew_admin_modules[$module]=1; //default status is active
|
259 |
+
}
|
260 |
+
$module_file=plugin_dir_path( __FILE__ )."modules/$module/$module.php";
|
261 |
+
if(file_exists($module_file) && $is_active==1)
|
262 |
+
{
|
263 |
+
self::$existing_modules[]=$module; //this is for module_exits checking
|
264 |
+
require_once $module_file;
|
265 |
+
}else
|
266 |
+
{
|
267 |
+
$wt_iew_admin_modules[$module]=0;
|
268 |
+
}
|
269 |
+
}
|
270 |
+
$out=array();
|
271 |
+
foreach($wt_iew_admin_modules as $k=>$m)
|
272 |
+
{
|
273 |
+
if(in_array($k, self::$modules))
|
274 |
+
{
|
275 |
+
$out[$k]=$m;
|
276 |
+
}
|
277 |
+
}
|
278 |
+
update_option('wt_iew_admin_modules',$out);
|
279 |
+
|
280 |
+
|
281 |
+
/**
|
282 |
+
* Add on modules
|
283 |
+
*/
|
284 |
+
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
285 |
+
foreach (self::$addon_modules as $module) //loop through module list and include its file
|
286 |
+
{
|
287 |
+
$plugin_file="wt-import-export-for-woo-$module/wt-import-export-for-woo-$module.php";
|
288 |
+
if(is_plugin_active($plugin_file))
|
289 |
+
{
|
290 |
+
$module_file=WP_PLUGIN_DIR."/wt-import-export-for-woo-$module/$module/$module.php";
|
291 |
+
if(file_exists($module_file))
|
292 |
+
{
|
293 |
+
self::$existing_modules[]=$module;
|
294 |
+
require_once $module_file;
|
295 |
+
}
|
296 |
+
}
|
297 |
+
}
|
298 |
+
|
299 |
+
|
300 |
+
$addon_modules_basic = array(
|
301 |
+
'order'=>'order-import-export-for-woocommerce',
|
302 |
+
'coupon'=>'order-import-export-for-woocommerce',
|
303 |
+
'product'=>'product-import-export-for-woo',
|
304 |
+
'user'=>'users-customers-import-export-for-wp-woocommerce',
|
305 |
+
);
|
306 |
+
foreach ($addon_modules_basic as $module_key => $module_path)
|
307 |
+
{
|
308 |
+
if(is_plugin_active("{$module_path}/{$module_path}.php"))
|
309 |
+
{
|
310 |
+
$module_file=WP_CONTENT_DIR."/plugins/{$module_path}/admin/modules/$module_key/$module_key.php";
|
311 |
+
if(file_exists($module_file))
|
312 |
+
{
|
313 |
+
self::$existing_modules[]=$module_key;
|
314 |
+
require_once $module_file;
|
315 |
+
}
|
316 |
+
}
|
317 |
+
}
|
318 |
+
|
319 |
+
}
|
320 |
+
|
321 |
+
public static function module_exists($module)
|
322 |
+
{
|
323 |
+
return in_array($module, self::$existing_modules);
|
324 |
+
}
|
325 |
+
|
326 |
+
/**
|
327 |
+
* Envelope settings tab content with tab div.
|
328 |
+
* relative path is not acceptable in view file
|
329 |
+
*/
|
330 |
+
public static function envelope_settings_tabcontent($target_id,$view_file="",$html="",$variables=array(),$need_submit_btn=0)
|
331 |
+
{
|
332 |
+
extract($variables);
|
333 |
+
?>
|
334 |
+
<div class="wt-iew-tab-content" data-id="<?php echo $target_id;?>">
|
335 |
+
<?php
|
336 |
+
if($view_file!="" && file_exists($view_file))
|
337 |
+
{
|
338 |
+
include_once $view_file;
|
339 |
+
}else
|
340 |
+
{
|
341 |
+
echo $html;
|
342 |
+
}
|
343 |
+
?>
|
344 |
+
<?php
|
345 |
+
if($need_submit_btn==1)
|
346 |
+
{
|
347 |
+
include WT_O_IEW_PLUGIN_PATH."admin/views/admin-settings-save-button.php";
|
348 |
+
}
|
349 |
+
?>
|
350 |
+
</div>
|
351 |
+
<?php
|
352 |
+
}
|
353 |
+
|
354 |
+
/**
|
355 |
+
* Plugin page action links
|
356 |
+
*/
|
357 |
+
public function plugin_action_links($links)
|
358 |
+
{
|
359 |
+
$links[] = '<a href="'.admin_url('admin.php?page='.WT_IEW_PLUGIN_ID_BASIC).'">'.__('Settings').'</a>';
|
360 |
+
$links[] = '<a href="https://www.webtoffee.com/" target="_blank">'.__('Documentation').'</a>';
|
361 |
+
$links[] = '<a href="https://www.webtoffee.com/support/" target="_blank">'.__('Support').'</a>';
|
362 |
+
return $links;
|
363 |
+
}
|
364 |
+
}
|
365 |
+
}
|
admin/classes/class-csvreader.php
ADDED
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* CSV reading section of the plugin
|
4 |
+
*
|
5 |
+
* @link
|
6 |
+
*
|
7 |
+
* @package Wt_Import_Export_For_Woo
|
8 |
+
*/
|
9 |
+
if (!defined('ABSPATH')) {
|
10 |
+
exit;
|
11 |
+
}
|
12 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Basic_Csvreader')){
|
13 |
+
class Wt_Import_Export_For_Woo_Basic_Csvreader
|
14 |
+
{
|
15 |
+
public $delimiter=',';
|
16 |
+
public $fgetcsv_esc_check=0;
|
17 |
+
public function __construct($delimiter=',')
|
18 |
+
{
|
19 |
+
$this->delimiter=$delimiter;
|
20 |
+
$this->delimiter=($this->delimiter=='tab' ? "\t" : $this->delimiter);
|
21 |
+
|
22 |
+
/* version 5.3.0 onwards 5th escaping argument introduced in `fgetcsv` function */
|
23 |
+
$this->fgetcsv_esc_check = (version_compare(PHP_VERSION, '5.3.0') >= 0);
|
24 |
+
}
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Taking sample data for mapping screen preparation
|
28 |
+
* This function skip empty rows and take first two non empty rows
|
29 |
+
*/
|
30 |
+
public function get_sample_data($file, $grouping=false)
|
31 |
+
{
|
32 |
+
$enc = mb_detect_encoding($file, 'UTF-8, ISO-8859-1', true);
|
33 |
+
if($enc)
|
34 |
+
{
|
35 |
+
setlocale(LC_ALL, 'en_US.'.$enc);
|
36 |
+
}
|
37 |
+
@ini_set('auto_detect_line_endings', true);
|
38 |
+
|
39 |
+
$sample_data_key=array();
|
40 |
+
$sample_data_val=array();
|
41 |
+
$sample_data=array();
|
42 |
+
|
43 |
+
if(($handle=@fopen($file, "r"))!== false)
|
44 |
+
{
|
45 |
+
$row_count=0;
|
46 |
+
while(($row=($this->fgetcsv_esc_check) ? fgetcsv($handle, 0, $this->delimiter, '"', '"') : fgetcsv($handle, 0, $this->delimiter, '"') )!==false)
|
47 |
+
{
|
48 |
+
if(count(array_filter($row))==0)
|
49 |
+
{
|
50 |
+
continue;
|
51 |
+
}else
|
52 |
+
{
|
53 |
+
$row_count++;
|
54 |
+
}
|
55 |
+
|
56 |
+
if($row_count==1) //taking heading row
|
57 |
+
{
|
58 |
+
$sample_data_key=$row;
|
59 |
+
}else //taking data row
|
60 |
+
{
|
61 |
+
$sample_data_val=$row;
|
62 |
+
break; //only single data row needed
|
63 |
+
}
|
64 |
+
}
|
65 |
+
|
66 |
+
foreach($sample_data_key as $k => $key)
|
67 |
+
{
|
68 |
+
if(!$key)
|
69 |
+
{
|
70 |
+
continue;
|
71 |
+
}
|
72 |
+
|
73 |
+
$val=(isset($sample_data_val[$k]) ? $this->format_data_from_csv($sample_data_val[$k], $enc) : '');
|
74 |
+
|
75 |
+
/* removing BOM like non characters */
|
76 |
+
// $key=preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $key);
|
77 |
+
$key= wt_removeBomUtf8_basic($key);
|
78 |
+
if($grouping)
|
79 |
+
{
|
80 |
+
if(strrpos($key, ':')!==false)
|
81 |
+
{
|
82 |
+
$key_arr=explode(":", $key);
|
83 |
+
if(count($key_arr)>1)
|
84 |
+
{
|
85 |
+
$meta_key=$key_arr[0];
|
86 |
+
if(!isset($sample_data[$meta_key]))
|
87 |
+
{
|
88 |
+
$sample_data[$meta_key]=array();
|
89 |
+
}
|
90 |
+
$sample_data[$meta_key][$key]=$val;
|
91 |
+
}else
|
92 |
+
{
|
93 |
+
$sample_data[$key]=$val;
|
94 |
+
}
|
95 |
+
}else
|
96 |
+
{
|
97 |
+
$sample_data[$key]=$val;
|
98 |
+
}
|
99 |
+
}else
|
100 |
+
{
|
101 |
+
$sample_data[$key]=$val;
|
102 |
+
}
|
103 |
+
}
|
104 |
+
|
105 |
+
fclose($handle);
|
106 |
+
}
|
107 |
+
|
108 |
+
return $sample_data;
|
109 |
+
}
|
110 |
+
|
111 |
+
/**
|
112 |
+
* Get data from CSV as batch
|
113 |
+
*/
|
114 |
+
public function get_data_as_batch($file, $offset, $batch_count, $module_obj, $form_data)
|
115 |
+
{
|
116 |
+
// Set locale
|
117 |
+
$enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
|
118 |
+
if($enc)
|
119 |
+
{
|
120 |
+
setlocale( LC_ALL, 'en_US.' . $enc );
|
121 |
+
}
|
122 |
+
@ini_set('auto_detect_line_endings', true);
|
123 |
+
|
124 |
+
$out=array(
|
125 |
+
'response'=>false,
|
126 |
+
'offset'=>$offset,
|
127 |
+
'data_arr'=>array(),
|
128 |
+
);
|
129 |
+
|
130 |
+
if(($handle=@fopen($file, "r"))!== false)
|
131 |
+
{
|
132 |
+
/**
|
133 |
+
* taking head
|
134 |
+
*/
|
135 |
+
$head_arr=array();
|
136 |
+
while(($row=($this->fgetcsv_esc_check) ? fgetcsv($handle, 0, $this->delimiter, '"', '"') : fgetcsv($handle, 0, $this->delimiter, '"') )!==false)
|
137 |
+
{
|
138 |
+
if(count(array_filter($row))!=0) /* first non empty array */
|
139 |
+
{
|
140 |
+
$head_arr=$row;
|
141 |
+
if($offset==0) /* on first batch */
|
142 |
+
{
|
143 |
+
$offset_after_head=ftell($handle);
|
144 |
+
fseek($handle, $offset_after_head); /* skipping head row */
|
145 |
+
}
|
146 |
+
break;
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
$empty_head_columns=array();
|
151 |
+
foreach($head_arr as $head_key=>$head_val)
|
152 |
+
{
|
153 |
+
if(trim($head_val)=='')
|
154 |
+
{
|
155 |
+
$empty_head_columns[]=$head_key;
|
156 |
+
unset($head_arr[$head_key]);
|
157 |
+
}else
|
158 |
+
{
|
159 |
+
/* removing BOM like non characters */
|
160 |
+
// $head_arr[$head_key]=preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $head_val);
|
161 |
+
$head_arr[$head_key]= wt_removeBomUtf8_basic($head_val);
|
162 |
+
}
|
163 |
+
}
|
164 |
+
|
165 |
+
/* moving the pointer to corresponding batch. If not first batch */
|
166 |
+
if($offset!=0)
|
167 |
+
{
|
168 |
+
fseek($handle, $offset);
|
169 |
+
}
|
170 |
+
|
171 |
+
$out_arr=array();
|
172 |
+
|
173 |
+
$row_count=0;
|
174 |
+
/* taking data */
|
175 |
+
while(($row=($this->fgetcsv_esc_check) ? fgetcsv($handle, 0, $this->delimiter, '"', '"') : fgetcsv($handle, 0, $this->delimiter, '"') )!==false)
|
176 |
+
{
|
177 |
+
$offset=ftell($handle); /* next offset */
|
178 |
+
|
179 |
+
/*
|
180 |
+
* Skipping empty rows
|
181 |
+
*/
|
182 |
+
if(count(array_filter($row))==0)
|
183 |
+
{
|
184 |
+
continue;
|
185 |
+
}
|
186 |
+
|
187 |
+
/*
|
188 |
+
* Remove values of empty head
|
189 |
+
*/
|
190 |
+
foreach($empty_head_columns as $key)
|
191 |
+
{
|
192 |
+
unset($row[$key]);
|
193 |
+
}
|
194 |
+
|
195 |
+
/*
|
196 |
+
* Creating associative array with heading and data
|
197 |
+
*/
|
198 |
+
$row_column_count=count($row);
|
199 |
+
$head_column_count=count($head_arr);
|
200 |
+
if($row_column_count<$head_column_count)
|
201 |
+
{
|
202 |
+
$empty_row=array_fill($row_column_count, ($head_column_count-$row_column_count), '');
|
203 |
+
$row=array_merge($row, $empty_row);
|
204 |
+
$empty_row=null;
|
205 |
+
unset($empty_row);
|
206 |
+
}
|
207 |
+
elseif($row_column_count>$head_column_count)
|
208 |
+
{
|
209 |
+
$row = array_slice($row, 0, $head_column_count); //IER-209
|
210 |
+
}
|
211 |
+
|
212 |
+
/* clearing temp variables */
|
213 |
+
$row_column_count=$head_column_count=null;
|
214 |
+
unset($row_column_count, $head_column_count);
|
215 |
+
|
216 |
+
/* preparing associative array */
|
217 |
+
$data_row=array_combine($head_arr, $row);
|
218 |
+
|
219 |
+
$out_arr[]=$module_obj->process_column_val($data_row, $form_data);
|
220 |
+
//$out_arr[]=$data_row;
|
221 |
+
|
222 |
+
unset($data_row);
|
223 |
+
|
224 |
+
$row_count++;
|
225 |
+
if($row_count==$batch_count)
|
226 |
+
{
|
227 |
+
break;
|
228 |
+
}
|
229 |
+
}
|
230 |
+
fclose($handle);
|
231 |
+
|
232 |
+
$out=array(
|
233 |
+
'response'=>true,
|
234 |
+
'offset'=>$offset,
|
235 |
+
'rows_processed'=>$row_count,
|
236 |
+
'data_arr'=>$out_arr,
|
237 |
+
);
|
238 |
+
|
239 |
+
$head_arr=$form_data=$row=$out_arr=null;
|
240 |
+
unset($head_arr, $form_data, $row, $out_arr);
|
241 |
+
}
|
242 |
+
|
243 |
+
return $out;
|
244 |
+
}
|
245 |
+
|
246 |
+
protected function format_data_from_csv($data, $enc)
|
247 |
+
{
|
248 |
+
//return sanitize_text_field(( $enc == 'UTF-8' ) ? trim($data) : utf8_encode(trim($data))); sanitize_text_field stripping html content
|
249 |
+
return (( $enc == 'UTF-8' ) ? trim($data) : utf8_encode(trim($data)));
|
250 |
+
}
|
251 |
+
}
|
252 |
+
}
|
admin/classes/class-csvwriter.php
ADDED
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* CSV writing section of the plugin
|
4 |
+
*
|
5 |
+
* @link
|
6 |
+
*
|
7 |
+
* @package Wt_Import_Export_For_Woo
|
8 |
+
*/
|
9 |
+
if (!defined('ABSPATH')) {
|
10 |
+
exit;
|
11 |
+
}
|
12 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Basic_Csvwriter')){
|
13 |
+
class Wt_Import_Export_For_Woo_Basic_Csvwriter
|
14 |
+
{
|
15 |
+
public $file_path='';
|
16 |
+
public $data_ar='';
|
17 |
+
public $csv_delimiter='';
|
18 |
+
public function __construct($file_path, $offset, $csv_delimiter=",")
|
19 |
+
{
|
20 |
+
$this->csv_delimiter=$csv_delimiter;
|
21 |
+
$this->file_path=$file_path;
|
22 |
+
$this->get_file_pointer($offset);
|
23 |
+
}
|
24 |
+
|
25 |
+
/**
|
26 |
+
* This is used in XML to CSV converting
|
27 |
+
*/
|
28 |
+
public function write_row($row_data, $offset=0, $is_last_offset=false)
|
29 |
+
{
|
30 |
+
if($is_last_offset)
|
31 |
+
{
|
32 |
+
$this->close_file_pointer();
|
33 |
+
}else
|
34 |
+
{
|
35 |
+
if($offset==0) /* set heading */
|
36 |
+
{
|
37 |
+
$this->fput_csv($this->file_pointer, array_keys($row_data), $this->csv_delimiter);
|
38 |
+
}
|
39 |
+
$this->fput_csv($this->file_pointer, $row_data, $this->csv_delimiter);
|
40 |
+
}
|
41 |
+
}
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Create CSV
|
45 |
+
*
|
46 |
+
*/
|
47 |
+
public function write_to_file($export_data, $offset, $is_last_offset, $to_export)
|
48 |
+
{
|
49 |
+
$this->export_data=$export_data;
|
50 |
+
$this->set_head($export_data, $offset, $this->csv_delimiter);
|
51 |
+
$this->set_content($export_data, $this->csv_delimiter);
|
52 |
+
$this->close_file_pointer();
|
53 |
+
}
|
54 |
+
private function get_file_pointer($offset)
|
55 |
+
{
|
56 |
+
if($offset==0)
|
57 |
+
{
|
58 |
+
$this->file_pointer=fopen($this->file_path, 'w');
|
59 |
+
}else
|
60 |
+
{
|
61 |
+
$this->file_pointer=fopen($this->file_path, 'a+');
|
62 |
+
}
|
63 |
+
}
|
64 |
+
private function close_file_pointer()
|
65 |
+
{
|
66 |
+
if($this->file_pointer!=null)
|
67 |
+
{
|
68 |
+
fclose($this->file_pointer);
|
69 |
+
}
|
70 |
+
}
|
71 |
+
/**
|
72 |
+
* Escape a string to be used in a CSV context
|
73 |
+
*
|
74 |
+
* Malicious input can inject formulas into CSV files, opening up the possibility
|
75 |
+
* for phishing attacks and disclosure of sensitive information.
|
76 |
+
*
|
77 |
+
* Additionally, Excel exposes the ability to launch arbitrary commands through
|
78 |
+
* the DDE protocol.
|
79 |
+
*
|
80 |
+
* @see http://www.contextis.com/resources/blog/comma-separated-vulnerabilities/
|
81 |
+
* @see https://hackerone.com/reports/72785
|
82 |
+
*
|
83 |
+
* @param string $data CSV field to escape.
|
84 |
+
* @return string
|
85 |
+
*/
|
86 |
+
public function escape_data( $data )
|
87 |
+
{
|
88 |
+
$active_content_triggers = array( '=', '+', '-', '@' );
|
89 |
+
|
90 |
+
if ( in_array( mb_substr( $data, 0, 1 ), $active_content_triggers, true ) ) {
|
91 |
+
$data = "'" . $data;
|
92 |
+
}
|
93 |
+
|
94 |
+
return $data;
|
95 |
+
}
|
96 |
+
public function format_data( $data )
|
97 |
+
{
|
98 |
+
if ( ! is_scalar( $data ) ) {
|
99 |
+
if ( is_a( $data, 'WC_Datetime' ) ) {
|
100 |
+
$data = $data->date( 'Y-m-d G:i:s' );
|
101 |
+
} else {
|
102 |
+
$data = ''; // Not supported.
|
103 |
+
}
|
104 |
+
} elseif ( is_bool( $data ) ) {
|
105 |
+
$data = $data ? 1 : 0;
|
106 |
+
}
|
107 |
+
|
108 |
+
$use_mb = function_exists( 'mb_convert_encoding' );
|
109 |
+
|
110 |
+
if ( $use_mb ) {
|
111 |
+
$encoding = mb_detect_encoding( $data, 'UTF-8, ISO-8859-1', true );
|
112 |
+
$data = 'UTF-8' === $encoding ? $data : utf8_encode( $data );
|
113 |
+
}
|
114 |
+
|
115 |
+
return $this->escape_data( $data );
|
116 |
+
}
|
117 |
+
private function set_content($export_data, $delm=',')
|
118 |
+
{
|
119 |
+
if(isset($export_data) && isset($export_data['body_data']) && count($export_data['body_data'])>0)
|
120 |
+
{
|
121 |
+
$row_datas=array_values($export_data['body_data']);
|
122 |
+
foreach($row_datas as $row_data)
|
123 |
+
{
|
124 |
+
foreach($row_data as $key => $value)
|
125 |
+
{
|
126 |
+
$row_data[$key]=$this->format_data($value);
|
127 |
+
}
|
128 |
+
$this->fput_csv($this->file_pointer, $row_data, $delm);
|
129 |
+
}
|
130 |
+
}
|
131 |
+
}
|
132 |
+
private function set_head($export_data, $offset, $delm=',')
|
133 |
+
{
|
134 |
+
if($offset==0 && isset($export_data) && isset($export_data['head_data']) && count($export_data['head_data'])>0)
|
135 |
+
{
|
136 |
+
foreach($export_data['head_data'] as $key => $value)
|
137 |
+
{
|
138 |
+
$export_data['head_data'][$key]=$this->format_data($value);
|
139 |
+
}
|
140 |
+
$this->fput_csv($this->file_pointer, $export_data['head_data'], $delm);
|
141 |
+
}
|
142 |
+
}
|
143 |
+
private function fput_csv($fp, $row, $delm=',', $encloser='"' )
|
144 |
+
{
|
145 |
+
fputcsv($fp,$row,$delm,$encloser);
|
146 |
+
}
|
147 |
+
private function array_to_csv($arr, $delm=',', $encloser='"')
|
148 |
+
{
|
149 |
+
$fp=fopen('php://memory','rw');
|
150 |
+
foreach($arr as $row)
|
151 |
+
{
|
152 |
+
$this->fput_csv($fp, $row, $delm, $encloser);
|
153 |
+
}
|
154 |
+
rewind($fp);
|
155 |
+
$csv=stream_get_contents($fp);
|
156 |
+
fclose($fp);
|
157 |
+
return $csv;
|
158 |
+
}
|
159 |
+
}
|
160 |
+
}
|
admin/classes/class-log.php
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Log writing section of the plugin
|
4 |
+
*
|
5 |
+
* @link
|
6 |
+
*
|
7 |
+
* @package Wt_Import_Export_For_Woo
|
8 |
+
*/
|
9 |
+
if (!defined('ABSPATH')) {
|
10 |
+
exit;
|
11 |
+
}
|
12 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Basic_Log')){
|
13 |
+
class Wt_Import_Export_For_Woo_Basic_Log
|
14 |
+
{
|
15 |
+
public static $log_dir=WP_CONTENT_DIR.'/webtoffee_iew_log';
|
16 |
+
public static $history_id='';
|
17 |
+
public function __construct()
|
18 |
+
{
|
19 |
+
|
20 |
+
}
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Get given temp file path.
|
24 |
+
* If file name is empty then file path will return
|
25 |
+
*/
|
26 |
+
public static function get_file_path($file_name="")
|
27 |
+
{
|
28 |
+
if(!is_dir(self::$log_dir))
|
29 |
+
{
|
30 |
+
if(!mkdir(self::$log_dir, 0700))
|
31 |
+
{
|
32 |
+
return false;
|
33 |
+
}else
|
34 |
+
{
|
35 |
+
$files_to_create=array('.htaccess' => 'deny from all', 'index.php'=>'<?php // Silence is golden');
|
36 |
+
foreach($files_to_create as $file=>$file_content)
|
37 |
+
{
|
38 |
+
if(!file_exists(self::$log_dir.'/'.$file))
|
39 |
+
{
|
40 |
+
$fh=@fopen(self::$log_dir.'/'.$file, "w");
|
41 |
+
if(is_resource($fh))
|
42 |
+
{
|
43 |
+
fwrite($fh, $file_content);
|
44 |
+
fclose($fh);
|
45 |
+
}
|
46 |
+
}
|
47 |
+
}
|
48 |
+
}
|
49 |
+
}
|
50 |
+
return self::$log_dir.'/'.$file_name;
|
51 |
+
}
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Checks a log file created for the history entry for current day
|
55 |
+
* @param int $history_id id of history entry
|
56 |
+
* @return string/bool if file found returns file name otherwise false
|
57 |
+
*/
|
58 |
+
public static function check_log_exists_for_entry($history_id)
|
59 |
+
{
|
60 |
+
$log_dir=self::get_file_path();
|
61 |
+
$exp='~^'.$history_id.'.*\.log$~';
|
62 |
+
$files = preg_grep($exp, scandir($log_dir));
|
63 |
+
|
64 |
+
if(count($files)>0) /* file exists */
|
65 |
+
{
|
66 |
+
foreach($files as $key => $value)
|
67 |
+
{
|
68 |
+
$file_name=pathinfo($value, PATHINFO_FILENAME);
|
69 |
+
$file_name_arr=explode('_', $file_name);
|
70 |
+
$file_date_time=end($file_name_arr);
|
71 |
+
$file_date_time_arr=explode(' ', $file_date_time);
|
72 |
+
$file_time=strtotime($file_date_time_arr[0]);
|
73 |
+
if($file_time) //file time exists
|
74 |
+
{
|
75 |
+
$today=strtotime(date('Y-m-d'));
|
76 |
+
$file_time=strtotime(date('Y-m-d', $file_time));
|
77 |
+
if($today==$file_time) //file exists with the current day
|
78 |
+
{
|
79 |
+
return $value;
|
80 |
+
}
|
81 |
+
}
|
82 |
+
}
|
83 |
+
}
|
84 |
+
return false;
|
85 |
+
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Generate log file name
|
89 |
+
*
|
90 |
+
*/
|
91 |
+
public static function generate_file_name($post_type='', $action_type='', $history_id='')
|
92 |
+
{
|
93 |
+
$arr=array($history_id, $post_type);
|
94 |
+
if(defined( 'WT_IEW_CRON' )) /* this is a cron run so add a schedule prefix */
|
95 |
+
{
|
96 |
+
$arr[]='schedule';
|
97 |
+
}
|
98 |
+
$arr[]=$action_type;
|
99 |
+
$arr[]=date('Y-m-d h i s A'); /* if changing this format please consider `check_log_exists_for_entry` method */
|
100 |
+
|
101 |
+
$arr=array_filter($arr);
|
102 |
+
return implode("_", $arr).'.log';
|
103 |
+
}
|
104 |
+
}
|
105 |
+
}
|
admin/classes/class-logreader.php
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Log reading section of the plugin
|
4 |
+
*
|
5 |
+
* @link
|
6 |
+
*
|
7 |
+
* @package Wt_Import_Export_For_Woo
|
8 |
+
*/
|
9 |
+
if (!defined('ABSPATH')) {
|
10 |
+
exit;
|
11 |
+
}
|
12 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Basic_Logreader')){
|
13 |
+
class Wt_Import_Export_For_Woo_Basic_Logreader
|
14 |
+
{
|
15 |
+
private $file_path='';
|
16 |
+
private $file_pointer=null;
|
17 |
+
private $mode='';
|
18 |
+
public function __construct()
|
19 |
+
{
|
20 |
+
|
21 |
+
}
|
22 |
+
public function init($file_path, $mode="r")
|
23 |
+
{
|
24 |
+
$this->file_path=$file_path;
|
25 |
+
$this->mode=$mode;
|
26 |
+
$this->file_pointer=@fopen($file_path, 'r');
|
27 |
+
}
|
28 |
+
public function close_file_pointer()
|
29 |
+
{
|
30 |
+
if($this->file_pointer!=null)
|
31 |
+
{
|
32 |
+
fclose($this->file_pointer);
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
public function get_full_data($file_path)
|
37 |
+
{
|
38 |
+
$out=array(
|
39 |
+
'response'=>false,
|
40 |
+
'data_str'=>'',
|
41 |
+
);
|
42 |
+
$this->init($file_path);
|
43 |
+
if(!is_resource($this->file_pointer))
|
44 |
+
{
|
45 |
+
return $out;
|
46 |
+
}
|
47 |
+
$data=fread($this->file_pointer, filesize($file_path));
|
48 |
+
|
49 |
+
$this->close_file_pointer();
|
50 |
+
|
51 |
+
$out=array(
|
52 |
+
'response'=>false,
|
53 |
+
'data_str'=>$data,
|
54 |
+
);
|
55 |
+
return $out;
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Read log file as batch
|
60 |
+
* @param string path of file to read
|
61 |
+
* @param int offset in bytes. default 0
|
62 |
+
* @param int total row in a batch. default 50
|
63 |
+
* @return array response, next offset, data array, finished or not flag
|
64 |
+
*/
|
65 |
+
public function get_data_as_batch($file_path, $offset=0, $batch_count=50)
|
66 |
+
{
|
67 |
+
$out=array(
|
68 |
+
'response'=>false,
|
69 |
+
'offset'=>$offset,
|
70 |
+
'data_arr'=>array(),
|
71 |
+
'finished'=>false, //end of file reached or not
|
72 |
+
);
|
73 |
+
$this->init($file_path);
|
74 |
+
if(!is_resource($this->file_pointer))
|
75 |
+
{
|
76 |
+
return $out;
|
77 |
+
}
|
78 |
+
|
79 |
+
fseek($this->file_pointer, $offset);
|
80 |
+
$row_count=0;
|
81 |
+
$next_offset=$offset;
|
82 |
+
$finished=false;
|
83 |
+
$data_arr=array();
|
84 |
+
while(($data=fgets($this->file_pointer))!==false)
|
85 |
+
{
|
86 |
+
$data=maybe_unserialize($data);
|
87 |
+
if(is_array($data))
|
88 |
+
{
|
89 |
+
$data_arr[]=$data;
|
90 |
+
$row_count++;
|
91 |
+
$next_offset=ftell($this->file_pointer);
|
92 |
+
}
|
93 |
+
if($row_count==$batch_count)
|
94 |
+
{
|
95 |
+
break;
|
96 |
+
}
|
97 |
+
}
|
98 |
+
if($next_offset==filesize($file_path))
|
99 |
+
{
|
100 |
+
$finished=true;
|
101 |
+
}
|
102 |
+
$this->close_file_pointer();
|
103 |
+
|
104 |
+
$out=array(
|
105 |
+
'response'=>true,
|
106 |
+
'offset'=>$next_offset,
|
107 |
+
'data_arr'=>$data_arr,
|
108 |
+
'finished'=>$finished,
|
109 |
+
);
|
110 |
+
return $out;
|
111 |
+
}
|
112 |
+
}
|
113 |
+
}
|
admin/classes/class-logwriter.php
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Log writing section of the plugin
|
4 |
+
*
|
5 |
+
* @link
|
6 |
+
*
|
7 |
+
* @package Wt_Import_Export_For_Woo
|
8 |
+
*/
|
9 |
+
if (!defined('ABSPATH')) {
|
10 |
+
exit;
|
11 |
+
}
|
12 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Basic_Logwriter')){
|
13 |
+
class Wt_Import_Export_For_Woo_Basic_Logwriter extends Wt_Import_Export_For_Woo_Basic_Log
|
14 |
+
{
|
15 |
+
private static $file_path='';
|
16 |
+
private static $file_pointer=null;
|
17 |
+
private static $mode='';
|
18 |
+
public function __construct()
|
19 |
+
{
|
20 |
+
|
21 |
+
}
|
22 |
+
public static function init($file_path, $mode="a+")
|
23 |
+
{
|
24 |
+
self::$file_path=$file_path;
|
25 |
+
self::$mode=$mode;
|
26 |
+
self::$file_pointer=@fopen($file_path, $mode);
|
27 |
+
}
|
28 |
+
public static function write_row($text, $is_writing_finished=false)
|
29 |
+
{
|
30 |
+
if(is_null(self::$file_pointer))
|
31 |
+
{
|
32 |
+
return;
|
33 |
+
}
|
34 |
+
@fwrite(self::$file_pointer, $text.PHP_EOL);
|
35 |
+
if($is_writing_finished)
|
36 |
+
{
|
37 |
+
self::close_file_pointer();
|
38 |
+
}
|
39 |
+
}
|
40 |
+
public static function close_file_pointer()
|
41 |
+
{
|
42 |
+
if(self::$file_pointer!=null)
|
43 |
+
{
|
44 |
+
fclose(self::$file_pointer);
|
45 |
+
}
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Debug log writing function
|
50 |
+
* @param string $post_type post type
|
51 |
+
* @param string $action_type action type
|
52 |
+
* @param mixed $data array/string of data to write
|
53 |
+
*/
|
54 |
+
public static function write_log($post_type, $action_type, $data)
|
55 |
+
{
|
56 |
+
/**
|
57 |
+
* Checks log file created for the current day
|
58 |
+
*/
|
59 |
+
$old_file_name=self::check_log_exists_for_entry(self::$history_id);
|
60 |
+
if(!$old_file_name)
|
61 |
+
{
|
62 |
+
$file_name=self::generate_file_name($post_type, $action_type, self::$history_id);
|
63 |
+
}else
|
64 |
+
{
|
65 |
+
$file_name=$old_file_name;
|
66 |
+
}
|
67 |
+
$file_path=self::get_file_path($file_name);
|
68 |
+
self::init($file_path);
|
69 |
+
$date_string=date_i18n('m-d-Y @ H:i:s');
|
70 |
+
if(is_array($data))
|
71 |
+
{
|
72 |
+
foreach ($data as $value)
|
73 |
+
{
|
74 |
+
self::write_row($date_string." - ".maybe_serialize($value));
|
75 |
+
}
|
76 |
+
}else
|
77 |
+
{
|
78 |
+
self::write_row($date_string." - ".$data);
|
79 |
+
}
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Import response log
|
84 |
+
* @param array $data array/string of import response data
|
85 |
+
* @param string $file_path import log file
|
86 |
+
*/
|
87 |
+
public static function write_import_log($data_arr, $file_path)
|
88 |
+
{
|
89 |
+
self::init($file_path);
|
90 |
+
foreach($data_arr as $key => $data)
|
91 |
+
{
|
92 |
+
self::write_row(maybe_serialize($data));
|
93 |
+
}
|
94 |
+
self::close_file_pointer();
|
95 |
+
}
|
96 |
+
}
|
97 |
+
}
|
admin/css/images/ui-bg_flat_0_aaaaaa_40x100.png
ADDED
Binary file
|
admin/css/images/ui-bg_flat_75_ffffff_40x100.png
ADDED
Binary file
|
admin/css/images/ui-bg_glass_55_fbf9ee_1x400.png
ADDED
Binary file
|
admin/css/images/ui-bg_glass_65_ffffff_1x400.png
ADDED
Binary file
|
admin/css/images/ui-bg_glass_75_dadada_1x400.png
ADDED
Binary file
|
admin/css/images/ui-bg_glass_75_e6e6e6_1x400.png
ADDED
Binary file
|
admin/css/images/ui-bg_glass_95_fef1ec_1x400.png
ADDED
Binary file
|
admin/css/images/ui-bg_highlight-soft_75_cccccc_1x100.png
ADDED
Binary file
|
admin/css/images/ui-icons_222222_256x240.png
ADDED
Binary file
|
admin/css/images/ui-icons_2e83ff_256x240.png
ADDED
Binary file
|
admin/css/images/ui-icons_454545_256x240.png
ADDED
Binary file
|
admin/css/images/ui-icons_888888_256x240.png
ADDED
Binary file
|
admin/css/images/ui-icons_cd0a0a_256x240.png
ADDED
Binary file
|
admin/css/jquery-ui.css
ADDED
@@ -0,0 +1,470 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*! jQuery UI - v1.9.0 - 2012-10-05
|
2 |
+
* http://jqueryui.com
|
3 |
+
* Includes: jquery.ui.core.css, jquery.ui.accordion.css, jquery.ui.autocomplete.css, jquery.ui.button.css, jquery.ui.datepicker.css, jquery.ui.dialog.css, jquery.ui.menu.css, jquery.ui.progressbar.css, jquery.ui.resizable.css, jquery.ui.selectable.css, jquery.ui.slider.css, jquery.ui.spinner.css, jquery.ui.tabs.css, jquery.ui.tooltip.css, jquery.ui.theme.css
|
4 |
+
* Copyright 2012 jQuery Foundation and other contributors; Licensed MIT */
|
5 |
+
|
6 |
+
/* Layout helpers
|
7 |
+
----------------------------------*/
|
8 |
+
.ui-helper-hidden { display: none; }
|
9 |
+
.ui-helper-hidden-accessible { position: absolute !important; clip: rect(1px 1px 1px 1px); clip: rect(1px,1px,1px,1px); }
|
10 |
+
.ui-helper-reset { margin: 0; padding: 0; border: 0; outline: 0; line-height: 1.3; text-decoration: none; font-size: 100%; list-style: none; }
|
11 |
+
.ui-helper-clearfix:before, .ui-helper-clearfix:after { content: ""; display: table; }
|
12 |
+
.ui-helper-clearfix:after { clear: both; }
|
13 |
+
.ui-helper-clearfix { zoom: 1; }
|
14 |
+
.ui-helper-zfix { width: 100%; height: 100%; top: 0; left: 0; position: absolute; opacity: 0; filter:Alpha(Opacity=0); }
|
15 |
+
|
16 |
+
|
17 |
+
/* Interaction Cues
|
18 |
+
----------------------------------*/
|
19 |
+
.ui-state-disabled { cursor: default !important; }
|
20 |
+
|
21 |
+
|
22 |
+
/* Icons
|
23 |
+
----------------------------------*/
|
24 |
+
|
25 |
+
/* states and images */
|
26 |
+
.ui-icon { display: block; text-indent: -99999px; overflow: hidden; background-repeat: no-repeat; }
|
27 |
+
|
28 |
+
|
29 |
+
/* Misc visuals
|
30 |
+
----------------------------------*/
|
31 |
+
|
32 |
+
/* Overlays */
|
33 |
+
.ui-widget-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
|
34 |
+
|
35 |
+
.ui-accordion .ui-accordion-header { display: block; cursor: pointer; position: relative; margin-top: 2px; padding: .5em .5em .5em .7em; zoom: 1; }
|
36 |
+
.ui-accordion .ui-accordion-icons { padding-left: 2.2em; }
|
37 |
+
.ui-accordion .ui-accordion-noicons { padding-left: .7em; }
|
38 |
+
.ui-accordion .ui-accordion-icons .ui-accordion-icons { padding-left: 2.2em; }
|
39 |
+
.ui-accordion .ui-accordion-header .ui-accordion-header-icon { position: absolute; left: .5em; top: 50%; margin-top: -8px; }
|
40 |
+
.ui-accordion .ui-accordion-content { padding: 1em 2.2em; border-top: 0; overflow: auto; zoom: 1; }
|
41 |
+
|
42 |
+
.ui-autocomplete { position: absolute; cursor: default; }
|
43 |
+
|
44 |
+
/* workarounds */
|
45 |
+
* html .ui-autocomplete { width:1px; } /* without this, the menu expands to 100% in IE6 */
|
46 |
+
|
47 |
+
.ui-button { display: inline-block; position: relative; padding: 0; margin-right: .1em; cursor: pointer; text-align: center; zoom: 1; overflow: visible; } /* the overflow property removes extra width in IE */
|
48 |
+
.ui-button, .ui-button:link, .ui-button:visited, .ui-button:hover, .ui-button:active { text-decoration: none; }
|
49 |
+
.ui-button-icon-only { width: 2.2em; } /* to make room for the icon, a width needs to be set here */
|
50 |
+
button.ui-button-icon-only { width: 2.4em; } /* button elements seem to need a little more width */
|
51 |
+
.ui-button-icons-only { width: 3.4em; }
|
52 |
+
button.ui-button-icons-only { width: 3.7em; }
|
53 |
+
|
54 |
+
/*button text element */
|
55 |
+
.ui-button .ui-button-text { display: block; line-height: 1.4; }
|
56 |
+
.ui-button-text-only .ui-button-text { padding: .4em 1em; }
|
57 |
+
.ui-button-icon-only .ui-button-text, .ui-button-icons-only .ui-button-text { padding: .4em; text-indent: -9999999px; }
|
58 |
+
.ui-button-text-icon-primary .ui-button-text, .ui-button-text-icons .ui-button-text { padding: .4em 1em .4em 2.1em; }
|
59 |
+
.ui-button-text-icon-secondary .ui-button-text, .ui-button-text-icons .ui-button-text { padding: .4em 2.1em .4em 1em; }
|
60 |
+
.ui-button-text-icons .ui-button-text { padding-left: 2.1em; padding-right: 2.1em; }
|
61 |
+
/* no icon support for input elements, provide padding by default */
|
62 |
+
input.ui-button { padding: .4em 1em; }
|
63 |
+
|
64 |
+
/*button icon element(s) */
|
65 |
+
.ui-button-icon-only .ui-icon, .ui-button-text-icon-primary .ui-icon, .ui-button-text-icon-secondary .ui-icon, .ui-button-text-icons .ui-icon, .ui-button-icons-only .ui-icon { position: absolute; top: 50%; margin-top: -8px; }
|
66 |
+
.ui-button-icon-only .ui-icon { left: 50%; margin-left: -8px; }
|
67 |
+
.ui-button-text-icon-primary .ui-button-icon-primary, .ui-button-text-icons .ui-button-icon-primary, .ui-button-icons-only .ui-button-icon-primary { left: .5em; }
|
68 |
+
.ui-button-text-icon-secondary .ui-button-icon-secondary, .ui-button-text-icons .ui-button-icon-secondary, .ui-button-icons-only .ui-button-icon-secondary { right: .5em; }
|
69 |
+
.ui-button-text-icons .ui-button-icon-secondary, .ui-button-icons-only .ui-button-icon-secondary { right: .5em; }
|
70 |
+
|
71 |
+
/*button sets*/
|
72 |
+
.ui-buttonset { margin-right: 7px; }
|
73 |
+
.ui-buttonset .ui-button { margin-left: 0; margin-right: -.3em; }
|
74 |
+
|
75 |
+
/* workarounds */
|
76 |
+
button.ui-button::-moz-focus-inner { border: 0; padding: 0; } /* reset extra padding in Firefox */
|
77 |
+
|
78 |
+
.ui-datepicker { width: 17em; padding: .2em .2em 0; display: none; }
|
79 |
+
.ui-datepicker .ui-datepicker-header { position:relative; padding:.2em 0; }
|
80 |
+
.ui-datepicker .ui-datepicker-prev, .ui-datepicker .ui-datepicker-next { position:absolute; top: 2px; width: 1.8em; height: 1.8em; }
|
81 |
+
.ui-datepicker .ui-datepicker-prev-hover, .ui-datepicker .ui-datepicker-next-hover { top: 1px; }
|
82 |
+
.ui-datepicker .ui-datepicker-prev { left:2px; }
|
83 |
+
.ui-datepicker .ui-datepicker-next { right:2px; }
|
84 |
+
.ui-datepicker .ui-datepicker-prev-hover { left:1px; }
|
85 |
+
.ui-datepicker .ui-datepicker-next-hover { right:1px; }
|
86 |
+
.ui-datepicker .ui-datepicker-prev span, .ui-datepicker .ui-datepicker-next span { display: block; position: absolute; left: 50%; margin-left: -8px; top: 50%; margin-top: -8px; }
|
87 |
+
.ui-datepicker .ui-datepicker-title { margin: 0 2.3em; line-height: 1.8em; text-align: center; }
|
88 |
+
.ui-datepicker .ui-datepicker-title select { font-size:1em; margin:1px 0; }
|
89 |
+
.ui-datepicker select.ui-datepicker-month-year {width: 100%;}
|
90 |
+
.ui-datepicker select.ui-datepicker-month,
|
91 |
+
.ui-datepicker select.ui-datepicker-year { width: 49%;}
|
92 |
+
.ui-datepicker table {width: 100%; font-size: .9em; border-collapse: collapse; margin:0 0 .4em; }
|
93 |
+
.ui-datepicker th { padding: .7em .3em; text-align: center; font-weight: bold; border: 0; }
|
94 |
+
.ui-datepicker td { border: 0; padding: 1px; }
|
95 |
+
.ui-datepicker td span, .ui-datepicker td a { display: block; padding: .2em; text-align: right; text-decoration: none; }
|
96 |
+
.ui-datepicker .ui-datepicker-buttonpane { background-image: none; margin: .7em 0 0 0; padding:0 .2em; border-left: 0; border-right: 0; border-bottom: 0; }
|
97 |
+
.ui-datepicker .ui-datepicker-buttonpane button { float: right; margin: .5em .2em .4em; cursor: pointer; padding: .2em .6em .3em .6em; width:auto; overflow:visible; }
|
98 |
+
.ui-datepicker .ui-datepicker-buttonpane button.ui-datepicker-current { float:left; }
|
99 |
+
|
100 |
+
/* with multiple calendars */
|
101 |
+
.ui-datepicker.ui-datepicker-multi { width:auto; }
|
102 |
+
.ui-datepicker-multi .ui-datepicker-group { float:left; }
|
103 |
+
.ui-datepicker-multi .ui-datepicker-group table { width:95%; margin:0 auto .4em; }
|
104 |
+
.ui-datepicker-multi-2 .ui-datepicker-group { width:50%; }
|
105 |
+
.ui-datepicker-multi-3 .ui-datepicker-group { width:33.3%; }
|
106 |
+
.ui-datepicker-multi-4 .ui-datepicker-group { width:25%; }
|
107 |
+
.ui-datepicker-multi .ui-datepicker-group-last .ui-datepicker-header { border-left-width:0; }
|
108 |
+
.ui-datepicker-multi .ui-datepicker-group-middle .ui-datepicker-header { border-left-width:0; }
|
109 |
+
.ui-datepicker-multi .ui-datepicker-buttonpane { clear:left; }
|
110 |
+
.ui-datepicker-row-break { clear:both; width:100%; font-size:0em; }
|
111 |
+
|
112 |
+
/* RTL support */
|
113 |
+
.ui-datepicker-rtl { direction: rtl; }
|
114 |
+
.ui-datepicker-rtl .ui-datepicker-prev { right: 2px; left: auto; }
|
115 |
+
.ui-datepicker-rtl .ui-datepicker-next { left: 2px; right: auto; }
|
116 |
+
.ui-datepicker-rtl .ui-datepicker-prev:hover { right: 1px; left: auto; }
|
117 |
+
.ui-datepicker-rtl .ui-datepicker-next:hover { left: 1px; right: auto; }
|
118 |
+
.ui-datepicker-rtl .ui-datepicker-buttonpane { clear:right; }
|
119 |
+
.ui-datepicker-rtl .ui-datepicker-buttonpane button { float: left; }
|
120 |
+
.ui-datepicker-rtl .ui-datepicker-buttonpane button.ui-datepicker-current { float:right; }
|
121 |
+
.ui-datepicker-rtl .ui-datepicker-group { float:right; }
|
122 |
+
.ui-datepicker-rtl .ui-datepicker-group-last .ui-datepicker-header { border-right-width:0; border-left-width:1px; }
|
123 |
+
.ui-datepicker-rtl .ui-datepicker-group-middle .ui-datepicker-header { border-right-width:0; border-left-width:1px; }
|
124 |
+
|
125 |
+
/* IE6 IFRAME FIX (taken from datepicker 1.5.3 */
|
126 |
+
.ui-datepicker-cover {
|
127 |
+
position: absolute; /*must have*/
|
128 |
+
z-index: -1; /*must have*/
|
129 |
+
filter: mask(); /*must have*/
|
130 |
+
top: -4px; /*must have*/
|
131 |
+
left: -4px; /*must have*/
|
132 |
+
width: 200px; /*must have*/
|
133 |
+
height: 200px; /*must have*/
|
134 |
+
}
|
135 |
+
.ui-dialog { position: absolute; padding: .2em; width: 300px; overflow: hidden; }
|
136 |
+
.ui-dialog .ui-dialog-titlebar { padding: .4em 1em; position: relative; }
|
137 |
+
.ui-dialog .ui-dialog-title { float: left; margin: .1em 16px .1em 0; }
|
138 |
+
.ui-dialog .ui-dialog-titlebar-close { position: absolute; right: .3em; top: 50%; width: 19px; margin: -10px 0 0 0; padding: 1px; height: 18px; }
|
139 |
+
.ui-dialog .ui-dialog-titlebar-close span { display: block; margin: 1px; }
|
140 |
+
.ui-dialog .ui-dialog-titlebar-close:hover, .ui-dialog .ui-dialog-titlebar-close:focus { padding: 0; }
|
141 |
+
.ui-dialog .ui-dialog-content { position: relative; border: 0; padding: .5em 1em; background: none; overflow: auto; zoom: 1; }
|
142 |
+
.ui-dialog .ui-dialog-buttonpane { text-align: left; border-width: 1px 0 0 0; background-image: none; margin: .5em 0 0 0; padding: .3em 1em .5em .4em; }
|
143 |
+
.ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset { float: right; }
|
144 |
+
.ui-dialog .ui-dialog-buttonpane button { margin: .5em .4em .5em 0; cursor: pointer; }
|
145 |
+
.ui-dialog .ui-resizable-se { width: 14px; height: 14px; right: 3px; bottom: 3px; }
|
146 |
+
.ui-draggable .ui-dialog-titlebar { cursor: move; }
|
147 |
+
|
148 |
+
.ui-menu { list-style:none; padding: 2px; margin: 0; display:block; outline: none; }
|
149 |
+
.ui-menu .ui-menu { margin-top: -3px; position: absolute; }
|
150 |
+
.ui-menu .ui-menu-item { margin: 0; padding: 0; zoom: 1; width: 100%; }
|
151 |
+
.ui-menu .ui-menu-divider { margin: 5px -2px 5px -2px; height: 0; font-size: 0; line-height: 0; border-width: 1px 0 0 0; }
|
152 |
+
.ui-menu .ui-menu-item a { text-decoration: none; display: block; padding: 2px .4em; line-height: 1.5; zoom: 1; font-weight: normal; }
|
153 |
+
.ui-menu .ui-menu-item a.ui-state-focus,
|
154 |
+
.ui-menu .ui-menu-item a.ui-state-active { font-weight: normal; margin: -1px; }
|
155 |
+
|
156 |
+
.ui-menu .ui-state-disabled { font-weight: normal; margin: .4em 0 .2em; line-height: 1.5; }
|
157 |
+
.ui-menu .ui-state-disabled a { cursor: default; }
|
158 |
+
|
159 |
+
/* icon support */
|
160 |
+
.ui-menu-icons { position: relative; }
|
161 |
+
.ui-menu-icons .ui-menu-item a { position: relative; padding-left: 2em; }
|
162 |
+
|
163 |
+
/* left-aligned */
|
164 |
+
.ui-menu .ui-icon { position: absolute; top: .2em; left: .2em; }
|
165 |
+
|
166 |
+
/* right-aligned */
|
167 |
+
.ui-menu .ui-menu-icon { position: static; float: right; }
|
168 |
+
|
169 |
+
.ui-progressbar { height:2em; text-align: left; overflow: hidden; }
|
170 |
+
.ui-progressbar .ui-progressbar-value {margin: -1px; height:100%; }
|
171 |
+
.ui-resizable { position: relative;}
|
172 |
+
.ui-resizable-handle { position: absolute;font-size: 0.1px; display: block; }
|
173 |
+
.ui-resizable-disabled .ui-resizable-handle, .ui-resizable-autohide .ui-resizable-handle { display: none; }
|
174 |
+
.ui-resizable-n { cursor: n-resize; height: 7px; width: 100%; top: -5px; left: 0; }
|
175 |
+
.ui-resizable-s { cursor: s-resize; height: 7px; width: 100%; bottom: -5px; left: 0; }
|
176 |
+
.ui-resizable-e { cursor: e-resize; width: 7px; right: -5px; top: 0; height: 100%; }
|
177 |
+
.ui-resizable-w { cursor: w-resize; width: 7px; left: -5px; top: 0; height: 100%; }
|
178 |
+
.ui-resizable-se { cursor: se-resize; width: 12px; height: 12px; right: 1px; bottom: 1px; }
|
179 |
+
.ui-resizable-sw { cursor: sw-resize; width: 9px; height: 9px; left: -5px; bottom: -5px; }
|
180 |
+
.ui-resizable-nw { cursor: nw-resize; width: 9px; height: 9px; left: -5px; top: -5px; }
|
181 |
+
.ui-resizable-ne { cursor: ne-resize; width: 9px; height: 9px; right: -5px; top: -5px;}
|
182 |
+
.ui-selectable-helper { position: absolute; z-index: 100; border:1px dotted black; }
|
183 |
+
|
184 |
+
.ui-slider { position: relative; text-align: left; }
|
185 |
+
.ui-slider .ui-slider-handle { position: absolute; z-index: 2; width: 1.2em; height: 1.2em; cursor: default; }
|
186 |
+
.ui-slider .ui-slider-range { position: absolute; z-index: 1; font-size: .7em; display: block; border: 0; background-position: 0 0; }
|
187 |
+
|
188 |
+
.ui-slider-horizontal { height: .8em; }
|
189 |
+
.ui-slider-horizontal .ui-slider-handle { top: -.3em; margin-left: -.6em; }
|
190 |
+
.ui-slider-horizontal .ui-slider-range { top: 0; height: 100%; }
|
191 |
+
.ui-slider-horizontal .ui-slider-range-min { left: 0; }
|
192 |
+
.ui-slider-horizontal .ui-slider-range-max { right: 0; }
|
193 |
+
|
194 |
+
.ui-slider-vertical { width: .8em; height: 100px; }
|
195 |
+
.ui-slider-vertical .ui-slider-handle { left: -.3em; margin-left: 0; margin-bottom: -.6em; }
|
196 |
+
.ui-slider-vertical .ui-slider-range { left: 0; width: 100%; }
|
197 |
+
.ui-slider-vertical .ui-slider-range-min { bottom: 0; }
|
198 |
+
.ui-slider-vertical .ui-slider-range-max { top: 0; }
|
199 |
+
.ui-spinner { position:relative; display: inline-block; overflow: hidden; padding: 0; vertical-align: middle; }
|
200 |
+
.ui-spinner-input { border: none; background: none; padding: 0; margin: .2em 0; vertical-align: middle; margin-left: .4em; margin-right: 22px; }
|
201 |
+
.ui-spinner-button { width: 16px; height: 50%; font-size: .5em; padding: 0; margin: 0; z-index: 100; text-align: center; position: absolute; cursor: default; display: block; overflow: hidden; right: 0; }
|
202 |
+
.ui-spinner a.ui-spinner-button { border-top: none; border-bottom: none; border-right: none; } /* more specificity required here to overide default borders */
|
203 |
+
.ui-spinner .ui-icon { position: absolute; margin-top: -8px; top: 50%; left: 0; } /* vertical centre icon */
|
204 |
+
.ui-spinner-up { top: 0; }
|
205 |
+
.ui-spinner-down { bottom: 0; }
|
206 |
+
|
207 |
+
/* TR overrides */
|
208 |
+
span.ui-spinner { background: none; }
|
209 |
+
.ui-spinner .ui-icon-triangle-1-s {
|
210 |
+
/* need to fix icons sprite */
|
211 |
+
background-position:-65px -16px;
|
212 |
+
}
|
213 |
+
|
214 |
+
.ui-tabs { position: relative; padding: .2em; zoom: 1; } /* position: relative prevents IE scroll bug (element with position: relative inside container with overflow: auto appear as "fixed") */
|
215 |
+
.ui-tabs .ui-tabs-nav { margin: 0; padding: .2em .2em 0; }
|
216 |
+
.ui-tabs .ui-tabs-nav li { list-style: none; float: left; position: relative; top: 0; margin: 1px .2em 0 0; border-bottom: 0; padding: 0; white-space: nowrap; }
|
217 |
+
.ui-tabs .ui-tabs-nav li a { float: left; padding: .5em 1em; text-decoration: none; }
|
218 |
+
.ui-tabs .ui-tabs-nav li.ui-tabs-active { margin-bottom: -1px; padding-bottom: 1px; }
|
219 |
+
.ui-tabs .ui-tabs-nav li.ui-tabs-active a, .ui-tabs .ui-tabs-nav li.ui-state-disabled a, .ui-tabs .ui-tabs-nav li.ui-tabs-loading a { cursor: text; }
|
220 |
+
.ui-tabs .ui-tabs-nav li a, .ui-tabs-collapsible .ui-tabs-nav li.ui-tabs-active a { cursor: pointer; } /* first selector in group seems obsolete, but required to overcome bug in Opera applying cursor: text overall if defined elsewhere... */
|
221 |
+
.ui-tabs .ui-tabs-panel { display: block; border-width: 0; padding: 1em 1.4em; background: none; }
|
222 |
+
|
223 |
+
.ui-tooltip {
|
224 |
+
padding:8px;
|
225 |
+
position:absolute;
|
226 |
+
z-index:9999;
|
227 |
+
-o-box-shadow: 0 0 5px #aaa;
|
228 |
+
-moz-box-shadow: 0 0 5px #aaa;
|
229 |
+
-webkit-box-shadow: 0 0 5px #aaa;
|
230 |
+
box-shadow: 0 0 5px #aaa;
|
231 |
+
}
|
232 |
+
/* Fades and background-images don't work well together in IE6, drop the image */
|
233 |
+
* html .ui-tooltip {
|
234 |
+
background-image: none;
|
235 |
+
}
|
236 |
+
body .ui-tooltip { border-width:2px; }
|
237 |
+
|
238 |
+
/* Component containers
|
239 |
+
----------------------------------*/
|
240 |
+
.ui-widget { font-family: Verdana,Arial,sans-serif/*{ffDefault}*/; font-size: 1.1em/*{fsDefault}*/; }
|
241 |
+
.ui-widget .ui-widget { font-size: 1em; }
|
242 |
+
.ui-widget input, .ui-widget select, .ui-widget textarea, .ui-widget button { font-family: Verdana,Arial,sans-serif/*{ffDefault}*/; font-size: 1em; }
|
243 |
+
.ui-widget-content { border: 1px solid #aaaaaa/*{borderColorContent}*/; background: #ffffff/*{bgColorContent}*/ url(images/ui-bg_flat_75_ffffff_40x100.png)/*{bgImgUrlContent}*/ 50%/*{bgContentXPos}*/ 50%/*{bgContentYPos}*/ repeat-x/*{bgContentRepeat}*/; color: #222222/*{fcContent}*/; }
|
244 |
+
.ui-widget-content a { color: #222222/*{fcContent}*/; }
|
245 |
+
.ui-widget-header { border: 1px solid #aaaaaa/*{borderColorHeader}*/; background: #cccccc/*{bgColorHeader}*/ url(images/ui-bg_highlight-soft_75_cccccc_1x100.png)/*{bgImgUrlHeader}*/ 50%/*{bgHeaderXPos}*/ 50%/*{bgHeaderYPos}*/ repeat-x/*{bgHeaderRepeat}*/; color: #222222/*{fcHeader}*/; font-weight: bold; }
|
246 |
+
.ui-widget-header a { color: #222222/*{fcHeader}*/; }
|
247 |
+
|
248 |
+
/* Interaction states
|
249 |
+
----------------------------------*/
|
250 |
+
.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #d3d3d3/*{borderColorDefault}*/; background: #e6e6e6/*{bgColorDefault}*/ url(images/ui-bg_glass_75_e6e6e6_1x400.png)/*{bgImgUrlDefault}*/ 50%/*{bgDefaultXPos}*/ 50%/*{bgDefaultYPos}*/ repeat-x/*{bgDefaultRepeat}*/; font-weight: normal/*{fwDefault}*/; color: #555555/*{fcDefault}*/; }
|
251 |
+
.ui-state-default a, .ui-state-default a:link, .ui-state-default a:visited { color: #555555/*{fcDefault}*/; text-decoration: none; }
|
252 |
+
.ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus, .ui-widget-header .ui-state-focus { border: 1px solid #999999/*{borderColorHover}*/; background: #dadada/*{bgColorHover}*/ url(images/ui-bg_glass_75_dadada_1x400.png)/*{bgImgUrlHover}*/ 50%/*{bgHoverXPos}*/ 50%/*{bgHoverYPos}*/ repeat-x/*{bgHoverRepeat}*/; font-weight: normal/*{fwDefault}*/; color: #212121/*{fcHover}*/; }
|
253 |
+
.ui-state-hover a, .ui-state-hover a:hover { color: #212121/*{fcHover}*/; text-decoration: none; }
|
254 |
+
.ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active { border: 1px solid #aaaaaa/*{borderColorActive}*/; background: #ffffff/*{bgColorActive}*/ url(images/ui-bg_glass_65_ffffff_1x400.png)/*{bgImgUrlActive}*/ 50%/*{bgActiveXPos}*/ 50%/*{bgActiveYPos}*/ repeat-x/*{bgActiveRepeat}*/; font-weight: normal/*{fwDefault}*/; color: #212121/*{fcActive}*/; }
|
255 |
+
.ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #212121/*{fcActive}*/; text-decoration: none; }
|
256 |
+
|
257 |
+
/* Interaction Cues
|
258 |
+
----------------------------------*/
|
259 |
+
.ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {border: 1px solid #fcefa1/*{borderColorHighlight}*/; background: #fbf9ee/*{bgColorHighlight}*/ url(images/ui-bg_glass_55_fbf9ee_1x400.png)/*{bgImgUrlHighlight}*/ 50%/*{bgHighlightXPos}*/ 50%/*{bgHighlightYPos}*/ repeat-x/*{bgHighlightRepeat}*/; color: #363636/*{fcHighlight}*/; }
|
260 |
+
.ui-state-highlight a, .ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a { color: #363636/*{fcHighlight}*/; }
|
261 |
+
.ui-state-error, .ui-widget-content .ui-state-error, .ui-widget-header .ui-state-error {border: 1px solid #cd0a0a/*{borderColorError}*/; background: #fef1ec/*{bgColorError}*/ url(images/ui-bg_glass_95_fef1ec_1x400.png)/*{bgImgUrlError}*/ 50%/*{bgErrorXPos}*/ 50%/*{bgErrorYPos}*/ repeat-x/*{bgErrorRepeat}*/; color: #cd0a0a/*{fcError}*/; }
|
262 |
+
.ui-state-error a, .ui-widget-content .ui-state-error a, .ui-widget-header .ui-state-error a { color: #cd0a0a/*{fcError}*/; }
|
263 |
+
.ui-state-error-text, .ui-widget-content .ui-state-error-text, .ui-widget-header .ui-state-error-text { color: #cd0a0a/*{fcError}*/; }
|
264 |
+
.ui-priority-primary, .ui-widget-content .ui-priority-primary, .ui-widget-header .ui-priority-primary { font-weight: bold; }
|
265 |
+
.ui-priority-secondary, .ui-widget-content .ui-priority-secondary, .ui-widget-header .ui-priority-secondary { opacity: .7; filter:Alpha(Opacity=70); font-weight: normal; }
|
266 |
+
.ui-state-disabled, .ui-widget-content .ui-state-disabled, .ui-widget-header .ui-state-disabled { opacity: .35; filter:Alpha(Opacity=35); background-image: none; }
|
267 |
+
|
268 |
+
/* Icons
|
269 |
+
----------------------------------*/
|
270 |
+
|
271 |
+
/* states and images */
|
272 |
+
.ui-icon { width: 16px; height: 16px; background-image: url(images/ui-icons_222222_256x240.png)/*{iconsContent}*/; }
|
273 |
+
.ui-widget-content .ui-icon {background-image: url(images/ui-icons_222222_256x240.png)/*{iconsContent}*/; }
|
274 |
+
.ui-widget-header .ui-icon {background-image: url(images/ui-icons_222222_256x240.png)/*{iconsHeader}*/; }
|
275 |
+
.ui-state-default .ui-icon { background-image: url(images/ui-icons_888888_256x240.png)/*{iconsDefault}*/; }
|
276 |
+
.ui-state-hover .ui-icon, .ui-state-focus .ui-icon {background-image: url(images/ui-icons_454545_256x240.png)/*{iconsHover}*/; }
|
277 |
+
.ui-state-active .ui-icon {background-image: url(images/ui-icons_454545_256x240.png)/*{iconsActive}*/; }
|
278 |
+
.ui-state-highlight .ui-icon {background-image: url(images/ui-icons_2e83ff_256x240.png)/*{iconsHighlight}*/; }
|
279 |
+
.ui-state-error .ui-icon, .ui-state-error-text .ui-icon {background-image: url(images/ui-icons_cd0a0a_256x240.png)/*{iconsError}*/; }
|
280 |
+
|
281 |
+
/* positioning */
|
282 |
+
.ui-icon-carat-1-n { background-position: 0 0; }
|
283 |
+
.ui-icon-carat-1-ne { background-position: -16px 0; }
|
284 |
+
.ui-icon-carat-1-e { background-position: -32px 0; }
|
285 |
+
.ui-icon-carat-1-se { background-position: -48px 0; }
|
286 |
+
.ui-icon-carat-1-s { background-position: -64px 0; }
|
287 |
+
.ui-icon-carat-1-sw { background-position: -80px 0; }
|
288 |
+
.ui-icon-carat-1-w { background-position: -96px 0; }
|
289 |
+
.ui-icon-carat-1-nw { background-position: -112px 0; }
|
290 |
+
.ui-icon-carat-2-n-s { background-position: -128px 0; }
|
291 |
+
.ui-icon-carat-2-e-w { background-position: -144px 0; }
|
292 |
+
.ui-icon-triangle-1-n { background-position: 0 -16px; }
|
293 |
+
.ui-icon-triangle-1-ne { background-position: -16px -16px; }
|
294 |
+
.ui-icon-triangle-1-e { background-position: -32px -16px; }
|
295 |
+
.ui-icon-triangle-1-se { background-position: -48px -16px; }
|
296 |
+
.ui-icon-triangle-1-s { background-position: -64px -16px; }
|
297 |
+
.ui-icon-triangle-1-sw { background-position: -80px -16px; }
|
298 |
+
.ui-icon-triangle-1-w { background-position: -96px -16px; }
|
299 |
+
.ui-icon-triangle-1-nw { background-position: -112px -16px; }
|
300 |
+
.ui-icon-triangle-2-n-s { background-position: -128px -16px; }
|
301 |
+
.ui-icon-triangle-2-e-w { background-position: -144px -16px; }
|
302 |
+
.ui-icon-arrow-1-n { background-position: 0 -32px; }
|
303 |
+
.ui-icon-arrow-1-ne { background-position: -16px -32px; }
|
304 |
+
.ui-icon-arrow-1-e { background-position: -32px -32px; }
|
305 |
+
.ui-icon-arrow-1-se { background-position: -48px -32px; }
|
306 |
+
.ui-icon-arrow-1-s { background-position: -64px -32px; }
|
307 |
+
.ui-icon-arrow-1-sw { background-position: -80px -32px; }
|
308 |
+
.ui-icon-arrow-1-w { background-position: -96px -32px; }
|
309 |
+
.ui-icon-arrow-1-nw { background-position: -112px -32px; }
|
310 |
+
.ui-icon-arrow-2-n-s { background-position: -128px -32px; }
|
311 |
+
.ui-icon-arrow-2-ne-sw { background-position: -144px -32px; }
|
312 |
+
.ui-icon-arrow-2-e-w { background-position: -160px -32px; }
|
313 |
+
.ui-icon-arrow-2-se-nw { background-position: -176px -32px; }
|
314 |
+
.ui-icon-arrowstop-1-n { background-position: -192px -32px; }
|
315 |
+
.ui-icon-arrowstop-1-e { background-position: -208px -32px; }
|
316 |
+
.ui-icon-arrowstop-1-s { background-position: -224px -32px; }
|
317 |
+
.ui-icon-arrowstop-1-w { background-position: -240px -32px; }
|
318 |
+
.ui-icon-arrowthick-1-n { background-position: 0 -48px; }
|
319 |
+
.ui-icon-arrowthick-1-ne { background-position: -16px -48px; }
|
320 |
+
.ui-icon-arrowthick-1-e { background-position: -32px -48px; }
|
321 |
+
.ui-icon-arrowthick-1-se { background-position: -48px -48px; }
|
322 |
+
.ui-icon-arrowthick-1-s { background-position: -64px -48px; }
|
323 |
+
.ui-icon-arrowthick-1-sw { background-position: -80px -48px; }
|
324 |
+
.ui-icon-arrowthick-1-w { background-position: -96px -48px; }
|
325 |
+
.ui-icon-arrowthick-1-nw { background-position: -112px -48px; }
|
326 |
+
.ui-icon-arrowthick-2-n-s { background-position: -128px -48px; }
|
327 |
+
.ui-icon-arrowthick-2-ne-sw { background-position: -144px -48px; }
|
328 |
+
.ui-icon-arrowthick-2-e-w { background-position: -160px -48px; }
|
329 |
+
.ui-icon-arrowthick-2-se-nw { background-position: -176px -48px; }
|
330 |
+
.ui-icon-arrowthickstop-1-n { background-position: -192px -48px; }
|
331 |
+
.ui-icon-arrowthickstop-1-e { background-position: -208px -48px; }
|
332 |
+
.ui-icon-arrowthickstop-1-s { background-position: -224px -48px; }
|
333 |
+
.ui-icon-arrowthickstop-1-w { background-position: -240px -48px; }
|
334 |
+
.ui-icon-arrowreturnthick-1-w { background-position: 0 -64px; }
|
335 |
+
.ui-icon-arrowreturnthick-1-n { background-position: -16px -64px; }
|
336 |
+
.ui-icon-arrowreturnthick-1-e { background-position: -32px -64px; }
|
337 |
+
.ui-icon-arrowreturnthick-1-s { background-position: -48px -64px; }
|
338 |
+
.ui-icon-arrowreturn-1-w { background-position: -64px -64px; }
|
339 |
+
.ui-icon-arrowreturn-1-n { background-position: -80px -64px; }
|
340 |
+
.ui-icon-arrowreturn-1-e { background-position: -96px -64px; }
|
341 |
+
.ui-icon-arrowreturn-1-s { background-position: -112px -64px; }
|
342 |
+
.ui-icon-arrowrefresh-1-w { background-position: -128px -64px; }
|
343 |
+
.ui-icon-arrowrefresh-1-n { background-position: -144px -64px; }
|
344 |
+
.ui-icon-arrowrefresh-1-e { background-position: -160px -64px; }
|
345 |
+
.ui-icon-arrowrefresh-1-s { background-position: -176px -64px; }
|
346 |
+
.ui-icon-arrow-4 { background-position: 0 -80px; }
|
347 |
+
.ui-icon-arrow-4-diag { background-position: -16px -80px; }
|
348 |
+
.ui-icon-extlink { background-position: -32px -80px; }
|
349 |
+
.ui-icon-newwin { background-position: -48px -80px; }
|
350 |
+
.ui-icon-refresh { background-position: -64px -80px; }
|
351 |
+
.ui-icon-shuffle { background-position: -80px -80px; }
|
352 |
+
.ui-icon-transfer-e-w { background-position: -96px -80px; }
|
353 |
+
.ui-icon-transferthick-e-w { background-position: -112px -80px; }
|
354 |
+
.ui-icon-folder-collapsed { background-position: 0 -96px; }
|
355 |
+
.ui-icon-folder-open { background-position: -16px -96px; }
|
356 |
+
.ui-icon-document { background-position: -32px -96px; }
|
357 |
+
.ui-icon-document-b { background-position: -48px -96px; }
|
358 |
+
.ui-icon-note { background-position: -64px -96px; }
|
359 |
+
.ui-icon-mail-closed { background-position: -80px -96px; }
|
360 |
+
.ui-icon-mail-open { background-position: -96px -96px; }
|
361 |
+
.ui-icon-suitcase { background-position: -112px -96px; }
|
362 |
+
.ui-icon-comment { background-position: -128px -96px; }
|
363 |
+
.ui-icon-person { background-position: -144px -96px; }
|
364 |
+
.ui-icon-print { background-position: -160px -96px; }
|
365 |
+
.ui-icon-trash { background-position: -176px -96px; }
|
366 |
+
.ui-icon-locked { background-position: -192px -96px; }
|
367 |
+
.ui-icon-unlocked { background-position: -208px -96px; }
|
368 |
+
.ui-icon-bookmark { background-position: -224px -96px; }
|
369 |
+
.ui-icon-tag { background-position: -240px -96px; }
|
370 |
+
.ui-icon-home { background-position: 0 -112px; }
|
371 |
+
.ui-icon-flag { background-position: -16px -112px; }
|
372 |
+
.ui-icon-calendar { background-position: -32px -112px; }
|
373 |
+
.ui-icon-cart { background-position: -48px -112px; }
|
374 |
+
.ui-icon-pencil { background-position: -64px -112px; }
|
375 |
+
.ui-icon-clock { background-position: -80px -112px; }
|
376 |
+
.ui-icon-disk { background-position: -96px -112px; }
|
377 |
+
.ui-icon-calculator { background-position: -112px -112px; }
|
378 |
+
.ui-icon-zoomin { background-position: -128px -112px; }
|
379 |
+
.ui-icon-zoomout { background-position: -144px -112px; }
|
380 |
+
.ui-icon-search { background-position: -160px -112px; }
|
381 |
+
.ui-icon-wrench { background-position: -176px -112px; }
|
382 |
+
.ui-icon-gear { background-position: -192px -112px; }
|
383 |
+
.ui-icon-heart { background-position: -208px -112px; }
|
384 |
+
.ui-icon-star { background-position: -224px -112px; }
|
385 |
+
.ui-icon-link { background-position: -240px -112px; }
|
386 |
+
.ui-icon-cancel { background-position: 0 -128px; }
|
387 |
+
.ui-icon-plus { background-position: -16px -128px; }
|
388 |
+
.ui-icon-plusthick { background-position: -32px -128px; }
|
389 |
+
.ui-icon-minus { background-position: -48px -128px; }
|
390 |
+
.ui-icon-minusthick { background-position: -64px -128px; }
|
391 |
+
.ui-icon-close { background-position: -80px -128px; }
|
392 |
+
.ui-icon-closethick { background-position: -96px -128px; }
|
393 |
+
.ui-icon-key { background-position: -112px -128px; }
|
394 |
+
.ui-icon-lightbulb { background-position: -128px -128px; }
|
395 |
+
.ui-icon-scissors { background-position: -144px -128px; }
|
396 |
+
.ui-icon-clipboard { background-position: -160px -128px; }
|
397 |
+
.ui-icon-copy { background-position: -176px -128px; }
|
398 |
+
.ui-icon-contact { background-position: -192px -128px; }
|
399 |
+
.ui-icon-image { background-position: -208px -128px; }
|
400 |
+
.ui-icon-video { background-position: -224px -128px; }
|
401 |
+
.ui-icon-script { background-position: -240px -128px; }
|
402 |
+
.ui-icon-alert { background-position: 0 -144px; }
|
403 |
+
.ui-icon-info { background-position: -16px -144px; }
|
404 |
+
.ui-icon-notice { background-position: -32px -144px; }
|
405 |
+
.ui-icon-help { background-position: -48px -144px; }
|
406 |
+
.ui-icon-check { background-position: -64px -144px; }
|
407 |
+
.ui-icon-bullet { background-position: -80px -144px; }
|
408 |
+
.ui-icon-radio-on { background-position: -96px -144px; }
|
409 |
+
.ui-icon-radio-off { background-position: -112px -144px; }
|
410 |
+
.ui-icon-pin-w { background-position: -128px -144px; }
|
411 |
+
.ui-icon-pin-s { background-position: -144px -144px; }
|
412 |
+
.ui-icon-play { background-position: 0 -160px; }
|
413 |
+
.ui-icon-pause { background-position: -16px -160px; }
|
414 |
+
.ui-icon-seek-next { background-position: -32px -160px; }
|
415 |
+
.ui-icon-seek-prev { background-position: -48px -160px; }
|
416 |
+
.ui-icon-seek-end { background-position: -64px -160px; }
|
417 |
+
.ui-icon-seek-start { background-position: -80px -160px; }
|
418 |
+
/* ui-icon-seek-first is deprecated, use ui-icon-seek-start instead */
|
419 |
+
.ui-icon-seek-first { background-position: -80px -160px; }
|
420 |
+
.ui-icon-stop { background-position: -96px -160px; }
|
421 |
+
.ui-icon-eject { background-position: -112px -160px; }
|
422 |
+
.ui-icon-volume-off { background-position: -128px -160px; }
|
423 |
+
.ui-icon-volume-on { background-position: -144px -160px; }
|
424 |
+
.ui-icon-power { background-position: 0 -176px; }
|
425 |
+
.ui-icon-signal-diag { background-position: -16px -176px; }
|
426 |
+
.ui-icon-signal { background-position: -32px -176px; }
|
427 |
+
.ui-icon-battery-0 { background-position: -48px -176px; }
|
428 |
+
.ui-icon-battery-1 { background-position: -64px -176px; }
|
429 |
+
.ui-icon-battery-2 { background-position: -80px -176px; }
|
430 |
+
.ui-icon-battery-3 { background-position: -96px -176px; }
|
431 |
+
.ui-icon-circle-plus { background-position: 0 -192px; }
|
432 |
+
.ui-icon-circle-minus { background-position: -16px -192px; }
|
433 |
+
.ui-icon-circle-close { background-position: -32px -192px; }
|
434 |
+
.ui-icon-circle-triangle-e { background-position: -48px -192px; }
|
435 |
+
.ui-icon-circle-triangle-s { background-position: -64px -192px; }
|
436 |
+
.ui-icon-circle-triangle-w { background-position: -80px -192px; }
|
437 |
+
.ui-icon-circle-triangle-n { background-position: -96px -192px; }
|
438 |
+
.ui-icon-circle-arrow-e { background-position: -112px -192px; }
|
439 |
+
.ui-icon-circle-arrow-s { background-position: -128px -192px; }
|
440 |
+
.ui-icon-circle-arrow-w { background-position: -144px -192px; }
|
441 |
+
.ui-icon-circle-arrow-n { background-position: -160px -192px; }
|
442 |
+
.ui-icon-circle-zoomin { background-position: -176px -192px; }
|
443 |
+
.ui-icon-circle-zoomout { background-position: -192px -192px; }
|
444 |
+
.ui-icon-circle-check { background-position: -208px -192px; }
|
445 |
+
.ui-icon-circlesmall-plus { background-position: 0 -208px; }
|
446 |
+
.ui-icon-circlesmall-minus { background-position: -16px -208px; }
|
447 |
+
.ui-icon-circlesmall-close { background-position: -32px -208px; }
|
448 |
+
.ui-icon-squaresmall-plus { background-position: -48px -208px; }
|
449 |
+
.ui-icon-squaresmall-minus { background-position: -64px -208px; }
|
450 |
+
.ui-icon-squaresmall-close { background-position: -80px -208px; }
|
451 |
+
.ui-icon-grip-dotted-vertical { background-position: 0 -224px; }
|
452 |
+
.ui-icon-grip-dotted-horizontal { background-position: -16px -224px; }
|
453 |
+
.ui-icon-grip-solid-vertical { background-position: -32px -224px; }
|
454 |
+
.ui-icon-grip-solid-horizontal { background-position: -48px -224px; }
|
455 |
+
.ui-icon-gripsmall-diagonal-se { background-position: -64px -224px; }
|
456 |
+
.ui-icon-grip-diagonal-se { background-position: -80px -224px; }
|
457 |
+
|
458 |
+
|
459 |
+
/* Misc visuals
|
460 |
+
----------------------------------*/
|
461 |
+
|
462 |
+
/* Corner radius */
|
463 |
+
.ui-corner-all, .ui-corner-top, .ui-corner-left, .ui-corner-tl { -moz-border-radius-topleft: 4px/*{cornerRadius}*/; -webkit-border-top-left-radius: 4px/*{cornerRadius}*/; -khtml-border-top-left-radius: 4px/*{cornerRadius}*/; border-top-left-radius: 4px/*{cornerRadius}*/; }
|
464 |
+
.ui-corner-all, .ui-corner-top, .ui-corner-right, .ui-corner-tr { -moz-border-radius-topright: 4px/*{cornerRadius}*/; -webkit-border-top-right-radius: 4px/*{cornerRadius}*/; -khtml-border-top-right-radius: 4px/*{cornerRadius}*/; border-top-right-radius: 4px/*{cornerRadius}*/; }
|
465 |
+
.ui-corner-all, .ui-corner-bottom, .ui-corner-left, .ui-corner-bl { -moz-border-radius-bottomleft: 4px/*{cornerRadius}*/; -webkit-border-bottom-left-radius: 4px/*{cornerRadius}*/; -khtml-border-bottom-left-radius: 4px/*{cornerRadius}*/; border-bottom-left-radius: 4px/*{cornerRadius}*/; }
|
466 |
+
.ui-corner-all, .ui-corner-bottom, .ui-corner-right, .ui-corner-br { -moz-border-radius-bottomright: 4px/*{cornerRadius}*/; -webkit-border-bottom-right-radius: 4px/*{cornerRadius}*/; -khtml-border-bottom-right-radius: 4px/*{cornerRadius}*/; border-bottom-right-radius: 4px/*{cornerRadius}*/; }
|
467 |
+
|
468 |
+
/* Overlays */
|
469 |
+
.ui-widget-overlay { background: #aaaaaa/*{bgColorOverlay}*/ url(images/ui-bg_flat_0_aaaaaa_40x100.png)/*{bgImgUrlOverlay}*/ 50%/*{bgOverlayXPos}*/ 50%/*{bgOverlayYPos}*/ repeat-x/*{bgOverlayRepeat}*/; opacity: .3;filter:Alpha(Opacity=30)/*{opacityOverlay}*/; }
|
470 |
+
.ui-widget-shadow { margin: -8px/*{offsetTopShadow}*/ 0 0 -8px/*{offsetLeftShadow}*/; padding: 8px/*{thicknessShadow}*/; background: #aaaaaa/*{bgColorShadow}*/ url(images/ui-bg_flat_0_aaaaaa_40x100.png)/*{bgImgUrlShadow}*/ 50%/*{bgShadowXPos}*/ 50%/*{bgShadowYPos}*/ repeat-x/*{bgShadowRepeat}*/; opacity: .3;filter:Alpha(Opacity=30)/*{opacityShadow}*/; -moz-border-radius: 8px/*{cornerRadiusShadow}*/; -khtml-border-radius: 8px/*{cornerRadiusShadow}*/; -webkit-border-radius: 8px/*{cornerRadiusShadow}*/; border-radius: 8px/*{cornerRadiusShadow}*/; }
|
admin/css/select2.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
.select2-container{box-sizing:border-box;display:inline-block;margin:0;position:relative;vertical-align:middle}.select2-container .select2-selection--single{box-sizing:border-box;cursor:pointer;display:block;height:28px;user-select:none;-webkit-user-select:none}.select2-container .select2-selection--single .select2-selection__rendered{display:block;padding-left:8px;padding-right:20px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.select2-container .select2-selection--single .select2-selection__clear{position:relative}.select2-container[dir="rtl"] .select2-selection--single .select2-selection__rendered{padding-right:8px;padding-left:20px}.select2-container .select2-selection--multiple{box-sizing:border-box;cursor:pointer;display:block;min-height:32px;user-select:none;-webkit-user-select:none}.select2-container .select2-selection--multiple .select2-selection__rendered{display:inline-block;overflow:hidden;padding-left:8px;text-overflow:ellipsis;white-space:nowrap}.select2-container .select2-search--inline{float:left}.select2-container .select2-search--inline .select2-search__field{box-sizing:border-box;border:none;font-size:100%;margin-top:5px;padding:0}.select2-container .select2-search--inline .select2-search__field::-webkit-search-cancel-button{-webkit-appearance:none}.select2-dropdown{background-color:white;border:1px solid #aaa;border-radius:4px;box-sizing:border-box;display:block;position:absolute;left:-100000px;width:100%;z-index:1051}.select2-results{display:block}.select2-results__options{list-style:none;margin:0;padding:0}.select2-results__option{padding:6px;user-select:none;-webkit-user-select:none}.select2-results__option[aria-selected]{cursor:pointer}.select2-container--open .select2-dropdown{left:0}.select2-container--open .select2-dropdown--above{border-bottom:none;border-bottom-left-radius:0;border-bottom-right-radius:0}.select2-container--open .select2-dropdown--below{border-top:none;border-top-left-radius:0;border-top-right-radius:0}.select2-search--dropdown{display:block;padding:4px}.select2-search--dropdown .select2-search__field{padding:4px;width:100%;box-sizing:border-box}.select2-search--dropdown .select2-search__field::-webkit-search-cancel-button{-webkit-appearance:none}.select2-search--dropdown.select2-search--hide{display:none}.select2-close-mask{border:0;margin:0;padding:0;display:block;position:fixed;left:0;top:0;min-height:100%;min-width:100%;height:auto;width:auto;opacity:0;z-index:99;background-color:#fff;filter:alpha(opacity=0)}.select2-hidden-accessible{border:0 !important;clip:rect(0 0 0 0) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}.select2-container--default .select2-selection--single{background-color:#fff;border:1px solid #aaa;border-radius:4px}.select2-container--default .select2-selection--single .select2-selection__rendered{color:#444;line-height:28px}.select2-container--default .select2-selection--single .select2-selection__clear{cursor:pointer;float:right;font-weight:bold}.select2-container--default .select2-selection--single .select2-selection__placeholder{color:#999}.select2-container--default .select2-selection--single .select2-selection__arrow{height:26px;position:absolute;top:1px;right:1px;width:20px}.select2-container--default .select2-selection--single .select2-selection__arrow b{border-color:#888 transparent transparent transparent;border-style:solid;border-width:5px 4px 0 4px;height:0;left:50%;margin-left:-4px;margin-top:-2px;position:absolute;top:50%;width:0}.select2-container--default[dir="rtl"] .select2-selection--single .select2-selection__clear{float:left}.select2-container--default[dir="rtl"] .select2-selection--single .select2-selection__arrow{left:1px;right:auto}.select2-container--default.select2-container--disabled .select2-selection--single{background-color:#eee;cursor:default}.select2-container--default.select2-container--disabled .select2-selection--single .select2-selection__clear{display:none}.select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b{border-color:transparent transparent #888 transparent;border-width:0 4px 5px 4px}.select2-container--default .select2-selection--multiple{background-color:white;border:1px solid #ddd;border-radius:0px;cursor:text;line-height: 1.5}.select2-container--default .select2-selection--multiple .select2-selection__rendered{box-sizing:border-box;list-style:none;margin:0;padding:0 5px;width:100%}.select2-container--default .select2-selection--multiple .select2-selection__rendered li{list-style:none;margin: 5px 5px 0 0}.select2-container--default .select2-selection--multiple .select2-selection__placeholder{color:#999;margin-top:5px;float:left}.select2-container--default .select2-selection--multiple .select2-selection__clear{cursor:pointer;float:right;font-weight:bold;margin-top:5px;margin-right:10px}.select2-container--default .select2-selection--multiple .select2-selection__choice{background-color:#e4e4e4;border:1px solid #aaa;border-radius:4px;cursor:default;float:left;margin-right:5px;margin-top:5px;padding:0 5px}.select2-container--default .select2-selection--multiple .select2-selection__choice__remove{color:#999;cursor:pointer;display:inline-block;font-weight:bold;margin-right:2px}.select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover{color:#333}.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice,.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__placeholder,.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-search--inline{float:right}.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice{margin-left:5px;margin-right:auto}.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice__remove{margin-left:2px;margin-right:auto}.select2-container--default.select2-container--focus .select2-selection--multiple{border:solid black 1px;outline:0}.select2-container--default.select2-container--disabled .select2-selection--multiple{background-color:#eee;cursor:default}.select2-container--default.select2-container--disabled .select2-selection__choice__remove{display:none}.select2-container--default.select2-container--open.select2-container--above .select2-selection--single,.select2-container--default.select2-container--open.select2-container--above .select2-selection--multiple{border-top-left-radius:0;border-top-right-radius:0}.select2-container--default.select2-container--open.select2-container--below .select2-selection--single,.select2-container--default.select2-container--open.select2-container--below .select2-selection--multiple{border-bottom-left-radius:0;border-bottom-right-radius:0}.select2-container--default .select2-search--dropdown .select2-search__field{border:1px solid #aaa}.select2-container--default .select2-search--inline .select2-search__field{background:transparent;border:none;outline:0;box-shadow:none;-webkit-appearance:textfield}.select2-container--default .select2-results>.select2-results__options{max-height:200px;overflow-y:auto}.select2-container--default .select2-results__option[role=group]{padding:0}.select2-container--default .select2-results__option[aria-disabled=true]{color:#999}.select2-container--default .select2-results__option[aria-selected=true]{background-color:#ddd}.select2-container--default .select2-results__option .select2-results__option{padding-left:1em}.select2-container--default .select2-results__option .select2-results__option .select2-results__group{padding-left:0}.select2-container--default .select2-results__option .select2-results__option .select2-results__option{margin-left:-1em;padding-left:2em}.select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option{margin-left:-2em;padding-left:3em}.select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option{margin-left:-3em;padding-left:4em}.select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option{margin-left:-4em;padding-left:5em}.select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option{margin-left:-5em;padding-left:6em}.select2-container--default .select2-results__option--highlighted[aria-selected]{background-color:#5897fb;color:white}.select2-container--default .select2-results__group{cursor:default;display:block;padding:6px}.select2-container--classic .select2-selection--single{background-color:#f7f7f7;border:1px solid #aaa;border-radius:4px;outline:0;background-image:-webkit-linear-gradient(top, #fff 50%, #eee 100%);background-image:-o-linear-gradient(top, #fff 50%, #eee 100%);background-image:linear-gradient(to bottom, #fff 50%, #eee 100%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFFFFFFF', endColorstr='#FFEEEEEE', GradientType=0)}.select2-container--classic .select2-selection--single:focus{border:1px solid #5897fb}.select2-container--classic .select2-selection--single .select2-selection__rendered{color:#444;line-height:28px}.select2-container--classic .select2-selection--single .select2-selection__clear{cursor:pointer;float:right;font-weight:bold;margin-right:10px}.select2-container--classic .select2-selection--single .select2-selection__placeholder{color:#999}.select2-container--classic .select2-selection--single .select2-selection__arrow{background-color:#ddd;border:none;border-left:1px solid #aaa;border-top-right-radius:4px;border-bottom-right-radius:4px;height:26px;position:absolute;top:1px;right:1px;width:20px;background-image:-webkit-linear-gradient(top, #eee 50%, #ccc 100%);background-image:-o-linear-gradient(top, #eee 50%, #ccc 100%);background-image:linear-gradient(to bottom, #eee 50%, #ccc 100%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFEEEEEE', endColorstr='#FFCCCCCC', GradientType=0)}.select2-container--classic .select2-selection--single .select2-selection__arrow b{border-color:#888 transparent transparent transparent;border-style:solid;border-width:5px 4px 0 4px;height:0;left:50%;margin-left:-4px;margin-top:-2px;position:absolute;top:50%;width:0}.select2-container--classic[dir="rtl"] .select2-selection--single .select2-selection__clear{float:left}.select2-container--classic[dir="rtl"] .select2-selection--single .select2-selection__arrow{border:none;border-right:1px solid #aaa;border-radius:0;border-top-left-radius:4px;border-bottom-left-radius:4px;left:1px;right:auto}.select2-container--classic.select2-container--open .select2-selection--single{border:1px solid #5897fb}.select2-container--classic.select2-container--open .select2-selection--single .select2-selection__arrow{background:transparent;border:none}.select2-container--classic.select2-container--open .select2-selection--single .select2-selection__arrow b{border-color:transparent transparent #888 transparent;border-width:0 4px 5px 4px}.select2-container--classic.select2-container--open.select2-container--above .select2-selection--single{border-top:none;border-top-left-radius:0;border-top-right-radius:0;background-image:-webkit-linear-gradient(top, #fff 0%, #eee 50%);background-image:-o-linear-gradient(top, #fff 0%, #eee 50%);background-image:linear-gradient(to bottom, #fff 0%, #eee 50%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFFFFFFF', endColorstr='#FFEEEEEE', GradientType=0)}.select2-container--classic.select2-container--open.select2-container--below .select2-selection--single{border-bottom:none;border-bottom-left-radius:0;border-bottom-right-radius:0;background-image:-webkit-linear-gradient(top, #eee 50%, #fff 100%);background-image:-o-linear-gradient(top, #eee 50%, #fff 100%);background-image:linear-gradient(to bottom, #eee 50%, #fff 100%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFEEEEEE', endColorstr='#FFFFFFFF', GradientType=0)}.select2-container--classic .select2-selection--multiple{background-color:white;border:1px solid #aaa;border-radius:4px;cursor:text;outline:0}.select2-container--classic .select2-selection--multiple:focus{border:1px solid #5897fb}.select2-container--classic .select2-selection--multiple .select2-selection__rendered{list-style:none;margin:0;padding:0 5px}.select2-container--classic .select2-selection--multiple .select2-selection__clear{display:none}.select2-container--classic .select2-selection--multiple .select2-selection__choice{background-color:#e4e4e4;border:1px solid #aaa;border-radius:4px;cursor:default;float:left;margin-right:5px;margin-top:5px;padding:0 5px}.select2-container--classic .select2-selection--multiple .select2-selection__choice__remove{color:#888;cursor:pointer;display:inline-block;font-weight:bold;margin-right:2px}.select2-container--classic .select2-selection--multiple .select2-selection__choice__remove:hover{color:#555}.select2-container--classic[dir="rtl"] .select2-selection--multiple .select2-selection__choice{float:right}.select2-container--classic[dir="rtl"] .select2-selection--multiple .select2-selection__choice{margin-left:5px;margin-right:auto}.select2-container--classic[dir="rtl"] .select2-selection--multiple .select2-selection__choice__remove{margin-left:2px;margin-right:auto}.select2-container--classic.select2-container--open .select2-selection--multiple{border:1px solid #5897fb}.select2-container--classic.select2-container--open.select2-container--above .select2-selection--multiple{border-top:none;border-top-left-radius:0;border-top-right-radius:0}.select2-container--classic.select2-container--open.select2-container--below .select2-selection--multiple{border-bottom:none;border-bottom-left-radius:0;border-bottom-right-radius:0}.select2-container--classic .select2-search--dropdown .select2-search__field{border:1px solid #aaa;outline:0}.select2-container--classic .select2-search--inline .select2-search__field{outline:0;box-shadow:none}.select2-container--classic .select2-dropdown{background-color:#fff;border:1px solid transparent}.select2-container--classic .select2-dropdown--above{border-bottom:none}.select2-container--classic .select2-dropdown--below{border-top:none}.select2-container--classic .select2-results>.select2-results__options{max-height:200px;overflow-y:auto}.select2-container--classic .select2-results__option[role=group]{padding:0}.select2-container--classic .select2-results__option[aria-disabled=true]{color:grey}.select2-container--classic .select2-results__option--highlighted[aria-selected]{background-color:#3875d7;color:#fff}.select2-container--classic .select2-results__group{cursor:default;display:block;padding:6px}.select2-container--classic.select2-container--open .select2-dropdown{border-color:#5897fb}
|
admin/css/wt-import-export-for-woo-admin.css
ADDED
@@ -0,0 +1,445 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* All of the CSS for your admin-specific functionality should be
|
3 |
+
* included in this file.
|
4 |
+
*/
|
5 |
+
|
6 |
+
/**
|
7 |
+
* Tab section
|
8 |
+
*/
|
9 |
+
.wt_iew_page_hd{ font-size:20px; }
|
10 |
+
.wt-iew-tab-head{ margin-right:0px; margin-top:20px; clear:both;}
|
11 |
+
.wt-iew-tab-container{ padding:15px; padding-bottom:0px; background:#fff; box-shadow:0px 2px 2px #ccc; float:left; box-sizing:border-box; width:100%; height:auto;}
|
12 |
+
.wt-iew-tab-head .nav-tab-active{ background: #fff; border-bottom: solid 1px #fff; }
|
13 |
+
.wt-iew-tab-head .nav-tab:focus{ box-shadow:none;}
|
14 |
+
.wt-iew-tab-content{ display:none; float:left; width:100%; height:auto; }
|
15 |
+
.wt_iew_sub_tab_container{float:left; width:100%; height:auto; padding-bottom:0px;}
|
16 |
+
.wt_iew_sub_tab{ display:inline-block; margin:0px;}
|
17 |
+
.wt_iew_sub_tab li{ display:inline-block; border-left: solid 1px #ccc; padding:3px 10px; cursor: pointer;}
|
18 |
+
.wt_iew_sub_tab_content{ display: none; float:left; width:100%; height:auto; }
|
19 |
+
.wt-iew-settings-header{border-bottom:dashed 1px #ccc; margin-left:-15px; margin-right:-15px; padding-top:0px;}
|
20 |
+
.wt-iew-settings-header h3{margin-top:0px; margin-left:15px; width:60%; display:inline-block;}
|
21 |
+
.wt-iew-settings-header .wt_iew_step_info{float:right; font-weight:bold; margin-right:15px; background:#dceff4; display:inline-block; padding:5px 10px; margin-top:-6px; margin-bottom:-15px; padding-bottom:6px; line-height:24px; border-radius:6px; }
|
22 |
+
.wt-iew-plugin-toolbar {
|
23 |
+
height: 40px;
|
24 |
+
width: 100%;
|
25 |
+
margin: 0;
|
26 |
+
padding: 0;
|
27 |
+
}
|
28 |
+
.wt-iew-plugin-toolbar .left {
|
29 |
+
float: left;
|
30 |
+
margin: 0;
|
31 |
+
padding: 0;
|
32 |
+
}
|
33 |
+
.wt-iew-plugin-toolbar .left img {
|
34 |
+
vertical-align: text-bottom;
|
35 |
+
margin-right: 10px;
|
36 |
+
}
|
37 |
+
.wt-iew-plugin-toolbar .right {
|
38 |
+
float: right;
|
39 |
+
margin: 0 10px 0 0;
|
40 |
+
padding: 0;
|
41 |
+
}
|
42 |
+
.wt-iew-plugin-toolbar.top {
|
43 |
+
margin-bottom: -5px;
|
44 |
+
}
|
45 |
+
.wt-iew-plugin-toolbar.bottom {
|
46 |
+
margin-top: 12px;
|
47 |
+
background: #f5f5f5;
|
48 |
+
border-top: 1px solid #ddd;
|
49 |
+
margin-left: -15px;
|
50 |
+
margin-right: -15px;
|
51 |
+
margin-bottom:0px;
|
52 |
+
padding:9px 15px;
|
53 |
+
}
|
54 |
+
.wt-iew-plugin-toolbar.top {
|
55 |
+
margin-top:-15px;
|
56 |
+
background: #f5f5f5;
|
57 |
+
border-bottom: 1px solid #ddd;
|
58 |
+
border-top: 1px solid #ddd;
|
59 |
+
margin-left: -15px;
|
60 |
+
margin-right: -15px;
|
61 |
+
margin-bottom: -15px;
|
62 |
+
padding:15px;
|
63 |
+
}
|
64 |
+
.wt-iew-plugin-toolbar.bottom .button{padding:0.2rem 0.75rem; margin-top:2px; height:auto;}
|
65 |
+
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Form section
|
69 |
+
*/
|
70 |
+
.wt_notify_msg{ position:fixed; width:300px; padding:15px; color:#fff; right:60px; top:0px; opacity:0; box-shadow:0px 2px 2px #333; border-radius:5px; z-index:1000000000;}
|
71 |
+
.wt_iew_overlayed_loader{ position:absolute; z-index:10000; background:rgba(255,255,255,.5); width:100%; height:auto; margin-left:-15px; margin-top:-15px;}
|
72 |
+
.wt_iew_loader_info_box{display:none; position:fixed; z-index:10001; width:300px; left:50%; top:50%; font-size:14px; font-weight:bold; background:#0073aa; text-align:center; line-height:20px; box-shadow:2px 2px 4px 0px #ccc; margin-left:-155px; margin-top:-45px; padding:10px 5px; color:#fff;}
|
73 |
+
.wt_iew_loader_info_box a{ color:#fff; text-decoration:underline; cursor:pointer; }
|
74 |
+
.wt_iew_loader_info_box .wt_iew_info_box_title{ font-size:16px; }
|
75 |
+
.wt_iew_loader_info_box .wt_iew_info_box_finished_text{ display:inline-block; font-weight:normal; margin-top:0px; }
|
76 |
+
.wf-help-links li{ float:left; padding:40px; margin:20px; display: inline-block; text-align: center; box-shadow:1px 1px 5px 1px rgba(0,0,0,.1); width: 185px; height: 245px;}
|
77 |
+
.wf-help-links li a{ text-decoration: none; height: 28px !important; margin-top: 20px; }
|
78 |
+
.wf-help-links li img{
|
79 |
+
margin-top: 15px;
|
80 |
+
}
|
81 |
+
.wt_iew_noselect {
|
82 |
+
-webkit-touch-callout: none; /* iOS Safari */
|
83 |
+
-webkit-user-select: none; /* Safari */
|
84 |
+
-khtml-user-select: none; /* Konqueror HTML */
|
85 |
+
-moz-user-select: none; /* Old versions of Firefox */
|
86 |
+
-ms-user-select: none; /* Internet Explorer/Edge */
|
87 |
+
user-select: none; /* Non-prefixed version, currently
|
88 |
+
supported by Chrome, Opera and Firefox */
|
89 |
+
}
|
90 |
+
/* copied from bootstrap */
|
91 |
+
.wt-iew-form-table input[type="text"], .wt-iew-form-table input[type="number"], .wt-iew-form-table input[type="password"], .wt-iew-form-table select, .wt_iew_select, .wt_iew_text{
|
92 |
+
display: block;
|
93 |
+
width:100%;
|
94 |
+
padding: 0.35rem 0.75rem;
|
95 |
+
font-size: 1rem;
|
96 |
+
line-height: 1.5;
|
97 |
+
color: #495057;
|
98 |
+
background-color: #fff;
|
99 |
+
background-clip: padding-box;
|
100 |
+
border: 1px solid #ced4da;
|
101 |
+
border-radius: 0.25rem;
|
102 |
+
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
|
103 |
+
height:36px;
|
104 |
+
max-width:none;
|
105 |
+
}
|
106 |
+
.wt-iew-form-table *::placeholder{ font-size:12px; }
|
107 |
+
.wt-iew-form-table .select2-container .select2-selection--multiple{ border-color:#ced4da !important; }
|
108 |
+
|
109 |
+
|
110 |
+
.wt-iew-form-table select, .wt_iew_select{
|
111 |
+
padding: 0.44rem 0.75rem;
|
112 |
+
}
|
113 |
+
.wt-iew-form-table textarea{
|
114 |
+
display: block;
|
115 |
+
width:100%;
|
116 |
+
padding: 0.375rem 0.75rem;
|
117 |
+
font-size: 1rem;
|
118 |
+
line-height: 1.5;
|
119 |
+
color: #495057;
|
120 |
+
background-color: #fff;
|
121 |
+
background-clip: padding-box;
|
122 |
+
border: 1px solid #ced4da;
|
123 |
+
border-radius: 0.25rem;
|
124 |
+
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
|
125 |
+
}
|
126 |
+
.wt-iew-form-table .select2-selection, .wt-iew-form-table .select2-selection.select2-selection--multiple{
|
127 |
+
display: block;
|
128 |
+
width:100%;
|
129 |
+
color: #495057;
|
130 |
+
background-color: #fff;
|
131 |
+
background-clip: padding-box;
|
132 |
+
border: 1px solid #ced4da;
|
133 |
+
border-radius: 0.25rem;
|
134 |
+
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
|
135 |
+
min-height: 60px; font-size: 12px;
|
136 |
+
}
|
137 |
+
.wt-iew-form-table .select2-container {
|
138 |
+
width:100% !important;
|
139 |
+
}
|
140 |
+
.wf_select_multi{
|
141 |
+
width:100%;
|
142 |
+
}
|
143 |
+
.wf_select_multi .select2-container{
|
144 |
+
width:100% !important;
|
145 |
+
}
|
146 |
+
.wt-iew-form-table .button {
|
147 |
+
padding:0.2rem 0.75rem; height: auto;
|
148 |
+
}
|
149 |
+
.wf_settings_form .button {
|
150 |
+
padding:0.2rem 0.75rem; height: auto;
|
151 |
+
}
|
152 |
+
.wt-iew_form_help{ color:#666;font-weight:400; font-size:12px; display:inline-block; width:100%; margin-top:10px; }
|
153 |
+
.wt-iew_conditional_help_text{ display:none;}
|
154 |
+
.wt-iew-form-table tr th:first-child{ width:25%; padding:10px 15px 10px 0; vertical-align:top; }
|
155 |
+
.wt-iew-form-table tr th:first-child label{ margin-top:5px; display:inline-block; }
|
156 |
+
.wt-iew-form-table tr td:nth-child(2){ width:40%; padding:10px 5px 10px 0; }
|
157 |
+
.wt-iew-form-table tr td:nth-child(3){ width:35%; }
|
158 |
+
.wt_form_radio_block, .wt_form_checkbox_block{ display:inline-block; margin-top:8px; }
|
159 |
+
.wt-iew-tab-container .wp-list-table thead th{ font-weight:bold; }
|
160 |
+
.wt-iew-exporter-step-btn, .wt-iew-exporter-step-export-btn{ float:right; }
|
161 |
+
|
162 |
+
.wt-iew-form-table select.wt_iew_delimiter_preset{ width:70%; float:left; }
|
163 |
+
.wt-iew-form-table input[type="text"].wt_iew_custom_delimiter{ width:25%; float:right; }
|
164 |
+
|
165 |
+
.wt-iew-form-table select.wt_iew_date_format_preset{ width:70%; float:left; }
|
166 |
+
.wt-iew-form-table input[type="text"].wt_iew_custom_date_format{ width:25%; float:right; }
|
167 |
+
|
168 |
+
|
169 |
+
.wt_iew_warn_box{padding:20px; padding-bottom:0px;}
|
170 |
+
.wt_iew_warn{ display:inline-block; width:100%; box-sizing:border-box; padding:10px; background-color:#fff8e5; border-left:solid 2px #ffb900; color:#333; }
|
171 |
+
.wt_iew_rerun_warn{ width:95%; margin:30px 2.5%; }
|
172 |
+
|
173 |
+
.wt_iew_info_box{padding:20px; padding-bottom:0px;}
|
174 |
+
.wt_iew_info{ display:inline-block; width:100%; box-sizing:border-box; padding:10px; background-color:#d1ecf1; border-left:solid 2px #0c5460; color:#185b8d; }
|
175 |
+
|
176 |
+
|
177 |
+
/* mapping step */
|
178 |
+
.wt-iew-mapping-tb{ border:1px solid #e5e5e5; width:90%; max-width:700px; }
|
179 |
+
.wt-iew-mapping-tb th{ text-align:left; height:30px; /* background:#e5e5e5; */ border-bottom:solid 1px #e5e5e5; }
|
180 |
+
.wt-iew-mapping-tb tr td:first-child, .wt-iew-mapping-tb tr th:first-child{ width:50px; }
|
181 |
+
.wt-iew-mapping-tb td, .wt-iew-mapping-tb th{ padding:5px; }
|
182 |
+
.wt-iew-mapping-tb td input[type="text"], .wt_iew_text_field{
|
183 |
+
display: block;
|
184 |
+
max-width:500px;
|
185 |
+
width:100%;
|
186 |
+
color: #495057;
|
187 |
+
background-clip: padding-box;
|
188 |
+
border: 1px solid #ced4da !important;
|
189 |
+
border-radius: 0.25rem;
|
190 |
+
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
|
191 |
+
height:32px;
|
192 |
+
}
|
193 |
+
.wt_iew_sort_handle{ width:25px; cursor:move; }
|
194 |
+
.wt-iew-mapping-tb tbody tr:hover td{ background:#f6f6f6; }
|
195 |
+
.wt-iew-mapping-tb .wt_iew_mapping_checkbox_main{ margin-left:29px; }
|
196 |
+
.wt-iew-mapping-tb .wt_iew_mapping_checkbox_sub{ margin-left:4px; margin-top:6px; }
|
197 |
+
.wt_iew_sort_handle{ float:left; }
|
198 |
+
.wt_iew_sort_handle img{ margin-top:5px; color:#ccc; height:15px; opacity:.8; }
|
199 |
+
.wt_iew_checkbox{ display:inline-block; padding:0px 15px; }
|
200 |
+
.wt_iew_mapping_field_val{ width:100%; min-height:32px; display:inline-block; background:#fff; padding:5px 5px; box-sizing:border-box; border:solid 1px #ced4da; border-radius:0.25rem; cursor:text; }
|
201 |
+
|
202 |
+
.wt-iew-sortable-placeholder td{ height:30px; background:#fff; border-top:dashed 1px #ccc; border-bottom:dashed 1px #ccc; }
|
203 |
+
.wt-iew-sortable-placeholder td:first-child{ border:dashed 1px #ccc; border-right:none; }
|
204 |
+
.wt-iew-sortable-placeholder td:last-child{ border:dashed 1px #ccc; border-left:none; }
|
205 |
+
|
206 |
+
.meta_mapping_box{width:100%; float:left; height:auto; margin-bottom:0px;}
|
207 |
+
.meta_mapping_box_hd{min-width:720px; width:auto; display:inline-block; height:40px; line-height:40px; font-weight:bold; background:#f6f6f6; box-sizing:border-box; padding:2px 10px; box-shadow:1px 1px 1px #e0e0e0; border-bottom:solid 1px #ccc; border-top:solid 1px #fff; cursor:pointer;}
|
208 |
+
.meta_mapping_box_hd_nil{min-width:720px; width:auto; display:inline-block; height:40px; line-height:40px; font-weight:bold; background:#f6f6f6; box-sizing:border-box; padding:2px 10px; box-shadow:1px 1px 1px #e0e0e0; border-bottom:solid 1px #ccc; border-top:solid 1px #fff; cursor:pointer;}
|
209 |
+
.meta_mapping_box_hd .dashicons{ margin-top:10px; }
|
210 |
+
.meta_mapping_box_selected_count_box{ float:right; margin-top:-3px; font-weight:normal; font-style:italic; }
|
211 |
+
.meta_mapping_box_con{min-width:720px; width:auto; display:inline-block; height:auto; padding:0px; display:none;}
|
212 |
+
.wt-iew-mapping-tb{ min-width:720px; }
|
213 |
+
.meta_mapping_box_toggle{ font-weight:normal; float:right; cursor:pointer; }
|
214 |
+
.wt_iew_invalid_mapping_field{ color:red; display:inline-block !important; padding:0px !important; margin:0px !important; }
|
215 |
+
|
216 |
+
|
217 |
+
/* popup */
|
218 |
+
.wt_iew_overlay{ position:fixed; z-index:100000000; width:100%; height:100%; background-color:rgba(0,0,0,.5); left:0px; top:0px; display:none;}
|
219 |
+
.wt_iew_popup{position:fixed; z-index:100000001; background:#fff; border:solid 1px #eee; text-align:center; box-shadow:0px 2px 5px #333; left:50%; display:none;}
|
220 |
+
.wt_iew_popup_hd{display:inline-block; width:100%; box-sizing:border-box; font-weight:bold; background-color:#f3f3f3; height:40px; text-align:left; line-height:40px; padding:0px 20px;}
|
221 |
+
.wt_iew_popup_close{float:right; width:40px; height:40px; text-align:right; line-height:40px; cursor:pointer;}
|
222 |
+
.wt_iew_popup_footer{width:100%; text-align:right; margin-top:10px;}
|
223 |
+
|
224 |
+
.wt_iew_data_dv{ display:none; }
|
225 |
+
.wt_iew_action_btn{ cursor:pointer; }
|
226 |
+
|
227 |
+
.wt-iew-form-table .wt_iew_radio_block p{ margin-bottom:15px; line-height:18px; }
|
228 |
+
.wt-iew-form-table .wt_iew_radio_block span{ display:inline-block; padding-left:25px; }
|
229 |
+
.wt-iew-form-table .wt_iew_radio_block b{ display:inline-block; margin-left:5px; }
|
230 |
+
|
231 |
+
.wt-iew-form-table .wt_iew_field_group{ padding-left:0px; }
|
232 |
+
.wt-iew-form-table .wt_iew_field_group_hd{ display:block; border-bottom:dashed 1px #ccc; padding-bottom:5px; padding-top:20px; font-size:15px; font-weight:bold; cursor:pointer; }
|
233 |
+
.wt-iew-form-table .wt_iew_field_group_hd .wt_iew_field_group_toggle_btn{float:left; margin-right:10px; width:20px; height:20px; border-radius:10px; color:#666; cursor:pointer; }
|
234 |
+
.wt-iew-form-table .wt_iew_field_group_content{ padding-left:10px; display:none; }
|
235 |
+
|
236 |
+
|
237 |
+
/* Dropdown */
|
238 |
+
.wt_iew_dropdown{ position:absolute; z-index:100; background:#fff; border:1px solid #ccc; border-radius:4px; padding:0px; display:none; box-shadow:1px 3px 2px 2px rgba(0,0,0,0.1); }
|
239 |
+
.wt_iew_dropdown li{ padding:7px 14px; margin:5px 0px; cursor:pointer; }
|
240 |
+
.wt_iew_dropdown li:hover{ background:#fafafa; }
|
241 |
+
|
242 |
+
/* template saving popup */
|
243 |
+
.wt_iew_template_name{width:100%; max-width:320px;}
|
244 |
+
.wt_iew_template_name_box{ float:left; width:90%; padding:5%; padding-top:0px; }
|
245 |
+
.wt_iew_template_name_wrn{display:none; text-align:left; }
|
246 |
+
.wt_iew_template_name_label{ display:inline-block; width:100%; text-align:left; font-weight:bold; padding:3px 0px; }
|
247 |
+
|
248 |
+
/* file attacher */
|
249 |
+
.wt-iew-form-table .wt_iew_file_attacher_dv{width:100%; }
|
250 |
+
.wt-iew-form-table .wt_iew_file_attacher_dv input[type="text"]{width:70%; float:left; }
|
251 |
+
.wt-iew-form-table .wt_iew_file_attacher_dv input[type="button"]{width:25%; float:right; }
|
252 |
+
.wt_iew_file_attacher_dv{ float:left; width:100%; }
|
253 |
+
|
254 |
+
/* popover */
|
255 |
+
.wt_iew_popover{ position: absolute; min-width:250px; min-height:150px; height: auto; background: #fff; border-radius: 5px; box-shadow: 0 5px 10px rgba(0,0,0,.2); top:50px; border: 1px solid #ccc;}
|
256 |
+
.wt_iew_popover:after, .wt_iew_popover:before {
|
257 |
+
right: 100%;
|
258 |
+
top:25%;
|
259 |
+
border: solid transparent;
|
260 |
+
content: " ";
|
261 |
+
height: 0;
|
262 |
+
width: 0;
|
263 |
+
position: absolute;
|
264 |
+
pointer-events: none;
|
265 |
+
}
|
266 |
+
|
267 |
+
.wt_iew_popover:after {
|
268 |
+
border-color: rgba(255, 255, 255, 0);
|
269 |
+
border-right-color: #fff;
|
270 |
+
border-width: 20px;
|
271 |
+
margin-top: -20px;
|
272 |
+
}
|
273 |
+
.wt_iew_popover:before {
|
274 |
+
border-color: rgba(204, 204, 204, 0);
|
275 |
+
border-right-color: #ccc;
|
276 |
+
border-width: 21px;
|
277 |
+
margin-top: -21px;
|
278 |
+
}
|
279 |
+
.wt_iew_popover-title{ background:#f7f7f7; height:35px;
|
280 |
+
margin: 0px;
|
281 |
+
border-top-left-radius: 5px;
|
282 |
+
border-top-right-radius: 5px; padding:5px; padding-left: 15px; line-height: 35px; font-size: 14px;}
|
283 |
+
.popover_close_icon_button{ float:right; height:20px; width:20px; border-radius:20px; color:#fff; background:#666; padding:3px; font-weight:bold; text-align:center; line-height:20px; margin-top:5px; margin-right:5px; cursor:pointer; }
|
284 |
+
.wt_iew_popover-content{
|
285 |
+
min-height:65px; height: auto; padding:15px; float:left; clear:both;
|
286 |
+
}
|
287 |
+
.wt_iew_popover-footer{ background:#f7f7f7; clear:both; height:30px; margin:0px; margin-top:10px; border-bottom-left-radius:5px; border-bottom-right-radius:5px; padding:7px 15px;}
|
288 |
+
.wt_iew_popover-content input[type="text"]{
|
289 |
+
margin:5px 0px; border-radius:3px; padding: 0.2rem 0.3rem;
|
290 |
+
font-size: 1rem;
|
291 |
+
line-height: 1.5;
|
292 |
+
}
|
293 |
+
.wt_iew_popover-footer .button{
|
294 |
+
float: right; margin-left: 5px;
|
295 |
+
}
|
296 |
+
|
297 |
+
/* mapping field editor */
|
298 |
+
.wt_iew_mapping_field_editor_container{ display:none; }
|
299 |
+
.wt_iew_mapping_field_editor{ float:left; width:400px; padding:0px; background:#fff; margin:0px;}
|
300 |
+
.wt_iew_mapping_field_editor *{ box-sizing:border-box; }
|
301 |
+
.wt_iew_mapping_field_editor label{ float:left; width:100%; margin-bottom:3px; font-weight:bold; font-size:13px; color:#333; }
|
302 |
+
.wt_iew_mapping_field_editor_box{border:solid 1px #ddd; float:left; width:100%; height:auto; min-height:50px; padding:3px; margin-bottom:10px; margin-top:5px;}
|
303 |
+
.wt_iew_mapping_field_editor_box textarea{border:none; float:left; width:100%; height:50px; outline:none; resize:none;}
|
304 |
+
.wt_iew_mapping_field_editor_box input[type="text"]{width:100%; font-size:12px;}
|
305 |
+
.wt_iew_mapping_field_editor_box input[type="text"]::placeholder{ font-size:12px; }
|
306 |
+
.wt_iew_mapping_field_editor_info{ margin:0px; }
|
307 |
+
.wt_iew_mapping_field_editor_er{ margin:0px; color:red; }
|
308 |
+
.wt_iew_mapping_field_selector_box{ float:left; width:100%; height:120px; overflow:auto; margin-top:5px; }
|
309 |
+
.wt_iew_mapping_field_selector{ float:left; width:100%; margin:0px; padding:0px; }
|
310 |
+
.wt_iew_mapping_field_selector li{ float:left; width:100%; padding:5px; margin:0px; cursor:pointer;}
|
311 |
+
.wt_iew_mapping_field_selector li:hover{ background:#0073aa; color:#fff; }
|
312 |
+
.wt_iew_mapping_field_selector_no_column{ float:left; width:100%; color:red; }
|
313 |
+
.wt_iew_no_sample_mapping_data{ color:gray; display:inline-block !important; padding:0px !important; margin:0px !important; font-style:italic; }
|
314 |
+
|
315 |
+
/* debug panel */
|
316 |
+
.wt_iew_debug_panel{ position:fixed; top:30px; right:0px; background:#fff; padding:5px; padding-bottom:0px; box-shadow:2px 2px 2px #ccc; }
|
317 |
+
.wt_iew_debug_panel_hd{ width:100%; font-size:12px; font-weight:bold; padding:2px; }
|
318 |
+
.wt_iew_debug_panel_con{ width:100%; min-height:30px; font-size:12px; text-align:center;}
|
319 |
+
.wt_iew_debug_panel_con a{ display:inline-block; padding:2px; border-right:solid 1px #ccc; cursor:pointer; }
|
320 |
+
.wt_iew_debug_panel_con a:last-child{ border-right:solid 0px #ccc; }
|
321 |
+
|
322 |
+
/* pagination */
|
323 |
+
.wt_iew_pagination{ float:right; width:auto; height:auto; margin:10px 0px;}
|
324 |
+
.wt_iew_pagination a{ float:left; padding:6px 12px; background:#f3f5f6; border:solid 1px #cccccc; color:#2e8ab6; text-decoration:none; margin-right:5px; border-radius:5px; }
|
325 |
+
.wt_iew_pagination a.wt_iew_pageactive{ background:#fff; color:#333; border:solid 1px #ddd; }
|
326 |
+
.wt_iew_pagination a.wt_iew_pagedisabled{ background:#f7f7f7; color:#a0a5aa; border:solid 1px #ddd; }
|
327 |
+
.wt_iew_pagination a.wt_iew_page{ cursor:pointer; }
|
328 |
+
.wt_iew_pagination_total_info{ float:left; padding:8px; }
|
329 |
+
|
330 |
+
/* listing */
|
331 |
+
.wt_iew_badge{ display:inline-block; padding:2px 6px; font-size:12px; border-radius:3px; background:#ccc; color:#fff; text-align:center; }
|
332 |
+
|
333 |
+
/* responsive */
|
334 |
+
@media (max-width:768px) {
|
335 |
+
.wt-iew-form-table tr th:first-child{ width:100%; }
|
336 |
+
.wt-iew-form-table tr td:nth-child(2){ width:100%; }
|
337 |
+
.wt-iew-form-table tr td:nth-child(3){ width:100%; }
|
338 |
+
.wt-iew-form-table .wt_iew_file_attacher_dv input[type="text"]{width:50%; float:left; }
|
339 |
+
.wt-iew-form-table .wt_iew_file_attacher_dv input[type="button"]{width:45%; float:right; }
|
340 |
+
}
|
341 |
+
|
342 |
+
/* tooltip */
|
343 |
+
.wt-iew-tips{ color:#16a7c5; }
|
344 |
+
.wt_iew_tooltip_span{ display:inline-block; margin-bottom:9px; line-height:16px; text-align:left; border-top:
|
345 |
+
dashed 1px #efefef; }
|
346 |
+
#tiptip_content .wt_iew_tooltip_span:first-child{ border:none; margin-top:4px; }
|
347 |
+
#tiptip_content .wt_iew_tooltip_span:last-child{ margin-bottom:4px; }
|
348 |
+
.tips {
|
349 |
+
cursor:help;
|
350 |
+
text-decoration:none
|
351 |
+
}
|
352 |
+
img.tips {
|
353 |
+
padding:5px 0 0
|
354 |
+
}
|
355 |
+
#tiptip_holder {
|
356 |
+
display:none;
|
357 |
+
z-index:8675309;
|
358 |
+
position:absolute;
|
359 |
+
top:0;
|
360 |
+
left:0
|
361 |
+
}
|
362 |
+
#tiptip_holder.tip_top {
|
363 |
+
padding-bottom:5px
|
364 |
+
}
|
365 |
+
#tiptip_holder.tip_top #tiptip_arrow_inner {
|
366 |
+
margin-top:-7px;
|
367 |
+
margin-left:-6px;
|
368 |
+
border-top-color:#333
|
369 |
+
}
|
370 |
+
#tiptip_holder.tip_bottom {
|
371 |
+
padding-top:5px
|
372 |
+
}
|
373 |
+
#tiptip_holder.tip_bottom #tiptip_arrow_inner {
|
374 |
+
margin-top:-5px;
|
375 |
+
margin-left:-6px;
|
376 |
+
border-bottom-color:#333
|
377 |
+
}
|
378 |
+
#tiptip_holder.tip_right {
|
379 |
+
padding-left:5px
|
380 |
+
}
|
381 |
+
#tiptip_holder.tip_right #tiptip_arrow_inner {
|
382 |
+
margin-top:-6px;
|
383 |
+
margin-left:-5px;
|
384 |
+
border-right-color:#333
|
385 |
+
}
|
386 |
+
#tiptip_holder.tip_left {
|
387 |
+
padding-right:5px
|
388 |
+
}
|
389 |
+
#tiptip_holder.tip_left #tiptip_arrow_inner {
|
390 |
+
margin-top:-6px;
|
391 |
+
margin-left:-7px;
|
392 |
+
border-left-color:#333
|
393 |
+
}
|
394 |
+
#tiptip_content,
|
395 |
+
.chart-tooltip,
|
396 |
+
.wc_error_tip {
|
397 |
+
color:#fff;
|
398 |
+
font-size:.8em;
|
399 |
+
max-width:150px;
|
400 |
+
background:#333;
|
401 |
+
text-align:center;
|
402 |
+
border-radius:3px;
|
403 |
+
padding:.618em 1em;
|
404 |
+
box-shadow:0 1px 3px rgba(0,
|
405 |
+
0,
|
406 |
+
0,
|
407 |
+
.2)
|
408 |
+
}
|
409 |
+
#tiptip_content code,
|
410 |
+
.chart-tooltip code,
|
411 |
+
.wc_error_tip code {
|
412 |
+
padding:1px;
|
413 |
+
background:#888
|
414 |
+
}
|
415 |
+
#tiptip_arrow,
|
416 |
+
#tiptip_arrow_inner {
|
417 |
+
position:absolute;
|
418 |
+
border-color:transparent;
|
419 |
+
border-style:solid;
|
420 |
+
border-width:6px;
|
421 |
+
height:0;
|
422 |
+
width:0
|
423 |
+
}
|
424 |
+
|
425 |
+
/**
|
426 |
+
* Dropzone: Drag and Drop file upload
|
427 |
+
*/
|
428 |
+
.wt_iew_dropzone{ text-align:center; cursor:pointer; width:100%; height:200px; border:dashed 3px #ccc; }
|
429 |
+
.wt_iew_dropzone.wt_drag_start{ border-color:#92b0b3; background:#c8dadf; }
|
430 |
+
.dz-preview{ width:300px; display:inline-block; margin-top:70px; }
|
431 |
+
.dz-message{ font-size:1.5em; margin-top:85px; line-height:14px; }
|
432 |
+
.wt_iew_dropzone .dz-preview .dz-details{ font-size:14px}
|
433 |
+
.wt_iew_dropzone .dz-preview.dz-processing .dz-progress{ opacity:1;-webkit-transition:all .2s linear;-moz-transition:all .2s linear;-ms-transition:all .2s linear;-o-transition:all .2s linear;transition:all .2s linear}
|
434 |
+
.wt_iew_dropzone .dz-preview.dz-complete .dz-progress{opacity:0;-webkit-transition:opacity .4s ease-in;-moz-transition:opacity .4s ease-in;-ms-transition:opacity .4s ease-in;-o-transition:opacity .4s ease-in;transition:opacity .4s ease-in}
|
435 |
+
.wt_iew_dropzone .dz-preview:not(.dz-processing) .dz-progress{-webkit-animation:pulse 6s ease infinite;-moz-animation:pulse 6s ease infinite;-ms-animation:pulse 6s ease infinite;-o-animation:pulse 6s ease infinite;animation:pulse 6s ease infinite}
|
436 |
+
.wt_iew_dropzone .dz-preview .dz-progress{opacity:1;z-index:1000;pointer-events:none;position:absolute;height:16px;margin-top:-8px;margin-left:-40px;background:rgba(255,255,255,.9);-webkit-transform:scale(1);border-radius:8px;overflow:hidden}
|
437 |
+
.wt_iew_dropzone .dz-preview .dz-progress .dz-upload{background:#333;background:linear-gradient(to bottom,#666,#444);position:absolute;top:0;left:0;bottom:0;width:0;-webkit-transition:width .3s ease-in-out;-moz-transition:width .3s ease-in-out;-ms-transition:width .3s ease-in-out;-o-transition:width .3s ease-in-out;transition:width .3s ease-in-out}
|
438 |
+
.wt_iew_dropzone .dz-preview .dz-progress{width:300px;margin-left:0;margin-top:5px}
|
439 |
+
.wt_iew_dropzone .dz-preview .dz-progress .dz-upload{background:#2092ea}
|
440 |
+
.wt_iew_dz_file_name, .wt_iew_dz_remove_link, .wt_iew_dz_file_success{ display:inline-block; font-size:14px; }
|
441 |
+
.wt_iew_dz_remove_link{ cursor:pointer; color:#4289a9; }
|
442 |
+
.wt_iew_dz_file_success{ line-height:20px; }
|
443 |
+
.wt_iew_dropzone .dz-preview .dz-progress .dz-upload-info{display:inline-block;text-align:center;width:100%;}
|
444 |
+
.wt_iew_dropzone.dz-started .dz-message{ display:none;}
|
445 |
+
|
admin/index.php
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
<?php // Silence is golden
|
admin/js/dropzone.min.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _possibleConstructorReturn(e,t){return!t||"object"!==_typeof(t)&&"function"!=typeof t?_assertThisInitialized(e):t}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),e}var Emitter=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"on",value:function(e,t){return this._callbacks=this._callbacks||{},this._callbacks[e]||(this._callbacks[e]=[]),this._callbacks[e].push(t),this}},{key:"emit",value:function(e){this._callbacks=this._callbacks||{};var t=this._callbacks[e];if(t){for(var n=arguments.length,i=new Array(1<n?n-1:0),r=1;r<n;r++)i[r-1]=arguments[r];var o=!0,a=!1,l=void 0;try{for(var s,u=t[Symbol.iterator]();!(o=(s=u.next()).done);o=!0){s.value.apply(this,i)}}catch(e){a=!0,l=e}finally{try{o||null==u.return||u.return()}finally{if(a)throw l}}}return this}},{key:"off",value:function(e,t){if(!this._callbacks||0===arguments.length)return this._callbacks={},this;var n=this._callbacks[e];if(!n)return this;if(1===arguments.length)return delete this._callbacks[e],this;for(var i=0;i<n.length;i++){if(n[i]===t){n.splice(i,1);break}}return this}}]),e}(),Dropzone=function(){function C(e,t){var n,i,r;if(_classCallCheck(this,C),(n=_possibleConstructorReturn(this,_getPrototypeOf(C).call(this))).element=e,n.version=C.version,n.defaultOptions.previewTemplate=n.defaultOptions.previewTemplate.replace(/\n*/g,""),n.clickableElements=[],n.listeners=[],n.files=[],"string"==typeof n.element&&(n.element=document.querySelector(n.element)),!n.element||null==n.element.nodeType)throw new Error("Invalid dropzone element.");if(n.element.dropzone)throw new Error("Dropzone already attached.");C.instances.push(_assertThisInitialized(n)),n.element.dropzone=_assertThisInitialized(n);var o=null!=(r=C.optionsForElement(n.element))?r:{};if(n.options=C.extend({},n.defaultOptions,o,null!=t?t:{}),n.options.forceFallback||!C.isBrowserSupported())return _possibleConstructorReturn(n,n.options.fallback.call(_assertThisInitialized(n)));if(null==n.options.url&&(n.options.url=n.element.getAttribute("action")),!n.options.url)throw new Error("No URL provided.");if(n.options.acceptedFiles&&n.options.acceptedMimeTypes)throw new Error("You can't provide both 'acceptedFiles' and 'acceptedMimeTypes'. 'acceptedMimeTypes' is deprecated.");if(n.options.uploadMultiple&&n.options.chunking)throw new Error("You cannot set both: uploadMultiple and chunking.");return n.options.acceptedMimeTypes&&(n.options.acceptedFiles=n.options.acceptedMimeTypes,delete n.options.acceptedMimeTypes),null!=n.options.renameFilename&&(n.options.renameFile=function(e){return n.options.renameFilename.call(_assertThisInitialized(n),e.name,e)}),n.options.method=n.options.method.toUpperCase(),(i=n.getExistingFallback())&&i.parentNode&&i.parentNode.removeChild(i),!1!==n.options.previewsContainer&&(n.options.previewsContainer?n.previewsContainer=C.getElement(n.options.previewsContainer,"previewsContainer"):n.previewsContainer=n.element),n.options.clickable&&(!0===n.options.clickable?n.clickableElements=[n.element]:n.clickableElements=C.getElements(n.options.clickable,"clickable")),n.init(),n}return _inherits(C,Emitter),_createClass(C,null,[{key:"initClass",value:function(){this.prototype.Emitter=Emitter,this.prototype.events=["drop","dragstart","dragend","dragenter","dragover","dragleave","addedfile","addedfiles","removedfile","thumbnail","error","errormultiple","processing","processingmultiple","uploadprogress","totaluploadprogress","sending","sendingmultiple","success","successmultiple","canceled","canceledmultiple","complete","completemultiple","reset","maxfilesexceeded","maxfilesreached","queuecomplete"],this.prototype.defaultOptions={url:null,method:"post",withCredentials:!1,timeout:3e4,parallelUploads:2,uploadMultiple:!1,chunking:!1,forceChunking:!1,chunkSize:2e6,parallelChunkUploads:!1,retryChunks:!1,retryChunksLimit:3,maxFilesize:256,paramName:"file",createImageThumbnails:!0,maxThumbnailFilesize:10,thumbnailWidth:120,thumbnailHeight:120,thumbnailMethod:"crop",resizeWidth:null,resizeHeight:null,resizeMimeType:null,resizeQuality:.8,resizeMethod:"contain",filesizeBase:1e3,maxFiles:null,headers:null,clickable:!0,ignoreHiddenFiles:!0,acceptedFiles:null,acceptedMimeTypes:null,autoProcessQueue:!0,autoQueue:!0,addRemoveLinks:!1,previewsContainer:null,hiddenInputContainer:"body",capture:null,renameFilename:null,renameFile:null,forceFallback:!1,dictDefaultMessage:"Drop files here to upload",dictFallbackMessage:"Your browser does not support drag'n'drop file uploads.",dictFallbackText:"Please use the fallback form below to upload your files like in the olden days.",dictFileTooBig:"File is too big ({{filesize}}MiB). Max filesize: {{maxFilesize}}MiB.",dictInvalidFileType:"You can't upload files of this type.",dictResponseError:"Server responded with {{statusCode}} code.",dictCancelUpload:"Cancel upload",dictUploadCanceled:"Upload canceled.",dictCancelUploadConfirmation:"Are you sure you want to cancel this upload?",dictRemoveFile:"Remove file",dictRemoveFileConfirmation:null,dictMaxFilesExceeded:"You can not upload any more files.",dictFileSizeUnits:{tb:"TB",gb:"GB",mb:"MB",kb:"KB",b:"b"},init:function(){},params:function(e,t,n){if(n)return{dzuuid:n.file.upload.uuid,dzchunkindex:n.index,dztotalfilesize:n.file.size,dzchunksize:this.options.chunkSize,dztotalchunkcount:n.file.upload.totalChunkCount,dzchunkbyteoffset:n.index*this.options.chunkSize}},accept:function(e,t){return t()},chunksUploaded:function(e,t){t()},fallback:function(){var e;this.element.className="".concat(this.element.className," dz-browser-not-supported");var t=!0,n=!1,i=void 0;try{for(var r,o=this.element.getElementsByTagName("div")[Symbol.iterator]();!(t=(r=o.next()).done);t=!0){var a=r.value;if(/(^| )dz-message($| )/.test(a.className)){(e=a).className="dz-message";break}}}catch(e){n=!0,i=e}finally{try{t||null==o.return||o.return()}finally{if(n)throw i}}e||(e=C.createElement('<div class="dz-message"><span></span></div>'),this.element.appendChild(e));var l=e.getElementsByTagName("span")[0];return l&&(null!=l.textContent?l.textContent=this.options.dictFallbackMessage:null!=l.innerText&&(l.innerText=this.options.dictFallbackMessage)),this.element.appendChild(this.getFallbackForm())},resize:function(e,t,n,i){var r={srcX:0,srcY:0,srcWidth:e.width,srcHeight:e.height},o=e.width/e.height;null==t&&null==n?(t=r.srcWidth,n=r.srcHeight):null==t?t=n*o:null==n&&(n=t/o);var a=(t=Math.min(t,r.srcWidth))/(n=Math.min(n,r.srcHeight));if(r.srcWidth>t||r.srcHeight>n)if("crop"===i)a<o?(r.srcHeight=e.height,r.srcWidth=r.srcHeight*a):(r.srcWidth=e.width,r.srcHeight=r.srcWidth/a);else{if("contain"!==i)throw new Error("Unknown resizeMethod '".concat(i,"'"));a<o?n=t/o:t=n*o}return r.srcX=(e.width-r.srcWidth)/2,r.srcY=(e.height-r.srcHeight)/2,r.trgWidth=t,r.trgHeight=n,r},transformFile:function(e,t){return(this.options.resizeWidth||this.options.resizeHeight)&&e.type.match(/image.*/)?this.resizeImage(e,this.options.resizeWidth,this.options.resizeHeight,this.options.resizeMethod,t):t(e)},previewTemplate:'<div class="dz-preview dz-file-preview">\n <div class="dz-image"><img data-dz-thumbnail /></div>\n <div class="dz-details">\n <div class="dz-size"><span data-dz-size></span></div>\n <div class="dz-filename"><span data-dz-name></span></div>\n </div>\n <div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress></span></div>\n <div class="dz-error-message"><span data-dz-errormessage></span></div>\n <div class="dz-success-mark">\n <svg width="54px" height="54px" viewBox="0 0 54 54" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">\n <title>Check</title>\n <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">\n <path d="M23.5,31.8431458 L17.5852419,25.9283877 C16.0248253,24.3679711 13.4910294,24.366835 11.9289322,25.9289322 C10.3700136,27.4878508 10.3665912,30.0234455 11.9283877,31.5852419 L20.4147581,40.0716123 C20.5133999,40.1702541 20.6159315,40.2626649 20.7218615,40.3488435 C22.2835669,41.8725651 24.794234,41.8626202 26.3461564,40.3106978 L43.3106978,23.3461564 C44.8771021,21.7797521 44.8758057,19.2483887 43.3137085,17.6862915 C41.7547899,16.1273729 39.2176035,16.1255422 37.6538436,17.6893022 L23.5,31.8431458 Z M27,53 C41.3594035,53 53,41.3594035 53,27 C53,12.6405965 41.3594035,1 27,1 C12.6405965,1 1,12.6405965 1,27 C1,41.3594035 12.6405965,53 27,53 Z" stroke-opacity="0.198794158" stroke="#747474" fill-opacity="0.816519475" fill="#FFFFFF"></path>\n </g>\n </svg>\n </div>\n <div class="dz-error-mark">\n <svg width="54px" height="54px" viewBox="0 0 54 54" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">\n <title>Error</title>\n <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">\n <g stroke="#747474" stroke-opacity="0.198794158" fill="#FFFFFF" fill-opacity="0.816519475">\n <path d="M32.6568542,29 L38.3106978,23.3461564 C39.8771021,21.7797521 39.8758057,19.2483887 38.3137085,17.6862915 C36.7547899,16.1273729 34.2176035,16.1255422 32.6538436,17.6893022 L27,23.3431458 L21.3461564,17.6893022 C19.7823965,16.1255422 17.2452101,16.1273729 15.6862915,17.6862915 C14.1241943,19.2483887 14.1228979,21.7797521 15.6893022,23.3461564 L21.3431458,29 L15.6893022,34.6538436 C14.1228979,36.2202479 14.1241943,38.7516113 15.6862915,40.3137085 C17.2452101,41.8726271 19.7823965,41.8744578 21.3461564,40.3106978 L27,34.6568542 L32.6538436,40.3106978 C34.2176035,41.8744578 36.7547899,41.8726271 38.3137085,40.3137085 C39.8758057,38.7516113 39.8771021,36.2202479 38.3106978,34.6538436 L32.6568542,29 Z M27,53 C41.3594035,53 53,41.3594035 53,27 C53,12.6405965 41.3594035,1 27,1 C12.6405965,1 1,12.6405965 1,27 C1,41.3594035 12.6405965,53 27,53 Z"></path>\n </g>\n </g>\n </svg>\n </div>\n</div>',drop:function(){return this.element.classList.remove("dz-drag-hover")},dragstart:function(){},dragend:function(){return this.element.classList.remove("dz-drag-hover")},dragenter:function(){return this.element.classList.add("dz-drag-hover")},dragover:function(){return this.element.classList.add("dz-drag-hover")},dragleave:function(){return this.element.classList.remove("dz-drag-hover")},paste:function(){},reset:function(){return this.element.classList.remove("dz-started")},addedfile:function(t){var n=this;if(this.element===this.previewsContainer&&this.element.classList.add("dz-started"),this.previewsContainer){t.previewElement=C.createElement(this.options.previewTemplate.trim()),t.previewTemplate=t.previewElement,this.previewsContainer.appendChild(t.previewElement);var e=!0,i=!1,r=void 0;try{for(var o,a=t.previewElement.querySelectorAll("[data-dz-name]")[Symbol.iterator]();!(e=(o=a.next()).done);e=!0){var l=o.value;l.textContent=t.name}}catch(e){i=!0,r=e}finally{try{e||null==a.return||a.return()}finally{if(i)throw r}}var s=!0,u=!1,c=void 0;try{for(var d,p=t.previewElement.querySelectorAll("[data-dz-size]")[Symbol.iterator]();!(s=(d=p.next()).done);s=!0)(l=d.value).innerHTML=this.filesize(t.size)}catch(e){u=!0,c=e}finally{try{s||null==p.return||p.return()}finally{if(u)throw c}}this.options.addRemoveLinks&&(t._removeLink=C.createElement('<a class="dz-remove" href="javascript:undefined;" data-dz-remove>'.concat(this.options.dictRemoveFile,"</a>")),t.previewElement.appendChild(t._removeLink));var h=function(e){return e.preventDefault(),e.stopPropagation(),t.status===C.UPLOADING?C.confirm(n.options.dictCancelUploadConfirmation,function(){return n.removeFile(t)}):n.options.dictRemoveFileConfirmation?C.confirm(n.options.dictRemoveFileConfirmation,function(){return n.removeFile(t)}):n.removeFile(t)},f=!0,v=!1,m=void 0;try{for(var y,g=t.previewElement.querySelectorAll("[data-dz-remove]")[Symbol.iterator]();!(f=(y=g.next()).done);f=!0){y.value.addEventListener("click",h)}}catch(e){v=!0,m=e}finally{try{f||null==g.return||g.return()}finally{if(v)throw m}}}},removedfile:function(e){return null!=e.previewElement&&null!=e.previewElement.parentNode&&e.previewElement.parentNode.removeChild(e.previewElement),this._updateMaxFilesReachedClass()},thumbnail:function(e,t){if(e.previewElement){e.previewElement.classList.remove("dz-file-preview");var n=!0,i=!1,r=void 0;try{for(var o,a=e.previewElement.querySelectorAll("[data-dz-thumbnail]")[Symbol.iterator]();!(n=(o=a.next()).done);n=!0){var l=o.value;l.alt=e.name,l.src=t}}catch(e){i=!0,r=e}finally{try{n||null==a.return||a.return()}finally{if(i)throw r}}return setTimeout(function(){return e.previewElement.classList.add("dz-image-preview")},1)}},error:function(e,t){if(e.previewElement){e.previewElement.classList.add("dz-error"),"String"!=typeof t&&t.error&&(t=t.error);var n=!0,i=!1,r=void 0;try{for(var o,a=e.previewElement.querySelectorAll("[data-dz-errormessage]")[Symbol.iterator]();!(n=(o=a.next()).done);n=!0){o.value.textContent=t}}catch(e){i=!0,r=e}finally{try{n||null==a.return||a.return()}finally{if(i)throw r}}}},errormultiple:function(){},processing:function(e){if(e.previewElement&&(e.previewElement.classList.add("dz-processing"),e._removeLink))return e._removeLink.innerHTML=this.options.dictCancelUpload},processingmultiple:function(){},uploadprogress:function(e,t){if(e.previewElement){var n=!0,i=!1,r=void 0;try{for(var o,a=e.previewElement.querySelectorAll("[data-dz-uploadprogress]")[Symbol.iterator]();!(n=(o=a.next()).done);n=!0){var l=o.value;"PROGRESS"===l.nodeName?l.value=t:l.style.width="".concat(t,"%")}}catch(e){i=!0,r=e}finally{try{n||null==a.return||a.return()}finally{if(i)throw r}}}},totaluploadprogress:function(){},sending:function(){},sendingmultiple:function(){},success:function(e){if(e.previewElement)return e.previewElement.classList.add("dz-success")},successmultiple:function(){},canceled:function(e){return this.emit("error",e,this.options.dictUploadCanceled)},canceledmultiple:function(){},complete:function(e){if(e._removeLink&&(e._removeLink.innerHTML=this.options.dictRemoveFile),e.previewElement)return e.previewElement.classList.add("dz-complete")},completemultiple:function(){},maxfilesexceeded:function(){},maxfilesreached:function(){},queuecomplete:function(){},addedfiles:function(){}},this.prototype._thumbnailQueue=[],this.prototype._processingThumbnail=!1}},{key:"extend",value:function(e){for(var t=arguments.length,n=new Array(1<t?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];for(var r=0,o=n;r<o.length;r++){var a=o[r];for(var l in a){var s=a[l];e[l]=s}}return e}}]),_createClass(C,[{key:"getAcceptedFiles",value:function(){return this.files.filter(function(e){return e.accepted}).map(function(e){return e})}},{key:"getRejectedFiles",value:function(){return this.files.filter(function(e){return!e.accepted}).map(function(e){return e})}},{key:"getFilesWithStatus",value:function(t){return this.files.filter(function(e){return e.status===t}).map(function(e){return e})}},{key:"getQueuedFiles",value:function(){return this.getFilesWithStatus(C.QUEUED)}},{key:"getUploadingFiles",value:function(){return this.getFilesWithStatus(C.UPLOADING)}},{key:"getAddedFiles",value:function(){return this.getFilesWithStatus(C.ADDED)}},{key:"getActiveFiles",value:function(){return this.files.filter(function(e){return e.status===C.UPLOADING||e.status===C.QUEUED}).map(function(e){return e})}},{key:"init",value:function(){var s=this;if("form"===this.element.tagName&&this.element.setAttribute("enctype","multipart/form-data"),this.element.classList.contains("dropzone")&&!this.element.querySelector(".dz-message")&&this.element.appendChild(C.createElement('<div class="dz-default dz-message"><button class="dz-button" type="button">'.concat(this.options.dictDefaultMessage,"</button></div>"))),this.clickableElements.length){!function l(){return s.hiddenFileInput&&s.hiddenFileInput.parentNode.removeChild(s.hiddenFileInput),s.hiddenFileInput=document.createElement("input"),s.hiddenFileInput.setAttribute("type","file"),(null===s.options.maxFiles||1<s.options.maxFiles)&&s.hiddenFileInput.setAttribute("multiple","multiple"),s.hiddenFileInput.className="dz-hidden-input",null!==s.options.acceptedFiles&&s.hiddenFileInput.setAttribute("accept",s.options.acceptedFiles),null!==s.options.capture&&s.hiddenFileInput.setAttribute("capture",s.options.capture),s.hiddenFileInput.style.visibility="hidden",s.hiddenFileInput.style.position="absolute",s.hiddenFileInput.style.top="0",s.hiddenFileInput.style.left="0",s.hiddenFileInput.style.height="0",s.hiddenFileInput.style.width="0",C.getElement(s.options.hiddenInputContainer,"hiddenInputContainer").appendChild(s.hiddenFileInput),s.hiddenFileInput.addEventListener("change",function(){var e=s.hiddenFileInput.files;if(e.length){var t=!0,n=!1,i=void 0;try{for(var r,o=e[Symbol.iterator]();!(t=(r=o.next()).done);t=!0){var a=r.value;s.addFile(a)}}catch(e){n=!0,i=e}finally{try{t||null==o.return||o.return()}finally{if(n)throw i}}}return s.emit("addedfiles",e),l()})}()}this.URL=null!==window.URL?window.URL:window.webkitURL;var e=!0,t=!1,n=void 0;try{for(var i,r=this.events[Symbol.iterator]();!(e=(i=r.next()).done);e=!0){var o=i.value;this.on(o,this.options[o])}}catch(e){t=!0,n=e}finally{try{e||null==r.return||r.return()}finally{if(t)throw n}}this.on("uploadprogress",function(){return s.updateTotalUploadProgress()}),this.on("removedfile",function(){return s.updateTotalUploadProgress()}),this.on("canceled",function(e){return s.emit("complete",e)}),this.on("complete",function(e){if(0===s.getAddedFiles().length&&0===s.getUploadingFiles().length&&0===s.getQueuedFiles().length)return setTimeout(function(){return s.emit("queuecomplete")},0)});function a(e){var t;return(t=e).dataTransfer.types&&t.dataTransfer.types.some(function(e){return"Files"==e})&&(e.stopPropagation(),e.preventDefault?e.preventDefault():e.returnValue=!1)}return this.listeners=[{element:this.element,events:{dragstart:function(e){return s.emit("dragstart",e)},dragenter:function(e){return a(e),s.emit("dragenter",e)},dragover:function(e){var t;try{t=e.dataTransfer.effectAllowed}catch(e){}return e.dataTransfer.dropEffect="move"===t||"linkMove"===t?"move":"copy",a(e),s.emit("dragover",e)},dragleave:function(e){return s.emit("dragleave",e)},drop:function(e){return a(e),s.drop(e)},dragend:function(e){return s.emit("dragend",e)}}}],this.clickableElements.forEach(function(t){return s.listeners.push({element:t,events:{click:function(e){return t===s.element&&e.target!==s.element&&!C.elementInside(e.target,s.element.querySelector(".dz-message"))||s.hiddenFileInput.click(),!0}}})}),this.enable(),this.options.init.call(this)}},{key:"destroy",value:function(){return this.disable(),this.removeAllFiles(!0),null!=this.hiddenFileInput&&this.hiddenFileInput.parentNode&&(this.hiddenFileInput.parentNode.removeChild(this.hiddenFileInput),this.hiddenFileInput=null),delete this.element.dropzone,C.instances.splice(C.instances.indexOf(this),1)}},{key:"updateTotalUploadProgress",value:function(){var e,t=0,n=0;if(this.getActiveFiles().length){var i=!0,r=!1,o=void 0;try{for(var a,l=this.getActiveFiles()[Symbol.iterator]();!(i=(a=l.next()).done);i=!0){var s=a.value;t+=s.upload.bytesSent,n+=s.upload.total}}catch(e){r=!0,o=e}finally{try{i||null==l.return||l.return()}finally{if(r)throw o}}e=100*t/n}else e=100;return this.emit("totaluploadprogress",e,n,t)}},{key:"_getParamName",value:function(e){return"function"==typeof this.options.paramName?this.options.paramName(e):"".concat(this.options.paramName).concat(this.options.uploadMultiple?"[".concat(e,"]"):"")}},{key:"_renameFile",value:function(e){return"function"!=typeof this.options.renameFile?e.name:this.options.renameFile(e)}},{key:"getFallbackForm",value:function(){var e,t;if(e=this.getExistingFallback())return e;var n='<div class="dz-fallback">';this.options.dictFallbackText&&(n+="<p>".concat(this.options.dictFallbackText,"</p>")),n+='<input type="file" name="'.concat(this._getParamName(0),'" ').concat(this.options.uploadMultiple?'multiple="multiple"':void 0,' /><input type="submit" value="Upload!"></div>');var i=C.createElement(n);return"FORM"!==this.element.tagName?(t=C.createElement('<form action="'.concat(this.options.url,'" enctype="multipart/form-data" method="').concat(this.options.method,'"></form>'))).appendChild(i):(this.element.setAttribute("enctype","multipart/form-data"),this.element.setAttribute("method",this.options.method)),null!=t?t:i}},{key:"getExistingFallback",value:function(){for(var e=function(e){var t=!0,n=!1,i=void 0;try{for(var r,o=e[Symbol.iterator]();!(t=(r=o.next()).done);t=!0){var a=r.value;if(/(^| )fallback($| )/.test(a.className))return a}}catch(e){n=!0,i=e}finally{try{t||null==o.return||o.return()}finally{if(n)throw i}}},t=0,n=["div","form"];t<n.length;t++){var i,r=n[t];if(i=e(this.element.getElementsByTagName(r)))return i}}},{key:"setupEventListeners",value:function(){return this.listeners.map(function(i){return function(){var e=[];for(var t in i.events){var n=i.events[t];e.push(i.element.addEventListener(t,n,!1))}return e}()})}},{key:"removeEventListeners",value:function(){return this.listeners.map(function(i){return function(){var e=[];for(var t in i.events){var n=i.events[t];e.push(i.element.removeEventListener(t,n,!1))}return e}()})}},{key:"disable",value:function(){var t=this;return this.clickableElements.forEach(function(e){return e.classList.remove("dz-clickable")}),this.removeEventListeners(),this.disabled=!0,this.files.map(function(e){return t.cancelUpload(e)})}},{key:"enable",value:function(){return delete this.disabled,this.clickableElements.forEach(function(e){return e.classList.add("dz-clickable")}),this.setupEventListeners()}},{key:"filesize",value:function(e){var t=0,n="b";if(0<e){for(var i=["tb","gb","mb","kb","b"],r=0;r<i.length;r++){var o=i[r];if(Math.pow(this.options.filesizeBase,4-r)/10<=e){t=e/Math.pow(this.options.filesizeBase,4-r),n=o;break}}t=Math.round(10*t)/10}return"<strong>".concat(t,"</strong> ").concat(this.options.dictFileSizeUnits[n])}},{key:"_updateMaxFilesReachedClass",value:function(){return null!=this.options.maxFiles&&this.getAcceptedFiles().length>=this.options.maxFiles?(this.getAcceptedFiles().length===this.options.maxFiles&&this.emit("maxfilesreached",this.files),this.element.classList.add("dz-max-files-reached")):this.element.classList.remove("dz-max-files-reached")}},{key:"drop",value:function(e){if(e.dataTransfer){this.emit("drop",e);for(var t=[],n=0;n<e.dataTransfer.files.length;n++)t[n]=e.dataTransfer.files[n];if(t.length){var i=e.dataTransfer.items;i&&i.length&&null!=i[0].webkitGetAsEntry?this._addFilesFromItems(i):this.handleFiles(t)}this.emit("addedfiles",t)}}},{key:"paste",value:function(e){if(null!=__guard__(null!=e?e.clipboardData:void 0,function(e){return e.items})){this.emit("paste",e);var t=e.clipboardData.items;return t.length?this._addFilesFromItems(t):void 0}}},{key:"handleFiles",value:function(e){var t=!0,n=!1,i=void 0;try{for(var r,o=e[Symbol.iterator]();!(t=(r=o.next()).done);t=!0){var a=r.value;this.addFile(a)}}catch(e){n=!0,i=e}finally{try{t||null==o.return||o.return()}finally{if(n)throw i}}}},{key:"_addFilesFromItems",value:function(s){var u=this;return function(){var e=[],t=!0,n=!1,i=void 0;try{for(var r,o=s[Symbol.iterator]();!(t=(r=o.next()).done);t=!0){var a,l=r.value;null!=l.webkitGetAsEntry&&(a=l.webkitGetAsEntry())?a.isFile?e.push(u.addFile(l.getAsFile())):a.isDirectory?e.push(u._addFilesFromDirectory(a,a.name)):e.push(void 0):null!=l.getAsFile&&(null==l.kind||"file"===l.kind)?e.push(u.addFile(l.getAsFile())):e.push(void 0)}}catch(e){n=!0,i=e}finally{try{t||null==o.return||o.return()}finally{if(n)throw i}}return e}()}},{key:"_addFilesFromDirectory",value:function(e,s){function t(t){return __guardMethod__(console,"log",function(e){return e.log(t)})}var u=this,n=e.createReader();return function l(){return n.readEntries(function(e){if(0<e.length){var t=!0,n=!1,i=void 0;try{for(var r,o=e[Symbol.iterator]();!(t=(r=o.next()).done);t=!0){var a=r.value;a.isFile?a.file(function(e){if(!u.options.ignoreHiddenFiles||"."!==e.name.substring(0,1))return e.fullPath="".concat(s,"/").concat(e.name),u.addFile(e)}):a.isDirectory&&u._addFilesFromDirectory(a,"".concat(s,"/").concat(a.name))}}catch(e){n=!0,i=e}finally{try{t||null==o.return||o.return()}finally{if(n)throw i}}l()}return null},t)}()}},{key:"accept",value:function(e,t){this.options.maxFilesize&&e.size>1024*this.options.maxFilesize*1024?t(this.options.dictFileTooBig.replace("{{filesize}}",Math.round(e.size/1024/10.24)/100).replace("{{maxFilesize}}",this.options.maxFilesize)):C.isValidFile(e,this.options.acceptedFiles)?null!=this.options.maxFiles&&this.getAcceptedFiles().length>=this.options.maxFiles?(t(this.options.dictMaxFilesExceeded.replace("{{maxFiles}}",this.options.maxFiles)),this.emit("maxfilesexceeded",e)):this.options.accept.call(this,e,t):t(this.options.dictInvalidFileType)}},{key:"addFile",value:function(t){var n=this;t.upload={uuid:C.uuidv4(),progress:0,total:t.size,bytesSent:0,filename:this._renameFile(t)},this.files.push(t),t.status=C.ADDED,this.emit("addedfile",t),this._enqueueThumbnail(t),this.accept(t,function(e){e?(t.accepted=!1,n._errorProcessing([t],e)):(t.accepted=!0,n.options.autoQueue&&n.enqueueFile(t)),n._updateMaxFilesReachedClass()})}},{key:"enqueueFiles",value:function(e){var t=!0,n=!1,i=void 0;try{for(var r,o=e[Symbol.iterator]();!(t=(r=o.next()).done);t=!0){var a=r.value;this.enqueueFile(a)}}catch(e){n=!0,i=e}finally{try{t||null==o.return||o.return()}finally{if(n)throw i}}return null}},{key:"enqueueFile",value:function(e){var t=this;if(e.status!==C.ADDED||!0!==e.accepted)throw new Error("This file can't be queued because it has already been processed or was rejected.");if(e.status=C.QUEUED,this.options.autoProcessQueue)return setTimeout(function(){return t.processQueue()},0)}},{key:"_enqueueThumbnail",value:function(e){var t=this;if(this.options.createImageThumbnails&&e.type.match(/image.*/)&&e.size<=1024*this.options.maxThumbnailFilesize*1024)return this._thumbnailQueue.push(e),setTimeout(function(){return t._processThumbnailQueue()},0)}},{key:"_processThumbnailQueue",value:function(){var t=this;if(!this._processingThumbnail&&0!==this._thumbnailQueue.length){this._processingThumbnail=!0;var n=this._thumbnailQueue.shift();return this.createThumbnail(n,this.options.thumbnailWidth,this.options.thumbnailHeight,this.options.thumbnailMethod,!0,function(e){return t.emit("thumbnail",n,e),t._processingThumbnail=!1,t._processThumbnailQueue()})}}},{key:"removeFile",value:function(e){if(e.status===C.UPLOADING&&this.cancelUpload(e),this.files=without(this.files,e),this.emit("removedfile",e),0===this.files.length)return this.emit("reset")}},{key:"removeAllFiles",value:function(e){null==e&&(e=!1);var t=!0,n=!1,i=void 0;try{for(var r,o=this.files.slice()[Symbol.iterator]();!(t=(r=o.next()).done);t=!0){var a=r.value;a.status===C.UPLOADING&&!e||this.removeFile(a)}}catch(e){n=!0,i=e}finally{try{t||null==o.return||o.return()}finally{if(n)throw i}}return null}},{key:"resizeImage",value:function(r,e,t,n,o){var a=this;return this.createThumbnail(r,e,t,n,!0,function(e,t){if(null==t)return o(r);var n=a.options.resizeMimeType;null==n&&(n=r.type);var i=t.toDataURL(n,a.options.resizeQuality);return"image/jpeg"!==n&&"image/jpg"!==n||(i=ExifRestore.restore(r.dataURL,i)),o(C.dataURItoBlob(i))})}},{key:"createThumbnail",value:function(e,t,n,i,r,o){var a=this,l=new FileReader;l.onload=function(){e.dataURL=l.result,"image/svg+xml"!==e.type?a.createThumbnailFromUrl(e,t,n,i,r,o):null!=o&&o(l.result)},l.readAsDataURL(e)}},{key:"displayExistingFile",value:function(t,e,n,i,r){var o=this,a=!(4<arguments.length&&void 0!==r)||r;if(this.emit("addedfile",t),this.emit("complete",t),a){t.dataURL=e,this.createThumbnailFromUrl(t,this.options.thumbnailWidth,this.options.thumbnailHeight,this.options.resizeMethod,this.options.fixOrientation,function(e){o.emit("thumbnail",t,e),n&&n()},i)}else this.emit("thumbnail",t,e),n&&n()}},{key:"createThumbnailFromUrl",value:function(o,a,l,s,t,u,e){var c=this,d=document.createElement("img");return e&&(d.crossOrigin=e),d.onload=function(){var e=function(e){return e(1)};return"undefined"!=typeof EXIF&&null!==EXIF&&t&&(e=function(e){return EXIF.getData(d,function(){return e(EXIF.getTag(this,"Orientation"))})}),e(function(e){o.width=d.width,o.height=d.height;var t=c.options.resize.call(c,o,a,l,s),n=document.createElement("canvas"),i=n.getContext("2d");switch(n.width=t.trgWidth,n.height=t.trgHeight,4<e&&(n.width=t.trgHeight,n.height=t.trgWidth),e){case 2:i.translate(n.width,0),i.scale(-1,1);break;case 3:i.translate(n.width,n.height),i.rotate(Math.PI);break;case 4:i.translate(0,n.height),i.scale(1,-1);break;case 5:i.rotate(.5*Math.PI),i.scale(1,-1);break;case 6:i.rotate(.5*Math.PI),i.translate(0,-n.width);break;case 7:i.rotate(.5*Math.PI),i.translate(n.height,-n.width),i.scale(-1,1);break;case 8:i.rotate(-.5*Math.PI),i.translate(-n.height,0)}drawImageIOSFix(i,d,null!=t.srcX?t.srcX:0,null!=t.srcY?t.srcY:0,t.srcWidth,t.srcHeight,null!=t.trgX?t.trgX:0,null!=t.trgY?t.trgY:0,t.trgWidth,t.trgHeight);var r=n.toDataURL("image/png");if(null!=u)return u(r,n)})},null!=u&&(d.onerror=u),d.src=o.dataURL}},{key:"processQueue",value:function(){var e=this.options.parallelUploads,t=this.getUploadingFiles().length,n=t;if(!(e<=t)){var i=this.getQueuedFiles();if(0<i.length){if(this.options.uploadMultiple)return this.processFiles(i.slice(0,e-t));for(;n<e;){if(!i.length)return;this.processFile(i.shift()),n++}}}}},{key:"processFile",value:function(e){return this.processFiles([e])}},{key:"processFiles",value:function(e){var t=!0,n=!1,i=void 0;try{for(var r,o=e[Symbol.iterator]();!(t=(r=o.next()).done);t=!0){var a=r.value;a.processing=!0,a.status=C.UPLOADING,this.emit("processing",a)}}catch(e){n=!0,i=e}finally{try{t||null==o.return||o.return()}finally{if(n)throw i}}return this.options.uploadMultiple&&this.emit("processingmultiple",e),this.uploadFiles(e)}},{key:"_getFilesWithXhr",value:function(t){return this.files.filter(function(e){return e.xhr===t}).map(function(e){return e})}},{key:"cancelUpload",value:function(e){if(e.status===C.UPLOADING){var t=this._getFilesWithXhr(e.xhr),n=!0,i=!1,r=void 0;try{for(var o,a=t[Symbol.iterator]();!(n=(o=a.next()).done);n=!0){o.value.status=C.CANCELED}}catch(e){i=!0,r=e}finally{try{n||null==a.return||a.return()}finally{if(i)throw r}}void 0!==e.xhr&&e.xhr.abort();var l=!0,s=!1,u=void 0;try{for(var c,d=t[Symbol.iterator]();!(l=(c=d.next()).done);l=!0){var p=c.value;this.emit("canceled",p)}}catch(e){s=!0,u=e}finally{try{l||null==d.return||d.return()}finally{if(s)throw u}}this.options.uploadMultiple&&this.emit("canceledmultiple",t)}else e.status!==C.ADDED&&e.status!==C.QUEUED||(e.status=C.CANCELED,this.emit("canceled",e),this.options.uploadMultiple&&this.emit("canceledmultiple",[e]));if(this.options.autoProcessQueue)return this.processQueue()}},{key:"resolveOption",value:function(e){if("function"!=typeof e)return e;for(var t=arguments.length,n=new Array(1<t?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];return e.apply(this,n)}},{key:"uploadFile",value:function(e){return this.uploadFiles([e])}},{key:"uploadFiles",value:function(s){var u=this;this._transformFiles(s,function(e){if(u.options.chunking){var t=e[0];s[0].upload.chunked=u.options.chunking&&(u.options.forceChunking||t.size>u.options.chunkSize),s[0].upload.totalChunkCount=Math.ceil(t.size/u.options.chunkSize)}if(s[0].upload.chunked){var r=s[0],o=e[0];r.upload.chunks=[];var i=function(){for(var e=0;void 0!==r.upload.chunks[e];)e++;if(!(e>=r.upload.totalChunkCount)){0;var t=e*u.options.chunkSize,n=Math.min(t+u.options.chunkSize,r.size),i={name:u._getParamName(0),data:o.webkitSlice?o.webkitSlice(t,n):o.slice(t,n),filename:r.upload.filename,chunkIndex:e};r.upload.chunks[e]={file:r,index:e,dataBlock:i,status:C.UPLOADING,progress:0,retries:0},u._uploadData(s,[i])}};if(r.upload.finishedChunkUpload=function(e){var t=!0;e.status=C.SUCCESS,e.dataBlock=null,e.xhr=null;for(var n=0;n<r.upload.totalChunkCount;n++){if(void 0===r.upload.chunks[n])return i();r.upload.chunks[n].status!==C.SUCCESS&&(t=!1)}t&&u.options.chunksUploaded(r,function(){u._finished(s,"",null)})},u.options.parallelChunkUploads)for(var n=0;n<r.upload.totalChunkCount;n++)i();else i()}else{for(var a=[],l=0;l<s.length;l++)a[l]={name:u._getParamName(l),data:e[l],filename:s[l].upload.filename};u._uploadData(s,a)}})}},{key:"_getChunk",value:function(e,t){for(var n=0;n<e.upload.totalChunkCount;n++)if(void 0!==e.upload.chunks[n]&&e.upload.chunks[n].xhr===t)return e.upload.chunks[n]}},{key:"_uploadData",value:function(t,e){var n=this,i=new XMLHttpRequest,r=!0,o=!1,a=void 0;try{for(var l,s=t[Symbol.iterator]();!(r=(l=s.next()).done);r=!0){l.value.xhr=i}}catch(e){o=!0,a=e}finally{try{r||null==s.return||s.return()}finally{if(o)throw a}}t[0].upload.chunked&&(t[0].upload.chunks[e[0].chunkIndex].xhr=i);var u=this.resolveOption(this.options.method,t),c=this.resolveOption(this.options.url,t);i.open(u,c,!0),i.timeout=this.resolveOption(this.options.timeout,t),i.withCredentials=!!this.options.withCredentials,i.onload=function(e){n._finishedUploading(t,i,e)},i.ontimeout=function(){n._handleUploadError(t,i,"Request timedout after ".concat(n.options.timeout," seconds"))},i.onerror=function(){n._handleUploadError(t,i)},(null!=i.upload?i.upload:i).onprogress=function(e){return n._updateFilesUploadProgress(t,i,e)};var d={Accept:"application/json","Cache-Control":"no-cache","X-Requested-With":"XMLHttpRequest"};for(var p in this.options.headers&&C.extend(d,this.options.headers),d){var h=d[p];h&&i.setRequestHeader(p,h)}var f=new FormData;if(this.options.params){var v=this.options.params;for(var m in"function"==typeof v&&(v=v.call(this,t,i,t[0].upload.chunked?this._getChunk(t[0],i):null)),v){var y=v[m];f.append(m,y)}}var g=!0,b=!1,k=void 0;try{for(var w,F=t[Symbol.iterator]();!(g=(w=F.next()).done);g=!0){var z=w.value;this.emit("sending",z,i,f)}}catch(e){b=!0,k=e}finally{try{g||null==F.return||F.return()}finally{if(b)throw k}}this.options.uploadMultiple&&this.emit("sendingmultiple",t,i,f),this._addFormElementData(f);for(var x=0;x<e.length;x++){var E=e[x];f.append(E.name,E.data,E.filename)}this.submitRequest(i,f,t)}},{key:"_transformFiles",value:function(n,i){for(var e=this,r=[],o=0,t=function(t){e.options.transformFile.call(e,n[t],function(e){r[t]=e,++o===n.length&&i(r)})},a=0;a<n.length;a++)t(a)}},{key:"_addFormElementData",value:function(e){if("FORM"===this.element.tagName){var t=!0,n=!1,i=void 0;try{for(var r,o=this.element.querySelectorAll("input, textarea, select, button")[Symbol.iterator]();!(t=(r=o.next()).done);t=!0){var a=r.value,l=a.getAttribute("name"),s=a.getAttribute("type");if(s=s&&s.toLowerCase(),null!=l)if("SELECT"===a.tagName&&a.hasAttribute("multiple")){var u=!0,c=!1,d=void 0;try{for(var p,h=a.options[Symbol.iterator]();!(u=(p=h.next()).done);u=!0){var f=p.value;f.selected&&e.append(l,f.value)}}catch(e){c=!0,d=e}finally{try{u||null==h.return||h.return()}finally{if(c)throw d}}}else(!s||"checkbox"!==s&&"radio"!==s||a.checked)&&e.append(l,a.value)}}catch(e){n=!0,i=e}finally{try{t||null==o.return||o.return()}finally{if(n)throw i}}}}},{key:"_updateFilesUploadProgress",value:function(e,t,n){var i;if(void 0!==n){if(i=100*n.loaded/n.total,e[0].upload.chunked){var r=e[0],o=this._getChunk(r,t);o.progress=i,o.total=n.total,o.bytesSent=n.loaded;r.upload.progress=0,r.upload.total=0;for(var a=r.upload.bytesSent=0;a<r.upload.totalChunkCount;a++)void 0!==r.upload.chunks[a]&&void 0!==r.upload.chunks[a].progress&&(r.upload.progress+=r.upload.chunks[a].progress,r.upload.total+=r.upload.chunks[a].total,r.upload.bytesSent+=r.upload.chunks[a].bytesSent);r.upload.progress=r.upload.progress/r.upload.totalChunkCount}else{var l=!0,s=!1,u=void 0;try{for(var c,d=e[Symbol.iterator]();!(l=(c=d.next()).done);l=!0){var p=c.value;p.upload.progress=i,p.upload.total=n.total,p.upload.bytesSent=n.loaded}}catch(e){s=!0,u=e}finally{try{l||null==d.return||d.return()}finally{if(s)throw u}}}var h=!0,f=!1,v=void 0;try{for(var m,y=e[Symbol.iterator]();!(h=(m=y.next()).done);h=!0){var g=m.value;this.emit("uploadprogress",g,g.upload.progress,g.upload.bytesSent)}}catch(e){f=!0,v=e}finally{try{h||null==y.return||y.return()}finally{if(f)throw v}}}else{var b=!0,k=!0,w=!(i=100),F=void 0;try{for(var z,x=e[Symbol.iterator]();!(k=(z=x.next()).done);k=!0){var E=z.value;100===E.upload.progress&&E.upload.bytesSent===E.upload.total||(b=!1),E.upload.progress=i,E.upload.bytesSent=E.upload.total}}catch(e){w=!0,F=e}finally{try{k||null==x.return||x.return()}finally{if(w)throw F}}if(b)return;var C=!0,_=!1,S=void 0;try{for(var D,T=e[Symbol.iterator]();!(C=(D=T.next()).done);C=!0){var L=D.value;this.emit("uploadprogress",L,i,L.upload.bytesSent)}}catch(e){_=!0,S=e}finally{try{C||null==T.return||T.return()}finally{if(_)throw S}}}}},{key:"_finishedUploading",value:function(e,t,n){var i;if(e[0].status!==C.CANCELED&&4===t.readyState){if("arraybuffer"!==t.responseType&&"blob"!==t.responseType&&(i=t.responseText,t.getResponseHeader("content-type")&&~t.getResponseHeader("content-type").indexOf("application/json")))try{i=JSON.parse(i)}catch(e){n=e,i="Invalid JSON response from server."}this._updateFilesUploadProgress(e),200<=t.status&&t.status<300?e[0].upload.chunked?e[0].upload.finishedChunkUpload(this._getChunk(e[0],t)):this._finished(e,i,n):this._handleUploadError(e,t,i)}}},{key:"_handleUploadError",value:function(e,t,n){if(e[0].status!==C.CANCELED){if(e[0].upload.chunked&&this.options.retryChunks){var i=this._getChunk(e[0],t);if(i.retries++<this.options.retryChunksLimit)return void this._uploadData(e,[i.dataBlock]);console.warn("Retried this chunk too often. Giving up.")}this._errorProcessing(e,n||this.options.dictResponseError.replace("{{statusCode}}",t.status),t)}}},{key:"submitRequest",value:function(e,t){e.send(t)}},{key:"_finished",value:function(e,t,n){var i=!0,r=!1,o=void 0;try{for(var a,l=e[Symbol.iterator]();!(i=(a=l.next()).done);i=!0){var s=a.value;s.status=C.SUCCESS,this.emit("success",s,t,n),this.emit("complete",s)}}catch(e){r=!0,o=e}finally{try{i||null==l.return||l.return()}finally{if(r)throw o}}if(this.options.uploadMultiple&&(this.emit("successmultiple",e,t,n),this.emit("completemultiple",e)),this.options.autoProcessQueue)return this.processQueue()}},{key:"_errorProcessing",value:function(e,t,n){var i=!0,r=!1,o=void 0;try{for(var a,l=e[Symbol.iterator]();!(i=(a=l.next()).done);i=!0){var s=a.value;s.status=C.ERROR,this.emit("error",s,t,n),this.emit("complete",s)}}catch(e){r=!0,o=e}finally{try{i||null==l.return||l.return()}finally{if(r)throw o}}if(this.options.uploadMultiple&&(this.emit("errormultiple",e,t,n),this.emit("completemultiple",e)),this.options.autoProcessQueue)return this.processQueue()}}],[{key:"uuidv4",value:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}}]),C}();Dropzone.initClass(),Dropzone.version="5.7.0",Dropzone.options={},Dropzone.optionsForElement=function(e){return e.getAttribute("id")?Dropzone.options[camelize(e.getAttribute("id"))]:void 0},Dropzone.instances=[],Dropzone.forElement=function(e){if("string"==typeof e&&(e=document.querySelector(e)),null==(null!=e?e.dropzone:void 0))throw new Error("No Dropzone found for given element. This is probably because you're trying to access it before Dropzone had the time to initialize. Use the `init` option to setup any additional observers on your Dropzone.");return e.dropzone},Dropzone.autoDiscover=!0,Dropzone.discover=function(){var s;if(document.querySelectorAll)s=document.querySelectorAll(".dropzone");else{s=[];var e=function(l){return function(){var e=[],t=!0,n=!1,i=void 0;try{for(var r,o=l[Symbol.iterator]();!(t=(r=o.next()).done);t=!0){var a=r.value;/(^| )dropzone($| )/.test(a.className)?e.push(s.push(a)):e.push(void 0)}}catch(e){n=!0,i=e}finally{try{t||null==o.return||o.return()}finally{if(n)throw i}}return e}()};e(document.getElementsByTagName("div")),e(document.getElementsByTagName("form"))}return function(){var e=[],t=!0,n=!1,i=void 0;try{for(var r,o=s[Symbol.iterator]();!(t=(r=o.next()).done);t=!0){var a=r.value;!1!==Dropzone.optionsForElement(a)?e.push(new Dropzone(a)):e.push(void 0)}}catch(e){n=!0,i=e}finally{try{t||null==o.return||o.return()}finally{if(n)throw i}}return e}()},Dropzone.blacklistedBrowsers=[/opera.*(Macintosh|Windows Phone).*version\/12/i],Dropzone.isBrowserSupported=function(){var e=!0;if(window.File&&window.FileReader&&window.FileList&&window.Blob&&window.FormData&&document.querySelector)if("classList"in document.createElement("a")){var t=!0,n=!1,i=void 0;try{for(var r,o=Dropzone.blacklistedBrowsers[Symbol.iterator]();!(t=(r=o.next()).done);t=!0){r.value.test(navigator.userAgent)&&(e=!1)}}catch(e){n=!0,i=e}finally{try{t||null==o.return||o.return()}finally{if(n)throw i}}}else e=!1;else e=!1;return e},Dropzone.dataURItoBlob=function(e){for(var t=atob(e.split(",")[1]),n=e.split(",")[0].split(":")[1].split(";")[0],i=new ArrayBuffer(t.length),r=new Uint8Array(i),o=0,a=t.length,l=0<=a;l?o<=a:a<=o;l?o++:o--)r[o]=t.charCodeAt(o);return new Blob([i],{type:n})};var without=function(e,t){return e.filter(function(e){return e!==t}).map(function(e){return e})},camelize=function(e){return e.replace(/[\-_](\w)/g,function(e){return e.charAt(1).toUpperCase()})};Dropzone.createElement=function(e){var t=document.createElement("div");return t.innerHTML=e,t.childNodes[0]},Dropzone.elementInside=function(e,t){if(e===t)return!0;for(;e=e.parentNode;)if(e===t)return!0;return!1},Dropzone.getElement=function(e,t){var n;if("string"==typeof e?n=document.querySelector(e):null!=e.nodeType&&(n=e),null==n)throw new Error("Invalid `".concat(t,"` option provided. Please provide a CSS selector or a plain HTML element."));return n},Dropzone.getElements=function(e,t){var n,i;if(e instanceof Array){i=[];try{var r=!0,o=!1,a=void 0;try{for(var l,s=e[Symbol.iterator]();!(r=(l=s.next()).done);r=!0)n=l.value,i.push(this.getElement(n,t))}catch(e){o=!0,a=e}finally{try{r||null==s.return||s.return()}finally{if(o)throw a}}}catch(e){i=null}}else if("string"==typeof e){var u=!0,c=!(i=[]),d=void 0;try{for(var p,h=document.querySelectorAll(e)[Symbol.iterator]();!(u=(p=h.next()).done);u=!0)n=p.value,i.push(n)}catch(e){c=!0,d=e}finally{try{u||null==h.return||h.return()}finally{if(c)throw d}}}else null!=e.nodeType&&(i=[e]);if(null==i||!i.length)throw new Error("Invalid `".concat(t,"` option provided. Please provide a CSS selector, a plain HTML element or a list of those."));return i},Dropzone.confirm=function(e,t,n){return window.confirm(e)?t():null!=n?n():void 0},Dropzone.isValidFile=function(e,t){if(!t)return!0;t=t.split(",");var n=e.type,i=n.replace(/\/.*$/,""),r=!0,o=!1,a=void 0;try{for(var l,s=t[Symbol.iterator]();!(r=(l=s.next()).done);r=!0){var u=l.value;if("."===(u=u.trim()).charAt(0)){if(-1!==e.name.toLowerCase().indexOf(u.toLowerCase(),e.name.length-u.length))return!0}else if(/\/\*$/.test(u)){if(i===u.replace(/\/.*$/,""))return!0}else if(n===u)return!0}}catch(e){o=!0,a=e}finally{try{r||null==s.return||s.return()}finally{if(o)throw a}}return!1},"undefined"!=typeof jQuery&&null!==jQuery&&(jQuery.fn.dropzone=function(e){return this.each(function(){return new Dropzone(this,e)})}),"undefined"!=typeof module&&null!==module?module.exports=Dropzone:window.Dropzone=Dropzone,Dropzone.ADDED="added",Dropzone.QUEUED="queued",Dropzone.ACCEPTED=Dropzone.QUEUED,Dropzone.UPLOADING="uploading",Dropzone.PROCESSING=Dropzone.UPLOADING,Dropzone.CANCELED="canceled",Dropzone.ERROR="error",Dropzone.SUCCESS="success";var detectVerticalSquash=function(e){e.naturalWidth;var t=e.naturalHeight,n=document.createElement("canvas");n.width=1,n.height=t;var i=n.getContext("2d");i.drawImage(e,0,0);for(var r=i.getImageData(1,0,1,t).data,o=0,a=t,l=t;o<l;){0===r[4*(l-1)+3]?a=l:o=l,l=a+o>>1}var s=l/t;return 0==s?1:s},drawImageIOSFix=function(e,t,n,i,r,o,a,l,s,u){var c=detectVerticalSquash(t);return e.drawImage(t,n,i,r,o,a,l,s,u/c)},ExifRestore=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"initClass",value:function(){this.KEY_STR="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}},{key:"encode64",value:function(e){for(var t="",n=void 0,i=void 0,r="",o=void 0,a=void 0,l=void 0,s="",u=0;o=(n=e[u++])>>2,a=(3&n)<<4|(i=e[u++])>>4,l=(15&i)<<2|(r=e[u++])>>6,s=63&r,isNaN(i)?l=s=64:isNaN(r)&&(s=64),t=t+this.KEY_STR.charAt(o)+this.KEY_STR.charAt(a)+this.KEY_STR.charAt(l)+this.KEY_STR.charAt(s),n=i=r="",o=a=l=s="",u<e.length;);return t}},{key:"restore",value:function(e,t){if(!e.match("data:image/jpeg;base64,"))return t;var n=this.decode64(e.replace("data:image/jpeg;base64,","")),i=this.slice2Segments(n),r=this.exifManipulation(t,i);return"data:image/jpeg;base64,".concat(this.encode64(r))}},{key:"exifManipulation",value:function(e,t){var n=this.getExifArray(t),i=this.insertExif(e,n);return new Uint8Array(i)}},{key:"getExifArray",value:function(e){for(var t=void 0,n=0;n<e.length;){if(255===(t=e[n])[0]&225===t[1])return t;n++}return[]}},{key:"insertExif",value:function(e,t){var n=e.replace("data:image/jpeg;base64,",""),i=this.decode64(n),r=i.indexOf(255,3),o=i.slice(0,r),a=i.slice(r),l=o;return l=(l=l.concat(t)).concat(a)}},{key:"slice2Segments",value:function(e){for(var t=0,n=[];;){if(255===e[t]&218===e[t+1])break;if(255===e[t]&216===e[t+1])t+=2;else{var i=t+(256*e[t+2]+e[t+3])+2,r=e.slice(t,i);n.push(r),t=i}if(t>e.length)break}return n}},{key:"decode64",value:function(e){var t=void 0,n=void 0,i="",r=void 0,o=void 0,a="",l=0,s=[];for(/[^A-Za-z0-9\+\/\=]/g.exec(e)&&console.warn("There were invalid base64 characters in the input text.\nValid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\nExpect errors in decoding."),e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");t=this.KEY_STR.indexOf(e.charAt(l++))<<2|(r=this.KEY_STR.indexOf(e.charAt(l++)))>>4,n=(15&r)<<4|(o=this.KEY_STR.indexOf(e.charAt(l++)))>>2,i=(3&o)<<6|(a=this.KEY_STR.indexOf(e.charAt(l++))),s.push(t),64!==o&&s.push(n),64!==a&&s.push(i),t=n=i="",r=o=a="",l<e.length;);return s}}]),e}();ExifRestore.initClass();var contentLoaded=function(t,n){function i(e){if("readystatechange"!==e.type||"complete"===o.readyState)return("load"===e.type?t:o)[s](u+e.type,i,!1),!r&&(r=!0)?n.call(t,e.type||e):void 0}var r=!1,e=!0,o=t.document,a=o.documentElement,l=o.addEventListener?"addEventListener":"attachEvent",s=o.addEventListener?"removeEventListener":"detachEvent",u=o.addEventListener?"":"on";if("complete"!==o.readyState){if(o.createEventObject&&a.doScroll){try{e=!t.frameElement}catch(e){}e&&!function t(){try{a.doScroll("left")}catch(e){return void setTimeout(t,50)}return i("poll")}()}return o[l](u+"DOMContentLoaded",i,!1),o[l](u+"readystatechange",i,!1),t[l](u+"load",i,!1)}};function __guard__(e,t){return null!=e?t(e):void 0}function __guardMethod__(e,t,n){return null!=e&&"function"==typeof e[t]?n(e,t):void 0}Dropzone._autoDiscoverFunction=function(){if(Dropzone.autoDiscover)return Dropzone.discover()},contentLoaded(window,Dropzone._autoDiscoverFunction);
|
admin/js/select2.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
/*! Select2 4.0.6-rc.0 | https://github.com/select2/select2/blob/master/LICENSE.md */!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof module&&module.exports?module.exports=function(b,c){return void 0===c&&(c="undefined"!=typeof window?require("jquery"):require("jquery")(b)),a(c),c}:a(jQuery)}(function(a){var b=function(){if(a&&a.fn&&a.fn.select2&&a.fn.select2.amd)var b=a.fn.select2.amd;var b;return function(){if(!b||!b.requirejs){b?c=b:b={};var a,c,d;!function(b){function e(a,b){return v.call(a,b)}function f(a,b){var c,d,e,f,g,h,i,j,k,l,m,n,o=b&&b.split("/"),p=t.map,q=p&&p["*"]||{};if(a){for(a=a.split("/"),g=a.length-1,t.nodeIdCompat&&x.test(a[g])&&(a[g]=a[g].replace(x,"")),"."===a[0].charAt(0)&&o&&(n=o.slice(0,o.length-1),a=n.concat(a)),k=0;k<a.length;k++)if("."===(m=a[k]))a.splice(k,1),k-=1;else if(".."===m){if(0===k||1===k&&".."===a[2]||".."===a[k-1])continue;k>0&&(a.splice(k-1,2),k-=2)}a=a.join("/")}if((o||q)&&p){for(c=a.split("/"),k=c.length;k>0;k-=1){if(d=c.slice(0,k).join("/"),o)for(l=o.length;l>0;l-=1)if((e=p[o.slice(0,l).join("/")])&&(e=e[d])){f=e,h=k;break}if(f)break;!i&&q&&q[d]&&(i=q[d],j=k)}!f&&i&&(f=i,h=j),f&&(c.splice(0,h,f),a=c.join("/"))}return a}function g(a,c){return function(){var d=w.call(arguments,0);return"string"!=typeof d[0]&&1===d.length&&d.push(null),o.apply(b,d.concat([a,c]))}}function h(a){return function(b){return f(b,a)}}function i(a){return function(b){r[a]=b}}function j(a){if(e(s,a)){var c=s[a];delete s[a],u[a]=!0,n.apply(b,c)}if(!e(r,a)&&!e(u,a))throw new Error("No "+a);return r[a]}function k(a){var b,c=a?a.indexOf("!"):-1;return c>-1&&(b=a.substring(0,c),a=a.substring(c+1,a.length)),[b,a]}function l(a){return a?k(a):[]}function m(a){return function(){return t&&t.config&&t.config[a]||{}}}var n,o,p,q,r={},s={},t={},u={},v=Object.prototype.hasOwnProperty,w=[].slice,x=/\.js$/;p=function(a,b){var c,d=k(a),e=d[0],g=b[1];return a=d[1],e&&(e=f(e,g),c=j(e)),e?a=c&&c.normalize?c.normalize(a,h(g)):f(a,g):(a=f(a,g),d=k(a),e=d[0],a=d[1],e&&(c=j(e))),{f:e?e+"!"+a:a,n:a,pr:e,p:c}},q={require:function(a){return g(a)},exports:function(a){var b=r[a];return void 0!==b?b:r[a]={}},module:function(a){return{id:a,uri:"",exports:r[a],config:m(a)}}},n=function(a,c,d,f){var h,k,m,n,o,t,v,w=[],x=typeof d;if(f=f||a,t=l(f),"undefined"===x||"function"===x){for(c=!c.length&&d.length?["require","exports","module"]:c,o=0;o<c.length;o+=1)if(n=p(c[o],t),"require"===(k=n.f))w[o]=q.require(a);else if("exports"===k)w[o]=q.exports(a),v=!0;else if("module"===k)h=w[o]=q.module(a);else if(e(r,k)||e(s,k)||e(u,k))w[o]=j(k);else{if(!n.p)throw new Error(a+" missing "+k);n.p.load(n.n,g(f,!0),i(k),{}),w[o]=r[k]}m=d?d.apply(r[a],w):void 0,a&&(h&&h.exports!==b&&h.exports!==r[a]?r[a]=h.exports:m===b&&v||(r[a]=m))}else a&&(r[a]=d)},a=c=o=function(a,c,d,e,f){if("string"==typeof a)return q[a]?q[a](c):j(p(a,l(c)).f);if(!a.splice){if(t=a,t.deps&&o(t.deps,t.callback),!c)return;c.splice?(a=c,c=d,d=null):a=b}return c=c||function(){},"function"==typeof d&&(d=e,e=f),e?n(b,a,c,d):setTimeout(function(){n(b,a,c,d)},4),o},o.config=function(a){return o(a)},a._defined=r,d=function(a,b,c){if("string"!=typeof a)throw new Error("See almond README: incorrect module build, no module name");b.splice||(c=b,b=[]),e(r,a)||e(s,a)||(s[a]=[a,b,c])},d.amd={jQuery:!0}}(),b.requirejs=a,b.require=c,b.define=d}}(),b.define("almond",function(){}),b.define("jquery",[],function(){var b=a||$;return null==b&&console&&console.error&&console.error("Select2: An instance of jQuery or a jQuery-compatible library was not found. Make sure that you are including jQuery before Select2 on your web page."),b}),b.define("select2/utils",["jquery"],function(a){function b(a){var b=a.prototype,c=[];for(var d in b){"function"==typeof b[d]&&("constructor"!==d&&c.push(d))}return c}var c={};c.Extend=function(a,b){function c(){this.constructor=a}var d={}.hasOwnProperty;for(var e in b)d.call(b,e)&&(a[e]=b[e]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a},c.Decorate=function(a,c){function d(){var b=Array.prototype.unshift,d=c.prototype.constructor.length,e=a.prototype.constructor;d>0&&(b.call(arguments,a.prototype.constructor),e=c.prototype.constructor),e.apply(this,arguments)}function e(){this.constructor=d}var f=b(c),g=b(a);c.displayName=a.displayName,d.prototype=new e;for(var h=0;h<g.length;h++){var i=g[h];d.prototype[i]=a.prototype[i]}for(var j=(function(a){var b=function(){};a in d.prototype&&(b=d.prototype[a]);var e=c.prototype[a];return function(){return Array.prototype.unshift.call(arguments,b),e.apply(this,arguments)}}),k=0;k<f.length;k++){var l=f[k];d.prototype[l]=j(l)}return d};var d=function(){this.listeners={}};d.prototype.on=function(a,b){this.listeners=this.listeners||{},a in this.listeners?this.listeners[a].push(b):this.listeners[a]=[b]},d.prototype.trigger=function(a){var b=Array.prototype.slice,c=b.call(arguments,1);this.listeners=this.listeners||{},null==c&&(c=[]),0===c.length&&c.push({}),c[0]._type=a,a in this.listeners&&this.invoke(this.listeners[a],b.call(arguments,1)),"*"in this.listeners&&this.invoke(this.listeners["*"],arguments)},d.prototype.invoke=function(a,b){for(var c=0,d=a.length;c<d;c++)a[c].apply(this,b)},c.Observable=d,c.generateChars=function(a){for(var b="",c=0;c<a;c++){b+=Math.floor(36*Math.random()).toString(36)}return b},c.bind=function(a,b){return function(){a.apply(b,arguments)}},c._convertData=function(a){for(var b in a){var c=b.split("-"),d=a;if(1!==c.length){for(var e=0;e<c.length;e++){var f=c[e];f=f.substring(0,1).toLowerCase()+f.substring(1),f in d||(d[f]={}),e==c.length-1&&(d[f]=a[b]),d=d[f]}delete a[b]}}return a},c.hasScroll=function(b,c){var d=a(c),e=c.style.overflowX,f=c.style.overflowY;return(e!==f||"hidden"!==f&&"visible"!==f)&&("scroll"===e||"scroll"===f||(d.innerHeight()<c.scrollHeight||d.innerWidth()<c.scrollWidth))},c.escapeMarkup=function(a){var b={"\\":"\","&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};return"string"!=typeof a?a:String(a).replace(/[&<>"'\/\\]/g,function(a){return b[a]})},c.appendMany=function(b,c){if("1.7"===a.fn.jquery.substr(0,3)){var d=a();a.map(c,function(a){d=d.add(a)}),c=d}b.append(c)},c.__cache={};var e=0;return c.GetUniqueElementId=function(a){var b=a.getAttribute("data-select2-id");return null==b&&(a.id?(b=a.id,a.setAttribute("data-select2-id",b)):(a.setAttribute("data-select2-id",++e),b=e.toString())),b},c.StoreData=function(a,b,d){var e=c.GetUniqueElementId(a);c.__cache[e]||(c.__cache[e]={}),c.__cache[e][b]=d},c.GetData=function(b,d){var e=c.GetUniqueElementId(b);return d?c.__cache[e]&&null!=c.__cache[e][d]?c.__cache[e][d]:a(b).data(d):c.__cache[e]},c.RemoveData=function(a){var b=c.GetUniqueElementId(a);null!=c.__cache[b]&&delete c.__cache[b]},c}),b.define("select2/results",["jquery","./utils"],function(a,b){function c(a,b,d){this.$element=a,this.data=d,this.options=b,c.__super__.constructor.call(this)}return b.Extend(c,b.Observable),c.prototype.render=function(){var b=a('<ul class="select2-results__options" role="tree"></ul>');return this.options.get("multiple")&&b.attr("aria-multiselectable","true"),this.$results=b,b},c.prototype.clear=function(){this.$results.empty()},c.prototype.displayMessage=function(b){var c=this.options.get("escapeMarkup");this.clear(),this.hideLoading();var d=a('<li role="treeitem" aria-live="assertive" class="select2-results__option"></li>'),e=this.options.get("translations").get(b.message);d.append(c(e(b.args))),d[0].className+=" select2-results__message",this.$results.append(d)},c.prototype.hideMessages=function(){this.$results.find(".select2-results__message").remove()},c.prototype.append=function(a){this.hideLoading();var b=[];if(null==a.results||0===a.results.length)return void(0===this.$results.children().length&&this.trigger("results:message",{message:"noResults"}));a.results=this.sort(a.results);for(var c=0;c<a.results.length;c++){var d=a.results[c],e=this.option(d);b.push(e)}this.$results.append(b)},c.prototype.position=function(a,b){b.find(".select2-results").append(a)},c.prototype.sort=function(a){return this.options.get("sorter")(a)},c.prototype.highlightFirstItem=function(){var a=this.$results.find(".select2-results__option[aria-selected]"),b=a.filter("[aria-selected=true]");b.length>0?b.first().trigger("mouseenter"):a.first().trigger("mouseenter"),this.ensureHighlightVisible()},c.prototype.setClasses=function(){var c=this;this.data.current(function(d){var e=a.map(d,function(a){return a.id.toString()});c.$results.find(".select2-results__option[aria-selected]").each(function(){var c=a(this),d=b.GetData(this,"data"),f=""+d.id;null!=d.element&&d.element.selected||null==d.element&&a.inArray(f,e)>-1?c.attr("aria-selected","true"):c.attr("aria-selected","false")})})},c.prototype.showLoading=function(a){this.hideLoading();var b=this.options.get("translations").get("searching"),c={disabled:!0,loading:!0,text:b(a)},d=this.option(c);d.className+=" loading-results",this.$results.prepend(d)},c.prototype.hideLoading=function(){this.$results.find(".loading-results").remove()},c.prototype.option=function(c){var d=document.createElement("li");d.className="select2-results__option";var e={role:"treeitem","aria-selected":"false"};c.disabled&&(delete e["aria-selected"],e["aria-disabled"]="true"),null==c.id&&delete e["aria-selected"],null!=c._resultId&&(d.id=c._resultId),c.title&&(d.title=c.title),c.children&&(e.role="group",e["aria-label"]=c.text,delete e["aria-selected"]);for(var f in e){var g=e[f];d.setAttribute(f,g)}if(c.children){var h=a(d),i=document.createElement("strong");i.className="select2-results__group";a(i);this.template(c,i);for(var j=[],k=0;k<c.children.length;k++){var l=c.children[k],m=this.option(l);j.push(m)}var n=a("<ul></ul>",{class:"select2-results__options select2-results__options--nested"});n.append(j),h.append(i),h.append(n)}else this.template(c,d);return b.StoreData(d,"data",c),d},c.prototype.bind=function(c,d){var e=this,f=c.id+"-results";this.$results.attr("id",f),c.on("results:all",function(a){e.clear(),e.append(a.data),c.isOpen()&&(e.setClasses(),e.highlightFirstItem())}),c.on("results:append",function(a){e.append(a.data),c.isOpen()&&e.setClasses()}),c.on("query",function(a){e.hideMessages(),e.showLoading(a)}),c.on("select",function(){c.isOpen()&&(e.setClasses(),e.highlightFirstItem())}),c.on("unselect",function(){c.isOpen()&&(e.setClasses(),e.highlightFirstItem())}),c.on("open",function(){e.$results.attr("aria-expanded","true"),e.$results.attr("aria-hidden","false"),e.setClasses(),e.ensureHighlightVisible()}),c.on("close",function(){e.$results.attr("aria-expanded","false"),e.$results.attr("aria-hidden","true"),e.$results.removeAttr("aria-activedescendant")}),c.on("results:toggle",function(){var a=e.getHighlightedResults();0!==a.length&&a.trigger("mouseup")}),c.on("results:select",function(){var a=e.getHighlightedResults();if(0!==a.length){var c=b.GetData(a[0],"data");"true"==a.attr("aria-selected")?e.trigger("close",{}):e.trigger("select",{data:c})}}),c.on("results:previous",function(){var a=e.getHighlightedResults(),b=e.$results.find("[aria-selected]"),c=b.index(a);if(0!==c){var d=c-1;0===a.length&&(d=0);var f=b.eq(d);f.trigger("mouseenter");var g=e.$results.offset().top,h=f.offset().top,i=e.$results.scrollTop()+(h-g);0===d?e.$results.scrollTop(0):h-g<0&&e.$results.scrollTop(i)}}),c.on("results:next",function(){var a=e.getHighlightedResults(),b=e.$results.find("[aria-selected]"),c=b.index(a),d=c+1;if(!(d>=b.length)){var f=b.eq(d);f.trigger("mouseenter");var g=e.$results.offset().top+e.$results.outerHeight(!1),h=f.offset().top+f.outerHeight(!1),i=e.$results.scrollTop()+h-g;0===d?e.$results.scrollTop(0):h>g&&e.$results.scrollTop(i)}}),c.on("results:focus",function(a){a.element.addClass("select2-results__option--highlighted")}),c.on("results:message",function(a){e.displayMessage(a)}),a.fn.mousewheel&&this.$results.on("mousewheel",function(a){var b=e.$results.scrollTop(),c=e.$results.get(0).scrollHeight-b+a.deltaY,d=a.deltaY>0&&b-a.deltaY<=0,f=a.deltaY<0&&c<=e.$results.height();d?(e.$results.scrollTop(0),a.preventDefault(),a.stopPropagation()):f&&(e.$results.scrollTop(e.$results.get(0).scrollHeight-e.$results.height()),a.preventDefault(),a.stopPropagation())}),this.$results.on("mouseup",".select2-results__option[aria-selected]",function(c){var d=a(this),f=b.GetData(this,"data");if("true"===d.attr("aria-selected"))return void(e.options.get("multiple")?e.trigger("unselect",{originalEvent:c,data:f}):e.trigger("close",{}));e.trigger("select",{originalEvent:c,data:f})}),this.$results.on("mouseenter",".select2-results__option[aria-selected]",function(c){var d=b.GetData(this,"data");e.getHighlightedResults().removeClass("select2-results__option--highlighted"),e.trigger("results:focus",{data:d,element:a(this)})})},c.prototype.getHighlightedResults=function(){return this.$results.find(".select2-results__option--highlighted")},c.prototype.destroy=function(){this.$results.remove()},c.prototype.ensureHighlightVisible=function(){var a=this.getHighlightedResults();if(0!==a.length){var b=this.$results.find("[aria-selected]"),c=b.index(a),d=this.$results.offset().top,e=a.offset().top,f=this.$results.scrollTop()+(e-d),g=e-d;f-=2*a.outerHeight(!1),c<=2?this.$results.scrollTop(0):(g>this.$results.outerHeight()||g<0)&&this.$results.scrollTop(f)}},c.prototype.template=function(b,c){var d=this.options.get("templateResult"),e=this.options.get("escapeMarkup"),f=d(b,c);null==f?c.style.display="none":"string"==typeof f?c.innerHTML=e(f):a(c).append(f)},c}),b.define("select2/keys",[],function(){return{BACKSPACE:8,TAB:9,ENTER:13,SHIFT:16,CTRL:17,ALT:18,ESC:27,SPACE:32,PAGE_UP:33,PAGE_DOWN:34,END:35,HOME:36,LEFT:37,UP:38,RIGHT:39,DOWN:40,DELETE:46}}),b.define("select2/selection/base",["jquery","../utils","../keys"],function(a,b,c){function d(a,b){this.$element=a,this.options=b,d.__super__.constructor.call(this)}return b.Extend(d,b.Observable),d.prototype.render=function(){var c=a('<span class="select2-selection" role="combobox" aria-haspopup="true" aria-expanded="false"></span>');return this._tabindex=0,null!=b.GetData(this.$element[0],"old-tabindex")?this._tabindex=b.GetData(this.$element[0],"old-tabindex"):null!=this.$element.attr("tabindex")&&(this._tabindex=this.$element.attr("tabindex")),c.attr("title",this.$element.attr("title")),c.attr("tabindex",this._tabindex),this.$selection=c,c},d.prototype.bind=function(a,b){var d=this,e=(a.id,a.id+"-results");this.container=a,this.$selection.on("focus",function(a){d.trigger("focus",a)}),this.$selection.on("blur",function(a){d._handleBlur(a)}),this.$selection.on("keydown",function(a){d.trigger("keypress",a),a.which===c.SPACE&&a.preventDefault()}),a.on("results:focus",function(a){d.$selection.attr("aria-activedescendant",a.data._resultId)}),a.on("selection:update",function(a){d.update(a.data)}),a.on("open",function(){d.$selection.attr("aria-expanded","true"),d.$selection.attr("aria-owns",e),d._attachCloseHandler(a)}),a.on("close",function(){d.$selection.attr("aria-expanded","false"),d.$selection.removeAttr("aria-activedescendant"),d.$selection.removeAttr("aria-owns"),d.$selection.focus(),d._detachCloseHandler(a)}),a.on("enable",function(){d.$selection.attr("tabindex",d._tabindex)}),a.on("disable",function(){d.$selection.attr("tabindex","-1")})},d.prototype._handleBlur=function(b){var c=this;window.setTimeout(function(){document.activeElement==c.$selection[0]||a.contains(c.$selection[0],document.activeElement)||c.trigger("blur",b)},1)},d.prototype._attachCloseHandler=function(c){a(document.body).on("mousedown.select2."+c.id,function(c){var d=a(c.target),e=d.closest(".select2");a(".select2.select2-container--open").each(function(){a(this),this!=e[0]&&b.GetData(this,"element").select2("close")})})},d.prototype._detachCloseHandler=function(b){a(document.body).off("mousedown.select2."+b.id)},d.prototype.position=function(a,b){b.find(".selection").append(a)},d.prototype.destroy=function(){this._detachCloseHandler(this.container)},d.prototype.update=function(a){throw new Error("The `update` method must be defined in child classes.")},d}),b.define("select2/selection/single",["jquery","./base","../utils","../keys"],function(a,b,c,d){function e(){e.__super__.constructor.apply(this,arguments)}return c.Extend(e,b),e.prototype.render=function(){var a=e.__super__.render.call(this);return a.addClass("select2-selection--single"),a.html('<span class="select2-selection__rendered"></span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span>'),a},e.prototype.bind=function(a,b){var c=this;e.__super__.bind.apply(this,arguments);var d=a.id+"-container";this.$selection.find(".select2-selection__rendered").attr("id",d).attr("role","textbox").attr("aria-readonly","true"),this.$selection.attr("aria-labelledby",d),this.$selection.on("mousedown",function(a){1===a.which&&c.trigger("toggle",{originalEvent:a})}),this.$selection.on("focus",function(a){}),this.$selection.on("blur",function(a){}),a.on("focus",function(b){a.isOpen()||c.$selection.focus()})},e.prototype.clear=function(){var a=this.$selection.find(".select2-selection__rendered");a.empty(),a.removeAttr("title")},e.prototype.display=function(a,b){var c=this.options.get("templateSelection");return this.options.get("escapeMarkup")(c(a,b))},e.prototype.selectionContainer=function(){return a("<span></span>")},e.prototype.update=function(a){if(0===a.length)return void this.clear();var b=a[0],c=this.$selection.find(".select2-selection__rendered"),d=this.display(b,c);c.empty().append(d),c.attr("title",b.title||b.text)},e}),b.define("select2/selection/multiple",["jquery","./base","../utils"],function(a,b,c){function d(a,b){d.__super__.constructor.apply(this,arguments)}return c.Extend(d,b),d.prototype.render=function(){var a=d.__super__.render.call(this);return a.addClass("select2-selection--multiple"),a.html('<ul class="select2-selection__rendered"></ul>'),a},d.prototype.bind=function(b,e){var f=this;d.__super__.bind.apply(this,arguments),this.$selection.on("click",function(a){f.trigger("toggle",{originalEvent:a})}),this.$selection.on("click",".select2-selection__choice__remove",function(b){if(!f.options.get("disabled")){var d=a(this),e=d.parent(),g=c.GetData(e[0],"data");f.trigger("unselect",{originalEvent:b,data:g})}})},d.prototype.clear=function(){var a=this.$selection.find(".select2-selection__rendered");a.empty(),a.removeAttr("title")},d.prototype.display=function(a,b){var c=this.options.get("templateSelection");return this.options.get("escapeMarkup")(c(a,b))},d.prototype.selectionContainer=function(){return a('<li class="select2-selection__choice"><span class="select2-selection__choice__remove" role="presentation">×</span></li>')},d.prototype.update=function(a){if(this.clear(),0!==a.length){for(var b=[],d=0;d<a.length;d++){var e=a[d],f=this.selectionContainer(),g=this.display(e,f);f.append(g),f.attr("title",e.title||e.text),c.StoreData(f[0],"data",e),b.push(f)}var h=this.$selection.find(".select2-selection__rendered");c.appendMany(h,b)}},d}),b.define("select2/selection/placeholder",["../utils"],function(a){function b(a,b,c){this.placeholder=this.normalizePlaceholder(c.get("placeholder")),a.call(this,b,c)}return b.prototype.normalizePlaceholder=function(a,b){return"string"==typeof b&&(b={id:"",text:b}),b},b.prototype.createPlaceholder=function(a,b){var c=this.selectionContainer();return c.html(this.display(b)),c.addClass("select2-selection__placeholder").removeClass("select2-selection__choice"),c},b.prototype.update=function(a,b){var c=1==b.length&&b[0].id!=this.placeholder.id;if(b.length>1||c)return a.call(this,b);this.clear();var d=this.createPlaceholder(this.placeholder);this.$selection.find(".select2-selection__rendered").append(d)},b}),b.define("select2/selection/allowClear",["jquery","../keys","../utils"],function(a,b,c){function d(){}return d.prototype.bind=function(a,b,c){var d=this;a.call(this,b,c),null==this.placeholder&&this.options.get("debug")&&window.console&&console.error&&console.error("Select2: The `allowClear` option should be used in combination with the `placeholder` option."),this.$selection.on("mousedown",".select2-selection__clear",function(a){d._handleClear(a)}),b.on("keypress",function(a){d._handleKeyboardClear(a,b)})},d.prototype._handleClear=function(a,b){if(!this.options.get("disabled")){var d=this.$selection.find(".select2-selection__clear");if(0!==d.length){b.stopPropagation();var e=c.GetData(d[0],"data"),f=this.$element.val();this.$element.val(this.placeholder.id);var g={data:e};if(this.trigger("clear",g),g.prevented)return void this.$element.val(f);for(var h=0;h<e.length;h++)if(g={data:e[h]},this.trigger("unselect",g),g.prevented)return void this.$element.val(f);this.$element.trigger("change"),this.trigger("toggle",{})}}},d.prototype._handleKeyboardClear=function(a,c,d){d.isOpen()||c.which!=b.DELETE&&c.which!=b.BACKSPACE||this._handleClear(c)},d.prototype.update=function(b,d){if(b.call(this,d),!(this.$selection.find(".select2-selection__placeholder").length>0||0===d.length)){var e=a('<span class="select2-selection__clear">×</span>');c.StoreData(e[0],"data",d),this.$selection.find(".select2-selection__rendered").prepend(e)}},d}),b.define("select2/selection/search",["jquery","../utils","../keys"],function(a,b,c){function d(a,b,c){a.call(this,b,c)}return d.prototype.render=function(b){var c=a('<li class="select2-search select2-search--inline"><input class="select2-search__field" type="search" tabindex="-1" autocomplete="off" autocorrect="off" autocapitalize="none" spellcheck="false" role="textbox" aria-autocomplete="list" /></li>');this.$searchContainer=c,this.$search=c.find("input");var d=b.call(this);return this._transferTabIndex(),d},d.prototype.bind=function(a,d,e){var f=this;a.call(this,d,e),d.on("open",function(){f.$search.trigger("focus")}),d.on("close",function(){f.$search.val(""),f.$search.removeAttr("aria-activedescendant"),f.$search.trigger("focus")}),d.on("enable",function(){f.$search.prop("disabled",!1),f._transferTabIndex()}),d.on("disable",function(){f.$search.prop("disabled",!0)}),d.on("focus",function(a){f.$search.trigger("focus")}),d.on("results:focus",function(a){f.$search.attr("aria-activedescendant",a.id)}),this.$selection.on("focusin",".select2-search--inline",function(a){f.trigger("focus",a)}),this.$selection.on("focusout",".select2-search--inline",function(a){f._handleBlur(a)}),this.$selection.on("keydown",".select2-search--inline",function(a){if(a.stopPropagation(),f.trigger("keypress",a),f._keyUpPrevented=a.isDefaultPrevented(),a.which===c.BACKSPACE&&""===f.$search.val()){var d=f.$searchContainer.prev(".select2-selection__choice");if(d.length>0){var e=b.GetData(d[0],"data");f.searchRemoveChoice(e),a.preventDefault()}}});var g=document.documentMode,h=g&&g<=11;this.$selection.on("input.searchcheck",".select2-search--inline",function(a){if(h)return void f.$selection.off("input.search input.searchcheck");f.$selection.off("keyup.search")}),this.$selection.on("keyup.search input.search",".select2-search--inline",function(a){if(h&&"input"===a.type)return void f.$selection.off("input.search input.searchcheck");var b=a.which;b!=c.SHIFT&&b!=c.CTRL&&b!=c.ALT&&b!=c.TAB&&f.handleSearch(a)})},d.prototype._transferTabIndex=function(a){this.$search.attr("tabindex",this.$selection.attr("tabindex")),this.$selection.attr("tabindex","-1")},d.prototype.createPlaceholder=function(a,b){this.$search.attr("placeholder",b.text)},d.prototype.update=function(a,b){var c=this.$search[0]==document.activeElement;this.$search.attr("placeholder",""),a.call(this,b),this.$selection.find(".select2-selection__rendered").append(this.$searchContainer),this.resizeSearch(),c&&this.$search.focus()},d.prototype.handleSearch=function(){if(this.resizeSearch(),!this._keyUpPrevented){var a=this.$search.val();this.trigger("query",{term:a})}this._keyUpPrevented=!1},d.prototype.searchRemoveChoice=function(a,b){this.trigger("unselect",{data:b}),this.$search.val(b.text),this.handleSearch()},d.prototype.resizeSearch=function(){this.$search.css("width","25px");var a="";if(""!==this.$search.attr("placeholder"))a=this.$selection.find(".select2-selection__rendered").innerWidth();else{a=.75*(this.$search.val().length+1)+"em"}this.$search.css("width",a)},d}),b.define("select2/selection/eventRelay",["jquery"],function(a){function b(){}return b.prototype.bind=function(b,c,d){var e=this,f=["open","opening","close","closing","select","selecting","unselect","unselecting","clear","clearing"],g=["opening","closing","selecting","unselecting","clearing"];b.call(this,c,d),c.on("*",function(b,c){if(-1!==a.inArray(b,f)){c=c||{};var d=a.Event("select2:"+b,{params:c});e.$element.trigger(d),-1!==a.inArray(b,g)&&(c.prevented=d.isDefaultPrevented())}})},b}),b.define("select2/translation",["jquery","require"],function(a,b){function c(a){this.dict=a||{}}return c.prototype.all=function(){return this.dict},c.prototype.get=function(a){return this.dict[a]},c.prototype.extend=function(b){this.dict=a.extend({},b.all(),this.dict)},c._cache={},c.loadPath=function(a){if(!(a in c._cache)){var d=b(a);c._cache[a]=d}return new c(c._cache[a])},c}),b.define("select2/diacritics",[],function(){return{"Ⓐ":"A","A":"A","À":"A","Á":"A","Â":"A","Ầ":"A","Ấ":"A","Ẫ":"A","Ẩ":"A","Ã":"A","Ā":"A","Ă":"A","Ằ":"A","Ắ":"A","Ẵ":"A","Ẳ":"A","Ȧ":"A","Ǡ":"A","Ä":"A","Ǟ":"A","Ả":"A","Å":"A","Ǻ":"A","Ǎ":"A","Ȁ":"A","Ȃ":"A","Ạ":"A","Ậ":"A","Ặ":"A","Ḁ":"A","Ą":"A","Ⱥ":"A","Ɐ":"A","Ꜳ":"AA","Æ":"AE","Ǽ":"AE","Ǣ":"AE","Ꜵ":"AO","Ꜷ":"AU","Ꜹ":"AV","Ꜻ":"AV","Ꜽ":"AY","Ⓑ":"B","B":"B","Ḃ":"B","Ḅ":"B","Ḇ":"B","Ƀ":"B","Ƃ":"B","Ɓ":"B","Ⓒ":"C","C":"C","Ć":"C","Ĉ":"C","Ċ":"C","Č":"C","Ç":"C","Ḉ":"C","Ƈ":"C","Ȼ":"C","Ꜿ":"C","Ⓓ":"D","D":"D","Ḋ":"D","Ď":"D","Ḍ":"D","Ḑ":"D","Ḓ":"D","Ḏ":"D","Đ":"D","Ƌ":"D","Ɗ":"D","Ɖ":"D","Ꝺ":"D","DZ":"DZ","DŽ":"DZ","Dz":"Dz","Dž":"Dz","Ⓔ":"E","E":"E","È":"E","É":"E","Ê":"E","Ề":"E","Ế":"E","Ễ":"E","Ể":"E","Ẽ":"E","Ē":"E","Ḕ":"E","Ḗ":"E","Ĕ":"E","Ė":"E","Ë":"E","Ẻ":"E","Ě":"E","Ȅ":"E","Ȇ":"E","Ẹ":"E","Ệ":"E","Ȩ":"E","Ḝ":"E","Ę":"E","Ḙ":"E","Ḛ":"E","Ɛ":"E","Ǝ":"E","Ⓕ":"F","F":"F","Ḟ":"F","Ƒ":"F","Ꝼ":"F","Ⓖ":"G","G":"G","Ǵ":"G","Ĝ":"G","Ḡ":"G","Ğ":"G","Ġ":"G","Ǧ":"G","Ģ":"G","Ǥ":"G","Ɠ":"G","Ꞡ":"G","Ᵹ":"G","Ꝿ":"G","Ⓗ":"H","H":"H","Ĥ":"H","Ḣ":"H","Ḧ":"H","Ȟ":"H","Ḥ":"H","Ḩ":"H","Ḫ":"H","Ħ":"H","Ⱨ":"H","Ⱶ":"H","Ɥ":"H","Ⓘ":"I","I":"I","Ì":"I","Í":"I","Î":"I","Ĩ":"I","Ī":"I","Ĭ":"I","İ":"I","Ï":"I","Ḯ":"I","Ỉ":"I","Ǐ":"I","Ȉ":"I","Ȋ":"I","Ị":"I","Į":"I","Ḭ":"I","Ɨ":"I","Ⓙ":"J","J":"J","Ĵ":"J","Ɉ":"J","Ⓚ":"K","K":"K","Ḱ":"K","Ǩ":"K","Ḳ":"K","Ķ":"K","Ḵ":"K","Ƙ":"K","Ⱪ":"K","Ꝁ":"K","Ꝃ":"K","Ꝅ":"K","Ꞣ":"K","Ⓛ":"L","L":"L","Ŀ":"L","Ĺ":"L","Ľ":"L","Ḷ":"L","Ḹ":"L","Ļ":"L","Ḽ":"L","Ḻ":"L","Ł":"L","Ƚ":"L","Ɫ":"L","Ⱡ":"L","Ꝉ":"L","Ꝇ":"L","Ꞁ":"L","LJ":"LJ","Lj":"Lj","Ⓜ":"M","M":"M","Ḿ":"M","Ṁ":"M","Ṃ":"M","Ɱ":"M","Ɯ":"M","Ⓝ":"N","N":"N","Ǹ":"N","Ń":"N","Ñ":"N","Ṅ":"N","Ň":"N","Ṇ":"N","Ņ":"N","Ṋ":"N","Ṉ":"N","Ƞ":"N","Ɲ":"N","Ꞑ":"N","Ꞥ":"N","NJ":"NJ","Nj":"Nj","Ⓞ":"O","O":"O","Ò":"O","Ó":"O","Ô":"O","Ồ":"O","Ố":"O","Ỗ":"O","Ổ":"O","Õ":"O","Ṍ":"O","Ȭ":"O","Ṏ":"O","Ō":"O","Ṑ":"O","Ṓ":"O","Ŏ":"O","Ȯ":"O","Ȱ":"O","Ö":"O","Ȫ":"O","Ỏ":"O","Ő":"O","Ǒ":"O","Ȍ":"O","Ȏ":"O","Ơ":"O","Ờ":"O","Ớ":"O","Ỡ":"O","Ở":"O","Ợ":"O","Ọ":"O","Ộ":"O","Ǫ":"O","Ǭ":"O","Ø":"O","Ǿ":"O","Ɔ":"O","Ɵ":"O","Ꝋ":"O","Ꝍ":"O","Ƣ":"OI","Ꝏ":"OO","Ȣ":"OU","Ⓟ":"P","P":"P","Ṕ":"P","Ṗ":"P","Ƥ":"P","Ᵽ":"P","Ꝑ":"P","Ꝓ":"P","Ꝕ":"P","Ⓠ":"Q","Q":"Q","Ꝗ":"Q","Ꝙ":"Q","Ɋ":"Q","Ⓡ":"R","R":"R","Ŕ":"R","Ṙ":"R","Ř":"R","Ȑ":"R","Ȓ":"R","Ṛ":"R","Ṝ":"R","Ŗ":"R","Ṟ":"R","Ɍ":"R","Ɽ":"R","Ꝛ":"R","Ꞧ":"R","Ꞃ":"R","Ⓢ":"S","S":"S","ẞ":"S","Ś":"S","Ṥ":"S","Ŝ":"S","Ṡ":"S","Š":"S","Ṧ":"S","Ṣ":"S","Ṩ":"S","Ș":"S","Ş":"S","Ȿ":"S","Ꞩ":"S","Ꞅ":"S","Ⓣ":"T","T":"T","Ṫ":"T","Ť":"T","Ṭ":"T","Ț":"T","Ţ":"T","Ṱ":"T","Ṯ":"T","Ŧ":"T","Ƭ":"T","Ʈ":"T","Ⱦ":"T","Ꞇ":"T","Ꜩ":"TZ","Ⓤ":"U","U":"U","Ù":"U","Ú":"U","Û":"U","Ũ":"U","Ṹ":"U","Ū":"U","Ṻ":"U","Ŭ":"U","Ü":"U","Ǜ":"U","Ǘ":"U","Ǖ":"U","Ǚ":"U","Ủ":"U","Ů":"U","Ű":"U","Ǔ":"U","Ȕ":"U","Ȗ":"U","Ư":"U","Ừ":"U","Ứ":"U","Ữ":"U","Ử":"U","Ự":"U","Ụ":"U","Ṳ":"U","Ų":"U","Ṷ":"U","Ṵ":"U","Ʉ":"U","Ⓥ":"V","V":"V","Ṽ":"V","Ṿ":"V","Ʋ":"V","Ꝟ":"V","Ʌ":"V","Ꝡ":"VY","Ⓦ":"W","W":"W","Ẁ":"W","Ẃ":"W","Ŵ":"W","Ẇ":"W","Ẅ":"W","Ẉ":"W","Ⱳ":"W","Ⓧ":"X","X":"X","Ẋ":"X","Ẍ":"X","Ⓨ":"Y","Y":"Y","Ỳ":"Y","Ý":"Y","Ŷ":"Y","Ỹ":"Y","Ȳ":"Y","Ẏ":"Y","Ÿ":"Y","Ỷ":"Y","Ỵ":"Y","Ƴ":"Y","Ɏ":"Y","Ỿ":"Y","Ⓩ":"Z","Z":"Z","Ź":"Z","Ẑ":"Z","Ż":"Z","Ž":"Z","Ẓ":"Z","Ẕ":"Z","Ƶ":"Z","Ȥ":"Z","Ɀ":"Z","Ⱬ":"Z","Ꝣ":"Z","ⓐ":"a","a":"a","ẚ":"a","à":"a","á":"a","â":"a","ầ":"a","ấ":"a","ẫ":"a","ẩ":"a","ã":"a","ā":"a","ă":"a","ằ":"a","ắ":"a","ẵ":"a","ẳ":"a","ȧ":"a","ǡ":"a","ä":"a","ǟ":"a","ả":"a","å":"a","ǻ":"a","ǎ":"a","ȁ":"a","ȃ":"a","ạ":"a","ậ":"a","ặ":"a","ḁ":"a","ą":"a","ⱥ":"a","ɐ":"a","ꜳ":"aa","æ":"ae","ǽ":"ae","ǣ":"ae","ꜵ":"ao","ꜷ":"au","ꜹ":"av","ꜻ":"av","ꜽ":"ay","ⓑ":"b","b":"b","ḃ":"b","ḅ":"b","ḇ":"b","ƀ":"b","ƃ":"b","ɓ":"b","ⓒ":"c","c":"c","ć":"c","ĉ":"c","ċ":"c","č":"c","ç":"c","ḉ":"c","ƈ":"c","ȼ":"c","ꜿ":"c","ↄ":"c","ⓓ":"d","d":"d","ḋ":"d","ď":"d","ḍ":"d","ḑ":"d","ḓ":"d","ḏ":"d","đ":"d","ƌ":"d","ɖ":"d","ɗ":"d","ꝺ":"d","dz":"dz","dž":"dz","ⓔ":"e","e":"e","è":"e","é":"e","ê":"e","ề":"e","ế":"e","ễ":"e","ể":"e","ẽ":"e","ē":"e","ḕ":"e","ḗ":"e","ĕ":"e","ė":"e","ë":"e","ẻ":"e","ě":"e","ȅ":"e","ȇ":"e","ẹ":"e","ệ":"e","ȩ":"e","ḝ":"e","ę":"e","ḙ":"e","ḛ":"e","ɇ":"e","ɛ":"e","ǝ":"e","ⓕ":"f","f":"f","ḟ":"f","ƒ":"f","ꝼ":"f","ⓖ":"g","g":"g","ǵ":"g","ĝ":"g","ḡ":"g","ğ":"g","ġ":"g","ǧ":"g","ģ":"g","ǥ":"g","ɠ":"g","ꞡ":"g","ᵹ":"g","ꝿ":"g","ⓗ":"h","h":"h","ĥ":"h","ḣ":"h","ḧ":"h","ȟ":"h","ḥ":"h","ḩ":"h","ḫ":"h","ẖ":"h","ħ":"h","ⱨ":"h","ⱶ":"h","ɥ":"h","ƕ":"hv","ⓘ":"i","i":"i","ì":"i","í":"i","î":"i","ĩ":"i","ī":"i","ĭ":"i","ï":"i","ḯ":"i","ỉ":"i","ǐ":"i","ȉ":"i","ȋ":"i","ị":"i","į":"i","ḭ":"i","ɨ":"i","ı":"i","ⓙ":"j","j":"j","ĵ":"j","ǰ":"j","ɉ":"j","ⓚ":"k","k":"k","ḱ":"k","ǩ":"k","ḳ":"k","ķ":"k","ḵ":"k","ƙ":"k","ⱪ":"k","ꝁ":"k","ꝃ":"k","ꝅ":"k","ꞣ":"k","ⓛ":"l","l":"l","ŀ":"l","ĺ":"l","ľ":"l","ḷ":"l","ḹ":"l","ļ":"l","ḽ":"l","ḻ":"l","ſ":"l","ł":"l","ƚ":"l","ɫ":"l","ⱡ":"l","ꝉ":"l","ꞁ":"l","ꝇ":"l","lj":"lj","ⓜ":"m","m":"m","ḿ":"m","ṁ":"m","ṃ":"m","ɱ":"m","ɯ":"m","ⓝ":"n","n":"n","ǹ":"n","ń":"n","ñ":"n","ṅ":"n","ň":"n","ṇ":"n","ņ":"n","ṋ":"n","ṉ":"n","ƞ":"n","ɲ":"n","ʼn":"n","ꞑ":"n","ꞥ":"n","nj":"nj","ⓞ":"o","o":"o","ò":"o","ó":"o","ô":"o","ồ":"o","ố":"o","ỗ":"o","ổ":"o","õ":"o","ṍ":"o","ȭ":"o","ṏ":"o","ō":"o","ṑ":"o","ṓ":"o","ŏ":"o","ȯ":"o","ȱ":"o","ö":"o","ȫ":"o","ỏ":"o","ő":"o","ǒ":"o","ȍ":"o","ȏ":"o","ơ":"o","ờ":"o","ớ":"o","ỡ":"o","ở":"o","ợ":"o","ọ":"o","ộ":"o","ǫ":"o","ǭ":"o","ø":"o","ǿ":"o","ɔ":"o","ꝋ":"o","ꝍ":"o","ɵ":"o","ƣ":"oi","ȣ":"ou","ꝏ":"oo","ⓟ":"p","p":"p","ṕ":"p","ṗ":"p","ƥ":"p","ᵽ":"p","ꝑ":"p","ꝓ":"p","ꝕ":"p","ⓠ":"q","q":"q","ɋ":"q","ꝗ":"q","ꝙ":"q","ⓡ":"r","r":"r","ŕ":"r","ṙ":"r","ř":"r","ȑ":"r","ȓ":"r","ṛ":"r","ṝ":"r","ŗ":"r","ṟ":"r","ɍ":"r","ɽ":"r","ꝛ":"r","ꞧ":"r","ꞃ":"r","ⓢ":"s","s":"s","ß":"s","ś":"s","ṥ":"s","ŝ":"s","ṡ":"s","š":"s","ṧ":"s","ṣ":"s","ṩ":"s","ș":"s","ş":"s","ȿ":"s","ꞩ":"s","ꞅ":"s","ẛ":"s","ⓣ":"t","t":"t","ṫ":"t","ẗ":"t","ť":"t","ṭ":"t","ț":"t","ţ":"t","ṱ":"t","ṯ":"t","ŧ":"t","ƭ":"t","ʈ":"t","ⱦ":"t","ꞇ":"t","ꜩ":"tz","ⓤ":"u","u":"u","ù":"u","ú":"u","û":"u","ũ":"u","ṹ":"u","ū":"u","ṻ":"u","ŭ":"u","ü":"u","ǜ":"u","ǘ":"u","ǖ":"u","ǚ":"u","ủ":"u","ů":"u","ű":"u","ǔ":"u","ȕ":"u","ȗ":"u","ư":"u","ừ":"u","ứ":"u","ữ":"u","ử":"u","ự":"u","ụ":"u","ṳ":"u","ų":"u","ṷ":"u","ṵ":"u","ʉ":"u","ⓥ":"v","v":"v","ṽ":"v","ṿ":"v","ʋ":"v","ꝟ":"v","ʌ":"v","ꝡ":"vy","ⓦ":"w","w":"w","ẁ":"w","ẃ":"w","ŵ":"w","ẇ":"w","ẅ":"w","ẘ":"w","ẉ":"w","ⱳ":"w","ⓧ":"x","x":"x","ẋ":"x","ẍ":"x","ⓨ":"y","y":"y","ỳ":"y","ý":"y","ŷ":"y","ỹ":"y","ȳ":"y","ẏ":"y","ÿ":"y","ỷ":"y","ẙ":"y","ỵ":"y","ƴ":"y","ɏ":"y","ỿ":"y","ⓩ":"z","z":"z","ź":"z","ẑ":"z","ż":"z","ž":"z","ẓ":"z","ẕ":"z","ƶ":"z","ȥ":"z","ɀ":"z","ⱬ":"z","ꝣ":"z","Ά":"Α","Έ":"Ε","Ή":"Η","Ί":"Ι","Ϊ":"Ι","Ό":"Ο","Ύ":"Υ","Ϋ":"Υ","Ώ":"Ω","ά":"α","έ":"ε","ή":"η","ί":"ι","ϊ":"ι","ΐ":"ι","ό":"ο","ύ":"υ","ϋ":"υ","ΰ":"υ","ω":"ω","ς":"σ"}}),b.define("select2/data/base",["../utils"],function(a){function b(a,c){b.__super__.constructor.call(this)}return a.Extend(b,a.Observable),b.prototype.current=function(a){throw new Error("The `current` method must be defined in child classes.")},b.prototype.query=function(a,b){throw new Error("The `query` method must be defined in child classes.")},b.prototype.bind=function(a,b){},b.prototype.destroy=function(){},b.prototype.generateResultId=function(b,c){var d=b.id+"-result-";return d+=a.generateChars(4),null!=c.id?d+="-"+c.id.toString():d+="-"+a.generateChars(4),d},b}),b.define("select2/data/select",["./base","../utils","jquery"],function(a,b,c){function d(a,b){this.$element=a,this.options=b,d.__super__.constructor.call(this)}return b.Extend(d,a),d.prototype.current=function(a){var b=[],d=this;this.$element.find(":selected").each(function(){var a=c(this),e=d.item(a);b.push(e)}),a(b)},d.prototype.select=function(a){var b=this;if(a.selected=!0,c(a.element).is("option"))return a.element.selected=!0,void this.$element.trigger("change");if(this.$element.prop("multiple"))this.current(function(d){var e=[];a=[a],a.push.apply(a,d);for(var f=0;f<a.length;f++){var g=a[f].id;-1===c.inArray(g,e)&&e.push(g)}b.$element.val(e),b.$element.trigger("change")});else{var d=a.id;this.$element.val(d),this.$element.trigger("change")}},d.prototype.unselect=function(a){var b=this;if(this.$element.prop("multiple")){if(a.selected=!1,c(a.element).is("option"))return a.element.selected=!1,void this.$element.trigger("change");this.current(function(d){for(var e=[],f=0;f<d.length;f++){var g=d[f].id;g!==a.id&&-1===c.inArray(g,e)&&e.push(g)}b.$element.val(e),b.$element.trigger("change")})}},d.prototype.bind=function(a,b){var c=this;this.container=a,a.on("select",function(a){c.select(a.data)}),a.on("unselect",function(a){c.unselect(a.data)})},d.prototype.destroy=function(){this.$element.find("*").each(function(){b.RemoveData(this)})},d.prototype.query=function(a,b){var d=[],e=this;this.$element.children().each(function(){var b=c(this);if(b.is("option")||b.is("optgroup")){var f=e.item(b),g=e.matches(a,f);null!==g&&d.push(g)}}),b({results:d})},d.prototype.addOptions=function(a){b.appendMany(this.$element,a)},d.prototype.option=function(a){var d;a.children?(d=document.createElement("optgroup"),d.label=a.text):(d=document.createElement("option"),void 0!==d.textContent?d.textContent=a.text:d.innerText=a.text),void 0!==a.id&&(d.value=a.id),a.disabled&&(d.disabled=!0),a.selected&&(d.selected=!0),a.title&&(d.title=a.title);var e=c(d),f=this._normalizeItem(a);return f.element=d,b.StoreData(d,"data",f),e},d.prototype.item=function(a){var d={};if(null!=(d=b.GetData(a[0],"data")))return d;if(a.is("option"))d={id:a.val(),text:a.text(),disabled:a.prop("disabled"),selected:a.prop("selected"),title:a.prop("title")};else if(a.is("optgroup")){d={text:a.prop("label"),children:[],title:a.prop("title")};for(var e=a.children("option"),f=[],g=0;g<e.length;g++){var h=c(e[g]),i=this.item(h);f.push(i)}d.children=f}return d=this._normalizeItem(d),d.element=a[0],b.StoreData(a[0],"data",d),d},d.prototype._normalizeItem=function(a){a!==Object(a)&&(a={id:a,text:a}),a=c.extend({},{text:""},a);var b={selected:!1,disabled:!1};return null!=a.id&&(a.id=a.id.toString()),null!=a.text&&(a.text=a.text.toString()),null==a._resultId&&a.id&&null!=this.container&&(a._resultId=this.generateResultId(this.container,a)),c.extend({},b,a)},d.prototype.matches=function(a,b){return this.options.get("matcher")(a,b)},d}),b.define("select2/data/array",["./select","../utils","jquery"],function(a,b,c){function d(a,b){var c=b.get("data")||[];d.__super__.constructor.call(this,a,b),this.addOptions(this.convertToOptions(c))}return b.Extend(d,a),d.prototype.select=function(a){var b=this.$element.find("option").filter(function(b,c){return c.value==a.id.toString()});0===b.length&&(b=this.option(a),this.addOptions(b)),d.__super__.select.call(this,a)},d.prototype.convertToOptions=function(a){function d(a){return function(){return c(this).val()==a.id}}for(var e=this,f=this.$element.find("option"),g=f.map(function(){return e.item(c(this)).id}).get(),h=[],i=0;i<a.length;i++){var j=this._normalizeItem(a[i]);if(c.inArray(j.id,g)>=0){var k=f.filter(d(j)),l=this.item(k),m=c.extend(!0,{},j,l),n=this.option(m);k.replaceWith(n)}else{var o=this.option(j);if(j.children){var p=this.convertToOptions(j.children);b.appendMany(o,p)}h.push(o)}}return h},d}),b.define("select2/data/ajax",["./array","../utils","jquery"],function(a,b,c){function d(a,b){this.ajaxOptions=this._applyDefaults(b.get("ajax")),null!=this.ajaxOptions.processResults&&(this.processResults=this.ajaxOptions.processResults),d.__super__.constructor.call(this,a,b)}return b.Extend(d,a),d.prototype._applyDefaults=function(a){var b={data:function(a){return c.extend({},a,{q:a.term})},transport:function(a,b,d){var e=c.ajax(a);return e.then(b),e.fail(d),e}};return c.extend({},b,a,!0)},d.prototype.processResults=function(a){return a},d.prototype.query=function(a,b){function d(){var d=f.transport(f,function(d){var f=e.processResults(d,a);e.options.get("debug")&&window.console&&console.error&&(f&&f.results&&c.isArray(f.results)||console.error("Select2: The AJAX results did not return an array in the `results` key of the response.")),b(f)},function(){"status"in d&&(0===d.status||"0"===d.status)||e.trigger("results:message",{message:"errorLoading"})});e._request=d}var e=this;null!=this._request&&(c.isFunction(this._request.abort)&&this._request.abort(),this._request=null);var f=c.extend({type:"GET"},this.ajaxOptions);"function"==typeof f.url&&(f.url=f.url.call(this.$element,a)),"function"==typeof f.data&&(f.data=f.data.call(this.$element,a)),this.ajaxOptions.delay&&null!=a.term?(this._queryTimeout&&window.clearTimeout(this._queryTimeout),this._queryTimeout=window.setTimeout(d,this.ajaxOptions.delay)):d()},d}),b.define("select2/data/tags",["jquery"],function(a){function b(b,c,d){var e=d.get("tags"),f=d.get("createTag");void 0!==f&&(this.createTag=f);var g=d.get("insertTag");if(void 0!==g&&(this.insertTag=g),b.call(this,c,d),a.isArray(e))for(var h=0;h<e.length;h++){var i=e[h],j=this._normalizeItem(i),k=this.option(j);this.$element.append(k)}}return b.prototype.query=function(a,b,c){function d(a,f){for(var g=a.results,h=0;h<g.length;h++){var i=g[h],j=null!=i.children&&!d({results:i.children},!0);if((i.text||"").toUpperCase()===(b.term||"").toUpperCase()||j)return!f&&(a.data=g,void c(a))}if(f)return!0;var k=e.createTag(b);if(null!=k){var l=e.option(k);l.attr("data-select2-tag",!0),e.addOptions([l]),e.insertTag(g,k)}a.results=g,c(a)}var e=this;if(this._removeOldTags(),null==b.term||null!=b.page)return void a.call(this,b,c);a.call(this,b,d)},b.prototype.createTag=function(b,c){var d=a.trim(c.term);return""===d?null:{id:d,text:d}},b.prototype.insertTag=function(a,b,c){b.unshift(c)},b.prototype._removeOldTags=function(b){this._lastTag;this.$element.find("option[data-select2-tag]").each(function(){this.selected||a(this).remove()})},b}),b.define("select2/data/tokenizer",["jquery"],function(a){function b(a,b,c){var d=c.get("tokenizer");void 0!==d&&(this.tokenizer=d),a.call(this,b,c)}return b.prototype.bind=function(a,b,c){a.call(this,b,c),this.$search=b.dropdown.$search||b.selection.$search||c.find(".select2-search__field")},b.prototype.query=function(b,c,d){function e(b){var c=g._normalizeItem(b);if(!g.$element.find("option").filter(function(){return a(this).val()===c.id}).length){var d=g.option(c);d.attr("data-select2-tag",!0),g._removeOldTags(),g.addOptions([d])}f(c)}function f(a){g.trigger("select",{data:a})}var g=this;c.term=c.term||"";var h=this.tokenizer(c,this.options,e);h.term!==c.term&&(this.$search.length&&(this.$search.val(h.term),this.$search.focus()),c.term=h.term),b.call(this,c,d)},b.prototype.tokenizer=function(b,c,d,e){for(var f=d.get("tokenSeparators")||[],g=c.term,h=0,i=this.createTag||function(a){return{id:a.term,text:a.term}};h<g.length;){var j=g[h];if(-1!==a.inArray(j,f)){var k=g.substr(0,h),l=a.extend({},c,{term:k}),m=i(l);null!=m?(e(m),g=g.substr(h+1)||"",h=0):h++}else h++}return{term:g}},b}),b.define("select2/data/minimumInputLength",[],function(){function a(a,b,c){this.minimumInputLength=c.get("minimumInputLength"),a.call(this,b,c)}return a.prototype.query=function(a,b,c){if(b.term=b.term||"",b.term.length<this.minimumInputLength)return void this.trigger("results:message",{message:"inputTooShort",args:{minimum:this.minimumInputLength,input:b.term,params:b}});a.call(this,b,c)},a}),b.define("select2/data/maximumInputLength",[],function(){function a(a,b,c){this.maximumInputLength=c.get("maximumInputLength"),a.call(this,b,c)}return a.prototype.query=function(a,b,c){if(b.term=b.term||"",this.maximumInputLength>0&&b.term.length>this.maximumInputLength)return void this.trigger("results:message",{message:"inputTooLong",args:{maximum:this.maximumInputLength,input:b.term,params:b}});a.call(this,b,c)},a}),b.define("select2/data/maximumSelectionLength",[],function(){function a(a,b,c){this.maximumSelectionLength=c.get("maximumSelectionLength"),a.call(this,b,c)}return a.prototype.query=function(a,b,c){var d=this;this.current(function(e){var f=null!=e?e.length:0;if(d.maximumSelectionLength>0&&f>=d.maximumSelectionLength)return void d.trigger("results:message",{message:"maximumSelected",args:{maximum:d.maximumSelectionLength}});a.call(d,b,c)})},a}),b.define("select2/dropdown",["jquery","./utils"],function(a,b){function c(a,b){this.$element=a,this.options=b,c.__super__.constructor.call(this)}return b.Extend(c,b.Observable),c.prototype.render=function(){var b=a('<span class="select2-dropdown"><span class="select2-results"></span></span>');return b.attr("dir",this.options.get("dir")),this.$dropdown=b,b},c.prototype.bind=function(){},c.prototype.position=function(a,b){},c.prototype.destroy=function(){this.$dropdown.remove()},c}),b.define("select2/dropdown/search",["jquery","../utils"],function(a,b){function c(){}return c.prototype.render=function(b){var c=b.call(this),d=a('<span class="select2-search select2-search--dropdown"><input class="select2-search__field" type="search" tabindex="-1" autocomplete="off" autocorrect="off" autocapitalize="none" spellcheck="false" role="textbox" /></span>');return this.$searchContainer=d,this.$search=d.find("input"),c.prepend(d),c},c.prototype.bind=function(b,c,d){var e=this;b.call(this,c,d),this.$search.on("keydown",function(a){e.trigger("keypress",a),e._keyUpPrevented=a.isDefaultPrevented()}),this.$search.on("input",function(b){a(this).off("keyup")}),this.$search.on("keyup input",function(a){e.handleSearch(a)}),c.on("open",function(){e.$search.attr("tabindex",0),e.$search.focus(),window.setTimeout(function(){e.$search.focus()},0)}),c.on("close",function(){e.$search.attr("tabindex",-1),e.$search.val(""),e.$search.blur()}),c.on("focus",function(){c.isOpen()||e.$search.focus()}),c.on("results:all",function(a){if(null==a.query.term||""===a.query.term){e.showSearch(a)?e.$searchContainer.removeClass("select2-search--hide"):e.$searchContainer.addClass("select2-search--hide")}})},c.prototype.handleSearch=function(a){if(!this._keyUpPrevented){var b=this.$search.val();this.trigger("query",{term:b})}this._keyUpPrevented=!1},c.prototype.showSearch=function(a,b){return!0},c}),b.define("select2/dropdown/hidePlaceholder",[],function(){function a(a,b,c,d){this.placeholder=this.normalizePlaceholder(c.get("placeholder")),a.call(this,b,c,d)}return a.prototype.append=function(a,b){b.results=this.removePlaceholder(b.results),a.call(this,b)},a.prototype.normalizePlaceholder=function(a,b){return"string"==typeof b&&(b={id:"",text:b}),b},a.prototype.removePlaceholder=function(a,b){for(var c=b.slice(0),d=b.length-1;d>=0;d--){var e=b[d];this.placeholder.id===e.id&&c.splice(d,1)}return c},a}),b.define("select2/dropdown/infiniteScroll",["jquery"],function(a){function b(a,b,c,d){this.lastParams={},a.call(this,b,c,d),this.$loadingMore=this.createLoadingMore(),this.loading=!1}return b.prototype.append=function(a,b){this.$loadingMore.remove(),this.loading=!1,a.call(this,b),this.showLoadingMore(b)&&this.$results.append(this.$loadingMore)},b.prototype.bind=function(b,c,d){var e=this;b.call(this,c,d),c.on("query",function(a){e.lastParams=a,e.loading=!0}),c.on("query:append",function(a){e.lastParams=a,e.loading=!0}),this.$results.on("scroll",function(){var b=a.contains(document.documentElement,e.$loadingMore[0]);if(!e.loading&&b){e.$results.offset().top+e.$results.outerHeight(!1)+50>=e.$loadingMore.offset().top+e.$loadingMore.outerHeight(!1)&&e.loadMore()}})},b.prototype.loadMore=function(){this.loading=!0;var b=a.extend({},{page:1},this.lastParams);b.page++,this.trigger("query:append",b)},b.prototype.showLoadingMore=function(a,b){return b.pagination&&b.pagination.more},b.prototype.createLoadingMore=function(){var b=a('<li class="select2-results__option select2-results__option--load-more"role="treeitem" aria-disabled="true"></li>'),c=this.options.get("translations").get("loadingMore");return b.html(c(this.lastParams)),b},b}),b.define("select2/dropdown/attachBody",["jquery","../utils"],function(a,b){function c(b,c,d){this.$dropdownParent=d.get("dropdownParent")||a(document.body),b.call(this,c,d)}return c.prototype.bind=function(a,b,c){var d=this,e=!1;a.call(this,b,c),b.on("open",function(){d._showDropdown(),d._attachPositioningHandler(b),e||(e=!0,b.on("results:all",function(){d._positionDropdown(),d._resizeDropdown()}),b.on("results:append",function(){d._positionDropdown(),d._resizeDropdown()}))}),b.on("close",function(){d._hideDropdown(),d._detachPositioningHandler(b)}),this.$dropdownContainer.on("mousedown",function(a){a.stopPropagation()})},c.prototype.destroy=function(a){a.call(this),this.$dropdownContainer.remove()},c.prototype.position=function(a,b,c){b.attr("class",c.attr("class")),b.removeClass("select2"),b.addClass("select2-container--open"),b.css({position:"absolute",top:-999999}),this.$container=c},c.prototype.render=function(b){var c=a("<span></span>"),d=b.call(this);return c.append(d),this.$dropdownContainer=c,c},c.prototype._hideDropdown=function(a){this.$dropdownContainer.detach()},c.prototype._attachPositioningHandler=function(c,d){var e=this,f="scroll.select2."+d.id,g="resize.select2."+d.id,h="orientationchange.select2."+d.id,i=this.$container.parents().filter(b.hasScroll);i.each(function(){b.StoreData(this,"select2-scroll-position",{x:a(this).scrollLeft(),y:a(this).scrollTop()})}),i.on(f,function(c){var d=b.GetData(this,"select2-scroll-position");a(this).scrollTop(d.y)}),a(window).on(f+" "+g+" "+h,function(a){e._positionDropdown(),e._resizeDropdown()})},c.prototype._detachPositioningHandler=function(c,d){var e="scroll.select2."+d.id,f="resize.select2."+d.id,g="orientationchange.select2."+d.id;this.$container.parents().filter(b.hasScroll).off(e),a(window).off(e+" "+f+" "+g)},c.prototype._positionDropdown=function(){var b=a(window),c=this.$dropdown.hasClass("select2-dropdown--above"),d=this.$dropdown.hasClass("select2-dropdown--below"),e=null,f=this.$container.offset();f.bottom=f.top+this.$container.outerHeight(!1);var g={height:this.$container.outerHeight(!1)};g.top=f.top,g.bottom=f.top+g.height;var h={height:this.$dropdown.outerHeight(!1)},i={top:b.scrollTop(),bottom:b.scrollTop()+b.height()},j=i.top<f.top-h.height,k=i.bottom>f.bottom+h.height,l={left:f.left,top:g.bottom},m=this.$dropdownParent;"static"===m.css("position")&&(m=m.offsetParent());var n=m.offset();l.top-=n.top,l.left-=n.left,c||d||(e="below"),k||!j||c?!j&&k&&c&&(e="below"):e="above",("above"==e||c&&"below"!==e)&&(l.top=g.top-n.top-h.height),null!=e&&(this.$dropdown.removeClass("select2-dropdown--below select2-dropdown--above").addClass("select2-dropdown--"+e),this.$container.removeClass("select2-container--below select2-container--above").addClass("select2-container--"+e)),this.$dropdownContainer.css(l)},c.prototype._resizeDropdown=function(){var a={width:this.$container.outerWidth(!1)+"px"};this.options.get("dropdownAutoWidth")&&(a.minWidth=a.width,a.position="relative",a.width="auto"),this.$dropdown.css(a)},c.prototype._showDropdown=function(a){this.$dropdownContainer.appendTo(this.$dropdownParent),this._positionDropdown(),this._resizeDropdown()},c}),b.define("select2/dropdown/minimumResultsForSearch",[],function(){function a(b){for(var c=0,d=0;d<b.length;d++){var e=b[d];e.children?c+=a(e.children):c++}return c}function b(a,b,c,d){this.minimumResultsForSearch=c.get("minimumResultsForSearch"),this.minimumResultsForSearch<0&&(this.minimumResultsForSearch=1/0),a.call(this,b,c,d)}return b.prototype.showSearch=function(b,c){return!(a(c.data.results)<this.minimumResultsForSearch)&&b.call(this,c)},b}),b.define("select2/dropdown/selectOnClose",["../utils"],function(a){function b(){}return b.prototype.bind=function(a,b,c){var d=this;a.call(this,b,c),b.on("close",function(a){d._handleSelectOnClose(a)})},b.prototype._handleSelectOnClose=function(b,c){if(c&&null!=c.originalSelect2Event){var d=c.originalSelect2Event;if("select"===d._type||"unselect"===d._type)return}var e=this.getHighlightedResults();if(!(e.length<1)){var f=a.GetData(e[0],"data");null!=f.element&&f.element.selected||null==f.element&&f.selected||this.trigger("select",{data:f})}},b}),b.define("select2/dropdown/closeOnSelect",[],function(){function a(){}return a.prototype.bind=function(a,b,c){var d=this;a.call(this,b,c),b.on("select",function(a){d._selectTriggered(a)}),b.on("unselect",function(a){d._selectTriggered(a)})},a.prototype._selectTriggered=function(a,b){var c=b.originalEvent;c&&c.ctrlKey||this.trigger("close",{originalEvent:c,originalSelect2Event:b})},a}),b.define("select2/i18n/en",[],function(){return{errorLoading:function(){return"The results could not be loaded."},inputTooLong:function(a){var b=a.input.length-a.maximum,c="Please delete "+b+" character";return 1!=b&&(c+="s"),c},inputTooShort:function(a){return"Please enter "+(a.minimum-a.input.length)+" or more characters"},loadingMore:function(){return"Loading more results…"},maximumSelected:function(a){var b="You can only select "+a.maximum+" item";return 1!=a.maximum&&(b+="s"),b},noResults:function(){return"No results found"},searching:function(){return"Searching…"}}}),b.define("select2/defaults",["jquery","require","./results","./selection/single","./selection/multiple","./selection/placeholder","./selection/allowClear","./selection/search","./selection/eventRelay","./utils","./translation","./diacritics","./data/select","./data/array","./data/ajax","./data/tags","./data/tokenizer","./data/minimumInputLength","./data/maximumInputLength","./data/maximumSelectionLength","./dropdown","./dropdown/search","./dropdown/hidePlaceholder","./dropdown/infiniteScroll","./dropdown/attachBody","./dropdown/minimumResultsForSearch","./dropdown/selectOnClose","./dropdown/closeOnSelect","./i18n/en"],function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C){function D(){this.reset()}return D.prototype.apply=function(l){if(l=a.extend(!0,{},this.defaults,l),null==l.dataAdapter){if(null!=l.ajax?l.dataAdapter=o:null!=l.data?l.dataAdapter=n:l.dataAdapter=m,l.minimumInputLength>0&&(l.dataAdapter=j.Decorate(l.dataAdapter,r)),l.maximumInputLength>0&&(l.dataAdapter=j.Decorate(l.dataAdapter,s)),l.maximumSelectionLength>0&&(l.dataAdapter=j.Decorate(l.dataAdapter,t)),l.tags&&(l.dataAdapter=j.Decorate(l.dataAdapter,p)),null==l.tokenSeparators&&null==l.tokenizer||(l.dataAdapter=j.Decorate(l.dataAdapter,q)),null!=l.query){var C=b(l.amdBase+"compat/query");l.dataAdapter=j.Decorate(l.dataAdapter,C)}if(null!=l.initSelection){var D=b(l.amdBase+"compat/initSelection");l.dataAdapter=j.Decorate(l.dataAdapter,D)}}if(null==l.resultsAdapter&&(l.resultsAdapter=c,null!=l.ajax&&(l.resultsAdapter=j.Decorate(l.resultsAdapter,x)),null!=l.placeholder&&(l.resultsAdapter=j.Decorate(l.resultsAdapter,w)),l.selectOnClose&&(l.resultsAdapter=j.Decorate(l.resultsAdapter,A))),null==l.dropdownAdapter){if(l.multiple)l.dropdownAdapter=u;else{var E=j.Decorate(u,v);l.dropdownAdapter=E}if(0!==l.minimumResultsForSearch&&(l.dropdownAdapter=j.Decorate(l.dropdownAdapter,z)),l.closeOnSelect&&(l.dropdownAdapter=j.Decorate(l.dropdownAdapter,B)),null!=l.dropdownCssClass||null!=l.dropdownCss||null!=l.adaptDropdownCssClass){var F=b(l.amdBase+"compat/dropdownCss");l.dropdownAdapter=j.Decorate(l.dropdownAdapter,F)}l.dropdownAdapter=j.Decorate(l.dropdownAdapter,y)}if(null==l.selectionAdapter){if(l.multiple?l.selectionAdapter=e:l.selectionAdapter=d,null!=l.placeholder&&(l.selectionAdapter=j.Decorate(l.selectionAdapter,f)),l.allowClear&&(l.selectionAdapter=j.Decorate(l.selectionAdapter,g)),l.multiple&&(l.selectionAdapter=j.Decorate(l.selectionAdapter,h)),null!=l.containerCssClass||null!=l.containerCss||null!=l.adaptContainerCssClass){var G=b(l.amdBase+"compat/containerCss");l.selectionAdapter=j.Decorate(l.selectionAdapter,G)}l.selectionAdapter=j.Decorate(l.selectionAdapter,i)}if("string"==typeof l.language)if(l.language.indexOf("-")>0){var H=l.language.split("-"),I=H[0];l.language=[l.language,I]}else l.language=[l.language];if(a.isArray(l.language)){var J=new k;l.language.push("en");for(var K=l.language,L=0;L<K.length;L++){var M=K[L],N={};try{N=k.loadPath(M)}catch(a){try{M=this.defaults.amdLanguageBase+M,N=k.loadPath(M)}catch(a){l.debug&&window.console&&console.warn&&console.warn('Select2: The language file for "'+M+'" could not be automatically loaded. A fallback will be used instead.');continue}}J.extend(N)}l.translations=J}else{var O=k.loadPath(this.defaults.amdLanguageBase+"en"),P=new k(l.language);P.extend(O),l.translations=P}return l},D.prototype.reset=function(){function b(a){function b(a){return l[a]||a}return a.replace(/[^\u0000-\u007E]/g,b)}function c(d,e){if(""===a.trim(d.term))return e;if(e.children&&e.children.length>0){for(var f=a.extend(!0,{},e),g=e.children.length-1;g>=0;g--){null==c(d,e.children[g])&&f.children.splice(g,1)}return f.children.length>0?f:c(d,f)}var h=b(e.text).toUpperCase(),i=b(d.term).toUpperCase();return h.indexOf(i)>-1?e:null}this.defaults={amdBase:"./",amdLanguageBase:"./i18n/",closeOnSelect:!0,debug:!1,dropdownAutoWidth:!1,escapeMarkup:j.escapeMarkup,language:C,matcher:c,minimumInputLength:0,maximumInputLength:0,maximumSelectionLength:0,minimumResultsForSearch:0,selectOnClose:!1,sorter:function(a){return a},templateResult:function(a){return a.text},templateSelection:function(a){return a.text},theme:"default",width:"resolve"}},D.prototype.set=function(b,c){var d=a.camelCase(b),e={};e[d]=c;var f=j._convertData(e);a.extend(!0,this.defaults,f)},new D}),b.define("select2/options",["require","jquery","./defaults","./utils"],function(a,b,c,d){function e(b,e){if(this.options=b,null!=e&&this.fromElement(e),this.options=c.apply(this.options),e&&e.is("input")){var f=a(this.get("amdBase")+"compat/inputData");this.options.dataAdapter=d.Decorate(this.options.dataAdapter,f)}}return e.prototype.fromElement=function(a){var c=["select2"];null==this.options.multiple&&(this.options.multiple=a.prop("multiple")),null==this.options.disabled&&(this.options.disabled=a.prop("disabled")),null==this.options.language&&(a.prop("lang")?this.options.language=a.prop("lang").toLowerCase():a.closest("[lang]").prop("lang")&&(this.options.language=a.closest("[lang]").prop("lang"))),null==this.options.dir&&(a.prop("dir")?this.options.dir=a.prop("dir"):a.closest("[dir]").prop("dir")?this.options.dir=a.closest("[dir]").prop("dir"):this.options.dir="ltr"),a.prop("disabled",this.options.disabled),a.prop("multiple",this.options.multiple),d.GetData(a[0],"select2Tags")&&(this.options.debug&&window.console&&console.warn&&console.warn('Select2: The `data-select2-tags` attribute has been changed to use the `data-data` and `data-tags="true"` attributes and will be removed in future versions of Select2.'),d.StoreData(a[0],"data",d.GetData(a[0],"select2Tags")),d.StoreData(a[0],"tags",!0)),d.GetData(a[0],"ajaxUrl")&&(this.options.debug&&window.console&&console.warn&&console.warn("Select2: The `data-ajax-url` attribute has been changed to `data-ajax--url` and support for the old attribute will be removed in future versions of Select2."),a.attr("ajax--url",d.GetData(a[0],"ajaxUrl")),d.StoreData(a[0],"ajax-Url",d.GetData(a[0],"ajaxUrl")));var e={};e=b.fn.jquery&&"1."==b.fn.jquery.substr(0,2)&&a[0].dataset?b.extend(!0,{},a[0].dataset,d.GetData(a[0])):d.GetData(a[0]);var f=b.extend(!0,{},e);f=d._convertData(f);for(var g in f)b.inArray(g,c)>-1||(b.isPlainObject(this.options[g])?b.extend(this.options[g],f[g]):this.options[g]=f[g]);return this},e.prototype.get=function(a){return this.options[a]},e.prototype.set=function(a,b){this.options[a]=b},e}),b.define("select2/core",["jquery","./options","./utils","./keys"],function(a,b,c,d){var e=function(a,d){null!=c.GetData(a[0],"select2")&&c.GetData(a[0],"select2").destroy(),this.$element=a,this.id=this._generateId(a),d=d||{},this.options=new b(d,a),e.__super__.constructor.call(this);var f=a.attr("tabindex")||0;c.StoreData(a[0],"old-tabindex",f),a.attr("tabindex","-1");var g=this.options.get("dataAdapter");this.dataAdapter=new g(a,this.options);var h=this.render();this._placeContainer(h);var i=this.options.get("selectionAdapter");this.selection=new i(a,this.options),this.$selection=this.selection.render(),this.selection.position(this.$selection,h);var j=this.options.get("dropdownAdapter");this.dropdown=new j(a,this.options),this.$dropdown=this.dropdown.render(),this.dropdown.position(this.$dropdown,h);var k=this.options.get("resultsAdapter");this.results=new k(a,this.options,this.dataAdapter),this.$results=this.results.render(),this.results.position(this.$results,this.$dropdown);var l=this;this._bindAdapters(),this._registerDomEvents(),this._registerDataEvents(),this._registerSelectionEvents(),this._registerDropdownEvents(),this._registerResultsEvents(),this._registerEvents(),this.dataAdapter.current(function(a){l.trigger("selection:update",{data:a})}),a.addClass("select2-hidden-accessible"),a.attr("aria-hidden","true"),this._syncAttributes(),c.StoreData(a[0],"select2",this)};return c.Extend(e,c.Observable),e.prototype._generateId=function(a){var b="";return b=null!=a.attr("id")?a.attr("id"):null!=a.attr("name")?a.attr("name")+"-"+c.generateChars(2):c.generateChars(4),b=b.replace(/(:|\.|\[|\]|,)/g,""),b="select2-"+b},e.prototype._placeContainer=function(a){a.insertAfter(this.$element);var b=this._resolveWidth(this.$element,this.options.get("width"));null!=b&&a.css("width",b)},e.prototype._resolveWidth=function(a,b){var c=/^width:(([-+]?([0-9]*\.)?[0-9]+)(px|em|ex|%|in|cm|mm|pt|pc))/i;if("resolve"==b){var d=this._resolveWidth(a,"style");return null!=d?d:this._resolveWidth(a,"element")}if("element"==b){var e=a.outerWidth(!1);return e<=0?"auto":e+"px"}if("style"==b){var f=a.attr("style");if("string"!=typeof f)return null;for(var g=f.split(";"),h=0,i=g.length;h<i;h+=1){var j=g[h].replace(/\s/g,""),k=j.match(c);if(null!==k&&k.length>=1)return k[1]}return null}return b},e.prototype._bindAdapters=function(){this.dataAdapter.bind(this,this.$container),this.selection.bind(this,this.$container),this.dropdown.bind(this,this.$container),this.results.bind(this,this.$container)},e.prototype._registerDomEvents=function(){var b=this;this.$element.on("change.select2",function(){b.dataAdapter.current(function(a){b.trigger("selection:update",{data:a})})}),this.$element.on("focus.select2",function(a){b.trigger("focus",a)}),this._syncA=c.bind(this._syncAttributes,this),this._syncS=c.bind(this._syncSubtree,this),this.$element[0].attachEvent&&this.$element[0].attachEvent("onpropertychange",this._syncA);var d=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver;null!=d?(this._observer=new d(function(c){a.each(c,b._syncA),a.each(c,b._syncS)}),this._observer.observe(this.$element[0],{attributes:!0,childList:!0,subtree:!1})):this.$element[0].addEventListener&&(this.$element[0].addEventListener("DOMAttrModified",b._syncA,!1),this.$element[0].addEventListener("DOMNodeInserted",b._syncS,!1),this.$element[0].addEventListener("DOMNodeRemoved",b._syncS,!1))},e.prototype._registerDataEvents=function(){var a=this;this.dataAdapter.on("*",function(b,c){a.trigger(b,c)})},e.prototype._registerSelectionEvents=function(){var b=this,c=["toggle","focus"];this.selection.on("toggle",function(){b.toggleDropdown()}),this.selection.on("focus",function(a){b.focus(a)}),this.selection.on("*",function(d,e){-1===a.inArray(d,c)&&b.trigger(d,e)})},e.prototype._registerDropdownEvents=function(){var a=this;this.dropdown.on("*",function(b,c){a.trigger(b,c)})},e.prototype._registerResultsEvents=function(){var a=this;this.results.on("*",function(b,c){a.trigger(b,c)})},e.prototype._registerEvents=function(){var a=this;this.on("open",function(){a.$container.addClass("select2-container--open")}),this.on("close",function(){a.$container.removeClass("select2-container--open")}),this.on("enable",function(){a.$container.removeClass("select2-container--disabled")}),this.on("disable",function(){a.$container.addClass("select2-container--disabled")}),this.on("blur",function(){a.$container.removeClass("select2-container--focus")}),this.on("query",function(b){a.isOpen()||a.trigger("open",{}),this.dataAdapter.query(b,function(c){a.trigger("results:all",{data:c,query:b})})}),this.on("query:append",function(b){this.dataAdapter.query(b,function(c){a.trigger("results:append",{data:c,query:b})})}),this.on("keypress",function(b){var c=b.which;a.isOpen()?c===d.ESC||c===d.TAB||c===d.UP&&b.altKey?(a.close(),b.preventDefault()):c===d.ENTER?(a.trigger("results:select",{}),b.preventDefault()):c===d.SPACE&&b.ctrlKey?(a.trigger("results:toggle",{}),b.preventDefault()):c===d.UP?(a.trigger("results:previous",{}),b.preventDefault()):c===d.DOWN&&(a.trigger("results:next",{}),b.preventDefault()):(c===d.ENTER||c===d.SPACE||c===d.DOWN&&b.altKey)&&(a.open(),b.preventDefault())})},e.prototype._syncAttributes=function(){this.options.set("disabled",this.$element.prop("disabled")),this.options.get("disabled")?(this.isOpen()&&this.close(),this.trigger("disable",{})):this.trigger("enable",{})},e.prototype._syncSubtree=function(a,b){var c=!1,d=this;if(!a||!a.target||"OPTION"===a.target.nodeName||"OPTGROUP"===a.target.nodeName){if(b)if(b.addedNodes&&b.addedNodes.length>0)for(var e=0;e<b.addedNodes.length;e++){var f=b.addedNodes[e];f.selected&&(c=!0)}else b.removedNodes&&b.removedNodes.length>0&&(c=!0);else c=!0;c&&this.dataAdapter.current(function(a){d.trigger("selection:update",{data:a})})}},e.prototype.trigger=function(a,b){var c=e.__super__.trigger,d={open:"opening",close:"closing",select:"selecting",unselect:"unselecting",clear:"clearing"};if(void 0===b&&(b={}),a in d){var f=d[a],g={prevented:!1,name:a,args:b};if(c.call(this,f,g),g.prevented)return void(b.prevented=!0)}c.call(this,a,b)},e.prototype.toggleDropdown=function(){this.options.get("disabled")||(this.isOpen()?this.close():this.open())},e.prototype.open=function(){this.isOpen()||this.trigger("query",{})},e.prototype.close=function(){this.isOpen()&&this.trigger("close",{})},e.prototype.isOpen=function(){return this.$container.hasClass("select2-container--open")},e.prototype.hasFocus=function(){return this.$container.hasClass("select2-container--focus")},e.prototype.focus=function(a){this.hasFocus()||(this.$container.addClass("select2-container--focus"),this.trigger("focus",{}))},e.prototype.enable=function(a){this.options.get("debug")&&window.console&&console.warn&&console.warn('Select2: The `select2("enable")` method has been deprecated and will be removed in later Select2 versions. Use $element.prop("disabled") instead.'),null!=a&&0!==a.length||(a=[!0]);var b=!a[0];this.$element.prop("disabled",b)},e.prototype.data=function(){this.options.get("debug")&&arguments.length>0&&window.console&&console.warn&&console.warn('Select2: Data can no longer be set using `select2("data")`. You should consider setting the value instead using `$element.val()`.');var a=[];return this.dataAdapter.current(function(b){a=b}),a},e.prototype.val=function(b){if(this.options.get("debug")&&window.console&&console.warn&&console.warn('Select2: The `select2("val")` method has been deprecated and will be removed in later Select2 versions. Use $element.val() instead.'),null==b||0===b.length)return this.$element.val();var c=b[0];a.isArray(c)&&(c=a.map(c,function(a){return a.toString()})),this.$element.val(c).trigger("change")},e.prototype.destroy=function(){this.$container.remove(),this.$element[0].detachEvent&&this.$element[0].detachEvent("onpropertychange",this._syncA),null!=this._observer?(this._observer.disconnect(),this._observer=null):this.$element[0].removeEventListener&&(this.$element[0].removeEventListener("DOMAttrModified",this._syncA,!1),this.$element[0].removeEventListener("DOMNodeInserted",this._syncS,!1),this.$element[0].removeEventListener("DOMNodeRemoved",this._syncS,!1)),this._syncA=null,this._syncS=null,this.$element.off(".select2"),this.$element.attr("tabindex",c.GetData(this.$element[0],"old-tabindex")),this.$element.removeClass("select2-hidden-accessible"),this.$element.attr("aria-hidden","false"),c.RemoveData(this.$element[0]),this.dataAdapter.destroy(),this.selection.destroy(),this.dropdown.destroy(),this.results.destroy(),this.dataAdapter=null,this.selection=null,this.dropdown=null,this.results=null},e.prototype.render=function(){var b=a('<span class="select2 select2-container"><span class="selection"></span><span class="dropdown-wrapper" aria-hidden="true"></span></span>');return b.attr("dir",this.options.get("dir")),this.$container=b,this.$container.addClass("select2-container--"+this.options.get("theme")),c.StoreData(b[0],"element",this.$element),b},e}),b.define("jquery-mousewheel",["jquery"],function(a){return a}),b.define("jquery.select2",["jquery","jquery-mousewheel","./select2/core","./select2/defaults","./select2/utils"],function(a,b,c,d,e){if(null==a.fn.select2){var f=["open","close","destroy"];a.fn.select2=function(b){if("object"==typeof(b=b||{}))return this.each(function(){var d=a.extend(!0,{},b);new c(a(this),d)}),this;if("string"==typeof b){var d,g=Array.prototype.slice.call(arguments,1);return this.each(function(){var a=e.GetData(this,"select2");null==a&&window.console&&console.error&&console.error("The select2('"+b+"') method was called on an element that is not using Select2."),d=a[b].apply(a,g)}),a.inArray(b,f)>-1?this:d}throw new Error("Invalid arguments for Select2: "+b)}}return null==a.fn.select2.defaults&&(a.fn.select2.defaults=d),c}),{define:b.define,require:b.require}}(),c=b.require("jquery.select2");return a.fn.select2.amd=b,c});
|
admin/js/tiptip.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
!function(t){t.fn.tipTip=function(e){var o={activation:"hover",keepAlive:!1,maxWidth:"200px",edgeOffset:3,defaultPosition:"bottom",delay:400,fadeIn:200,fadeOut:200,attribute:"title",content:!1,enter:function(){},exit:function(){}},i=t.extend(o,e);if(t("#tiptip_holder").length<=0){var n=t('<div id="tiptip_holder" style="max-width:'+i.maxWidth+';"></div>'),r=t('<div id="tiptip_content"></div>'),a=t('<div id="tiptip_arrow"></div>');t("body").append(n.html(r).prepend(a.html('<div id="tiptip_arrow_inner"></div>')))}else var n=t("#tiptip_holder"),r=t("#tiptip_content"),a=t("#tiptip_arrow");return this.each(function(){function e(){i.enter.call(this),r.html(d),n.hide().removeAttr("class").css("margin","0"),a.removeAttr("style");var e=parseInt(f.offset().top),o=parseInt(f.offset().left),p=parseInt(f.outerWidth()),l=parseInt(f.outerHeight()),h=n.outerWidth(),c=n.outerHeight(),s=Math.round((p-h)/2),_=Math.round((l-c)/2),v=Math.round(o+s),m=Math.round(e+l+i.edgeOffset),g="",b="",M=Math.round(h-12)/2;"bottom"==i.defaultPosition?g="_bottom":"top"==i.defaultPosition?g="_top":"left"==i.defaultPosition?g="_left":"right"==i.defaultPosition&&(g="_right");var w=s+o<parseInt(t(window).scrollLeft()),O=h+o>parseInt(t(window).width());w&&s<0||"_right"==g&&!O||"_left"==g&&o<h+i.edgeOffset+5?(g="_right",b=Math.round(c-13)/2,M=-12,v=Math.round(o+p+i.edgeOffset),m=Math.round(e+_)):(O&&s<0||"_left"==g&&!w)&&(g="_left",b=Math.round(c-13)/2,M=Math.round(h),v=Math.round(o-(h+i.edgeOffset+5)),m=Math.round(e+_));var x=e+l+i.edgeOffset+c+8>parseInt(t(window).height()+t(window).scrollTop()),I=e+l-(i.edgeOffset+c+8)<0;x||"_bottom"==g&&x||"_top"==g&&!I?("_top"==g||"_bottom"==g?g="_top":g+="_top",b=c,m=Math.round(e-(c+5+i.edgeOffset))):(I|("_top"==g&&I)||"_bottom"==g&&!x)&&("_top"==g||"_bottom"==g?g="_bottom":g+="_bottom",b=-12,m=Math.round(e+l+i.edgeOffset)),"_right_top"==g||"_left_top"==g?m+=5:"_right_bottom"!=g&&"_left_bottom"!=g||(m-=5),"_left_top"!=g&&"_left_bottom"!=g||(v+=5),a.css({"margin-left":M+"px","margin-top":b+"px"}),n.css({"margin-left":v+"px","margin-top":m+"px"}).attr("class","tip"+g),u&&clearTimeout(u),u=setTimeout(function(){n.stop(!0,!0).fadeIn(i.fadeIn)},i.delay)}function o(){i.exit.call(this),u&&clearTimeout(u),n.fadeOut(i.fadeOut)}var f=t(this);if(i.content)d=i.content;else var d=f.attr(i.attribute);if(""!=d){i.content||f.removeAttr(i.attribute);var u=!1;"hover"==i.activation?(f.hover(function(){e()},function(){i.keepAlive||o()}),i.keepAlive&&n.hover(function(){},function(){o()})):"focus"==i.activation?f.focus(function(){e()}).blur(function(){o()}):"click"==i.activation&&(f.click(function(){return e(),!1}).hover(function(){},function(){i.keepAlive||o()}),i.keepAlive&&n.hover(function(){},function(){o()}))}})}}(jQuery);
|
admin/js/wt-import-export-for-woo-admin.js
ADDED
@@ -0,0 +1,724 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
(function( $ ) {
|
2 |
+
'use strict';
|
3 |
+
|
4 |
+
$(function() {
|
5 |
+
|
6 |
+
$(".wt-iew-tips").tipTip({'attribute': 'data-wt-iew-tip'});
|
7 |
+
|
8 |
+
|
9 |
+
/* tab view */
|
10 |
+
var wf_tab_view=
|
11 |
+
{
|
12 |
+
Set:function(prnt_selector)
|
13 |
+
{
|
14 |
+
var wf_prnt_obj=$(prnt_selector);
|
15 |
+
var wf_nav_tab=wf_prnt_obj.find('.wt-iew-tab-head .nav-tab');
|
16 |
+
if(wf_nav_tab.length>0)
|
17 |
+
{
|
18 |
+
wf_nav_tab.click(function(){
|
19 |
+
var wf_tab_hash=$(this).attr('href');
|
20 |
+
wf_nav_tab.removeClass('nav-tab-active');
|
21 |
+
$(this).addClass('nav-tab-active');
|
22 |
+
wf_tab_hash=wf_tab_hash.charAt(0)=='#' ? wf_tab_hash.substring(1) : wf_tab_hash;
|
23 |
+
var wf_tab_elm=$('div[data-id="'+wf_tab_hash+'"]');
|
24 |
+
wf_prnt_obj.find('.wt-iew-tab-content').hide();
|
25 |
+
if(wf_tab_elm.length>0 && wf_tab_elm.is(':hidden'))
|
26 |
+
{
|
27 |
+
wf_tab_elm.fadeIn();
|
28 |
+
}
|
29 |
+
});
|
30 |
+
$(window).on('hashchange', function (e) {
|
31 |
+
var location_hash=window.location.hash;
|
32 |
+
if(location_hash!="")
|
33 |
+
{
|
34 |
+
wf_tab_view.showTab(location_hash);
|
35 |
+
}
|
36 |
+
}).trigger('hashchange');
|
37 |
+
|
38 |
+
var location_hash=window.location.hash;
|
39 |
+
if(location_hash!="")
|
40 |
+
{
|
41 |
+
wf_tab_view.showTab(location_hash);
|
42 |
+
}else
|
43 |
+
{
|
44 |
+
wf_nav_tab.eq(0).click();
|
45 |
+
}
|
46 |
+
}
|
47 |
+
this.subTab(wf_prnt_obj);
|
48 |
+
},
|
49 |
+
showTab:function(location_hash)
|
50 |
+
{
|
51 |
+
var wf_tab_hash=location_hash.charAt(0)=='#' ? location_hash.substring(1) : location_hash;
|
52 |
+
if(wf_tab_hash!="")
|
53 |
+
{
|
54 |
+
var wf_tab_elm=$('div[data-id="'+wf_tab_hash+'"]');
|
55 |
+
if(wf_tab_elm.length>0 && wf_tab_elm.is(':hidden'))
|
56 |
+
{
|
57 |
+
$('a[href="#'+wf_tab_hash+'"]').click();
|
58 |
+
}
|
59 |
+
}
|
60 |
+
},
|
61 |
+
subTab:function(wf_prnt_obj)
|
62 |
+
{
|
63 |
+
wf_prnt_obj.find('.wt_iew_sub_tab li').click(function(){
|
64 |
+
var trgt=$(this).attr('data-target');
|
65 |
+
var prnt=$(this).parent('.wt_iew_sub_tab');
|
66 |
+
var ctnr=prnt.siblings('.wt_iew_sub_tab_container');
|
67 |
+
prnt.find('li a').css({'color':'#0073aa','cursor':'pointer'});
|
68 |
+
$(this).find('a').css({'color':'#000','cursor':'default'});
|
69 |
+
ctnr.find('.wt_iew_sub_tab_content').hide();
|
70 |
+
ctnr.find('.wt_iew_sub_tab_content[data-id="'+trgt+'"]').fadeIn();
|
71 |
+
});
|
72 |
+
wf_prnt_obj.find('.wt_iew_sub_tab').each(function(){
|
73 |
+
var elm=$(this).children('li').eq(0);
|
74 |
+
elm.click();
|
75 |
+
});
|
76 |
+
}
|
77 |
+
}
|
78 |
+
wf_tab_view.Set('#'+wt_iew_basic_params.plugin_id); /* set plugin main div as parent object to avoid conflict with other WT plugins */
|
79 |
+
/* tab view */
|
80 |
+
|
81 |
+
});
|
82 |
+
|
83 |
+
})( jQuery );
|
84 |
+
|
85 |
+
var wt_iew_settings_form_basic=
|
86 |
+
{
|
87 |
+
Set:function(prnt_selector)
|
88 |
+
{
|
89 |
+
var wf_prnt_obj=jQuery(prnt_selector);
|
90 |
+
wf_prnt_obj.find('.wt_iew_settings_form_basic').submit(function(e){
|
91 |
+
e.preventDefault();
|
92 |
+
var data=jQuery(this).serialize();
|
93 |
+
|
94 |
+
var submit_btn=jQuery(this).find('input[type="submit"]');
|
95 |
+
var spinner=submit_btn.siblings('.spinner');
|
96 |
+
spinner.css({'visibility':'visible'});
|
97 |
+
submit_btn.css({'opacity':'.5','cursor':'default'}).prop('disabled',true);
|
98 |
+
|
99 |
+
jQuery.ajax({
|
100 |
+
url:wt_iew_basic_params.ajax_url,
|
101 |
+
type:'POST',
|
102 |
+
dataType:'json',
|
103 |
+
data:data+'&action=wt_iew_save_settings_basic',
|
104 |
+
success:function(data)
|
105 |
+
{
|
106 |
+
spinner.css({'visibility':'hidden'});
|
107 |
+
submit_btn.css({'opacity':'1','cursor':'pointer'}).prop('disabled',false);
|
108 |
+
if(data.status==true)
|
109 |
+
{
|
110 |
+
wt_iew_notify_msg.success(data.msg);
|
111 |
+
}else
|
112 |
+
{
|
113 |
+
wt_iew_notify_msg.error(data.msg);
|
114 |
+
}
|
115 |
+
},
|
116 |
+
error:function ()
|
117 |
+
{
|
118 |
+
spinner.css({'visibility':'hidden'});
|
119 |
+
submit_btn.css({'opacity':'1','cursor':'pointer'}).prop('disabled',false);
|
120 |
+
wt_iew_notify_msg.error(wt_iew_basic_params.msgs.settings_error);
|
121 |
+
}
|
122 |
+
});
|
123 |
+
});
|
124 |
+
}
|
125 |
+
}
|
126 |
+
var wt_drp_menu=
|
127 |
+
{
|
128 |
+
Set:function()
|
129 |
+
{
|
130 |
+
jQuery(document).on('click', '.wt_iew_drp_menu', function(){
|
131 |
+
var trgt=jQuery(this).attr('data-target');
|
132 |
+
var drp_menu=jQuery('.wt_iew_dropdown[data-id="'+trgt+'"]');
|
133 |
+
if(drp_menu.is(':visible'))
|
134 |
+
{
|
135 |
+
drp_menu.hide();
|
136 |
+
}else
|
137 |
+
{
|
138 |
+
var pos=jQuery(this).position();
|
139 |
+
var t=pos.top+(jQuery(this).height()/2)+5;
|
140 |
+
var l=pos.left; //-drp_menu.outerWidth()+jQuery(this).outerWidth();
|
141 |
+
var w=jQuery(this).outerWidth();
|
142 |
+
drp_menu.css({'display':'block','left':l,'top':t,'opacity':0,'width':w}).stop(true, true).animate({'top':t+5, 'opacity':1});
|
143 |
+
}
|
144 |
+
});
|
145 |
+
|
146 |
+
jQuery(document).on('click', 'body, body *', function(e){
|
147 |
+
var drp_menu=jQuery('.wt_iew_dropdown');
|
148 |
+
if(drp_menu.is(':visible'))
|
149 |
+
{
|
150 |
+
if(jQuery(e.target).hasClass('wt_iew_dropdown')===false && jQuery(e.target).hasClass('wt_iew_drp_menu')===false && jQuery(e.target).hasClass('dashicons')===false)
|
151 |
+
{
|
152 |
+
drp_menu.hide();
|
153 |
+
}
|
154 |
+
}
|
155 |
+
});
|
156 |
+
}
|
157 |
+
}
|
158 |
+
|
159 |
+
var wt_iew_notify_msg=
|
160 |
+
{
|
161 |
+
error:function(message)
|
162 |
+
{
|
163 |
+
var er_elm=jQuery('<div class="wt_notify_msg" style="background:#f8d7da; border:solid 1px #f5c6cb; color: #721c24">'+message+'</div>');
|
164 |
+
this.setNotify(er_elm);
|
165 |
+
},
|
166 |
+
success:function(message)
|
167 |
+
{
|
168 |
+
var suss_elm=jQuery('<div class="wt_notify_msg" style="background:#d4edda; border:solid 1px #c3e6cb; color: #155724;">'+message+'</div>');
|
169 |
+
this.setNotify(suss_elm);
|
170 |
+
},
|
171 |
+
setNotify:function(elm)
|
172 |
+
{
|
173 |
+
jQuery('body').append(elm);
|
174 |
+
jQuery('.wt_notify_msg').click(function(){
|
175 |
+
jQuery(this).remove();
|
176 |
+
});
|
177 |
+
elm.stop(true,true).animate({'opacity':1,'top':'50px'},1000);
|
178 |
+
setTimeout(function(){
|
179 |
+
elm.animate({'opacity':0,'top':'100px'},1000,function(){
|
180 |
+
elm.remove();
|
181 |
+
});
|
182 |
+
},3000);
|
183 |
+
}
|
184 |
+
}
|
185 |
+
|
186 |
+
wt_iew_popup={
|
187 |
+
Set:function()
|
188 |
+
{
|
189 |
+
this.regPopupOpen();
|
190 |
+
this.regPopupClose();
|
191 |
+
jQuery('body').prepend('<div class="wt_iew_overlay"></div>');
|
192 |
+
},
|
193 |
+
regPopupOpen:function()
|
194 |
+
{
|
195 |
+
jQuery('[data-wt_iew_popup]').click(function(){
|
196 |
+
var elm_class=jQuery(this).attr('data-wt_iew_popup');
|
197 |
+
var elm=jQuery('.'+elm_class);
|
198 |
+
if(elm.length>0)
|
199 |
+
{
|
200 |
+
wt_iew_popup.showPopup(elm);
|
201 |
+
}
|
202 |
+
});
|
203 |
+
},
|
204 |
+
showPopup:function(popup_elm)
|
205 |
+
{
|
206 |
+
var pw=popup_elm.outerWidth();
|
207 |
+
var wh=jQuery(window).height();
|
208 |
+
var ph=wh-150;
|
209 |
+
popup_elm.css({'margin-left':((pw/2)*-1),'display':'block','top':'20px'}).animate({'top':'50px'});
|
210 |
+
popup_elm.find('.wt_iew_popup_body').css({'max-height':ph+'px','overflow':'auto'});
|
211 |
+
jQuery('.wt_iew_overlay').show();
|
212 |
+
},
|
213 |
+
hidePopup:function()
|
214 |
+
{
|
215 |
+
jQuery('.wt_iew_popup_close').click();
|
216 |
+
},
|
217 |
+
regPopupClose:function(popup_elm)
|
218 |
+
{
|
219 |
+
jQuery(document).keyup(function(e){
|
220 |
+
if(e.keyCode==27)
|
221 |
+
{
|
222 |
+
wt_iew_popup.hidePopup();
|
223 |
+
}
|
224 |
+
});
|
225 |
+
jQuery('.wt_iew_popup_close, .wt_iew_popup_cancel').unbind('click').click(function(){
|
226 |
+
jQuery('.wt_iew_overlay, .wt_iew_popup').hide();
|
227 |
+
});
|
228 |
+
}
|
229 |
+
}
|
230 |
+
|
231 |
+
var wt_field_group=
|
232 |
+
{
|
233 |
+
Set:function()
|
234 |
+
{
|
235 |
+
//jQuery('.wt_iew_field_group_children').hide();
|
236 |
+
jQuery('.wt_iew_field_group_hd .wt_iew_field_group_toggle_btn').each(function(){
|
237 |
+
var group_id = jQuery(this).attr('data-id');
|
238 |
+
var group_content_dv = jQuery(this).parents('tr').find('.wt_iew_field_group_content');
|
239 |
+
var visibility = jQuery(this).attr('data-visibility');
|
240 |
+
jQuery('.wt_iew_field_group_children[data-field-group="'+group_id+'"]').appendTo(group_content_dv.find('table'));
|
241 |
+
if(visibility==1)
|
242 |
+
{
|
243 |
+
group_content_dv.show();
|
244 |
+
}
|
245 |
+
});
|
246 |
+
jQuery('.wt_iew_field_group_hd').click(function(){
|
247 |
+
|
248 |
+
var toggle_btn=jQuery(this).find('.wt_iew_field_group_toggle_btn');
|
249 |
+
var visibility=toggle_btn.attr('data-visibility');
|
250 |
+
var group_content_dv=toggle_btn.parents('tr').find('.wt_iew_field_group_content');
|
251 |
+
if(visibility==1)
|
252 |
+
{
|
253 |
+
toggle_btn.attr('data-visibility',0);
|
254 |
+
toggle_btn.find('.dashicons').removeClass('dashicons-arrow-down').addClass('dashicons-arrow-right');
|
255 |
+
group_content_dv.hide();
|
256 |
+
}else
|
257 |
+
{
|
258 |
+
toggle_btn.attr('data-visibility',1);
|
259 |
+
toggle_btn.find('.dashicons').removeClass('dashicons-arrow-right').addClass('dashicons-arrow-down');
|
260 |
+
group_content_dv.show();
|
261 |
+
}
|
262 |
+
});
|
263 |
+
}
|
264 |
+
}
|
265 |
+
var wt_iew_form_toggler=
|
266 |
+
{
|
267 |
+
Set:function()
|
268 |
+
{
|
269 |
+
this.runToggler();
|
270 |
+
jQuery('select.wt_iew_form_toggler').change(function(){
|
271 |
+
wt_iew_form_toggler.toggle(jQuery(this));
|
272 |
+
});
|
273 |
+
jQuery('input[type="radio"].wt_iew_form_toggler').click(function(){
|
274 |
+
if(jQuery(this).is(':checked'))
|
275 |
+
{
|
276 |
+
wt_iew_form_toggler.toggle(jQuery(this));
|
277 |
+
}
|
278 |
+
});
|
279 |
+
jQuery('input[type="checkbox"].wt_iew_form_toggler').click(function(){
|
280 |
+
wt_iew_form_toggler.toggle(jQuery(this),1);
|
281 |
+
});
|
282 |
+
},
|
283 |
+
runToggler:function(prnt)
|
284 |
+
{
|
285 |
+
prnt=prnt ? prnt : jQuery('body');
|
286 |
+
prnt.find('select.wt_iew_form_toggler').each(function(){
|
287 |
+
wt_iew_form_toggler.toggle(jQuery(this));
|
288 |
+
});
|
289 |
+
prnt.find('input[type="radio"].wt_iew_form_toggler, input[type="checkbox"].wt_iew_form_toggler').each(function(){
|
290 |
+
if(jQuery(this).is(':checked'))
|
291 |
+
{
|
292 |
+
wt_iew_form_toggler.toggle(jQuery(this));
|
293 |
+
}
|
294 |
+
});
|
295 |
+
prnt.find('input[type="checkbox"].wt_iew_form_toggler').each(function(){
|
296 |
+
wt_iew_form_toggler.toggle(jQuery(this),1);
|
297 |
+
});
|
298 |
+
},
|
299 |
+
toggle:function(elm, checkbox)
|
300 |
+
{
|
301 |
+
var vl=elm.val();
|
302 |
+
var trgt=elm.attr('wf_frm_tgl-target');
|
303 |
+
jQuery('[wf_frm_tgl-id="'+trgt+'"]').hide();
|
304 |
+
if(!elm.is(':visible'))
|
305 |
+
{
|
306 |
+
return false;
|
307 |
+
}
|
308 |
+
if(elm.css('display')!='none') /* if parent is visible. `:visible` method. it will not work on JS tabview */
|
309 |
+
{
|
310 |
+
var elms=this.getElms(elm,trgt,vl,checkbox);
|
311 |
+
elms.show().find('th label').css({'margin-left':'0px'})
|
312 |
+
elms.each(function(){
|
313 |
+
var lvl=jQuery(this).attr('wf_frm_tgl-lvl');
|
314 |
+
var mrgin=25;
|
315 |
+
if (typeof lvl!== typeof undefined && lvl!== false) {
|
316 |
+
mrgin=lvl*mrgin;
|
317 |
+
}
|
318 |
+
jQuery(this).find('th label').animate({'margin-left':mrgin+'px'},1000);
|
319 |
+
});
|
320 |
+
}
|
321 |
+
|
322 |
+
/* in case of greater than 1 level */
|
323 |
+
jQuery('[wf_frm_tgl-id="'+trgt+'"]').each(function(){
|
324 |
+
wt_iew_form_toggler.runToggler(jQuery(this));
|
325 |
+
});
|
326 |
+
},
|
327 |
+
getElms:function(elm,trgt,vl,checkbox)
|
328 |
+
{
|
329 |
+
|
330 |
+
return jQuery('[wf_frm_tgl-id="'+trgt+'"]').filter(function(){
|
331 |
+
if(jQuery(this).attr('wf_frm_tgl-val')==vl)
|
332 |
+
{
|
333 |
+
if(checkbox)
|
334 |
+
{
|
335 |
+
if(elm.is(':checked'))
|
336 |
+
{
|
337 |
+
if(jQuery(this).attr('wf_frm_tgl-chk')=='true')
|
338 |
+
{
|
339 |
+
return true;
|
340 |
+
}else
|
341 |
+
{
|
342 |
+
return false;
|
343 |
+
}
|
344 |
+
}else
|
345 |
+
{
|
346 |
+
if(jQuery(this).attr('wf_frm_tgl-chk')=='false')
|
347 |
+
{
|
348 |
+
return true;
|
349 |
+
}else
|
350 |
+
{
|
351 |
+
return false;
|
352 |
+
}
|
353 |
+
}
|
354 |
+
}else
|
355 |
+
{
|
356 |
+
return true;
|
357 |
+
}
|
358 |
+
}else
|
359 |
+
{
|
360 |
+
return false;
|
361 |
+
}
|
362 |
+
});
|
363 |
+
}
|
364 |
+
}
|
365 |
+
|
366 |
+
var wt_iew_file_attacher={
|
367 |
+
|
368 |
+
Set:function()
|
369 |
+
{
|
370 |
+
var file_frame;
|
371 |
+
jQuery(".wt_iew_file_attacher").click(function(event){
|
372 |
+
event.preventDefault();
|
373 |
+
if(jQuery(this).data('file_frame'))
|
374 |
+
{
|
375 |
+
|
376 |
+
}else
|
377 |
+
{
|
378 |
+
/* reset user preference. This will open file uploader by default. */
|
379 |
+
wp.media.controller.Library.prototype.defaults.contentUserSetting=false;
|
380 |
+
|
381 |
+
|
382 |
+
/* Create the media frame. */
|
383 |
+
var file_frame = wp.media.frames.file_frame = wp.media({
|
384 |
+
title: jQuery( this ).data( 'invoice_uploader_title' ),
|
385 |
+
button: {
|
386 |
+
text: jQuery( this ).data( 'invoice_uploader_button_text' ),
|
387 |
+
},
|
388 |
+
/* Set to true to allow multiple files to be selected */
|
389 |
+
multiple: false
|
390 |
+
});
|
391 |
+
jQuery(this).data('file_frame',file_frame);
|
392 |
+
var wf_file_target=jQuery(this).attr('wt_iew_file_attacher_target');
|
393 |
+
var wt_file_attacher_choosed=jQuery(this).parent('.wt_iew_file_attacher_dv').find('.wt_iew_file_attacher_choosed');
|
394 |
+
var elm=jQuery(this);
|
395 |
+
|
396 |
+
/* When an image is selected, run a callback. */
|
397 |
+
jQuery(this).data('file_frame').on( 'select', function() {
|
398 |
+
/* We set multiple to false so only get one image from the uploader */
|
399 |
+
var attachment =file_frame.state().get('selection').first().toJSON();
|
400 |
+
/* Send the value of attachment.url back to shipment label printing settings form */
|
401 |
+
jQuery(wf_file_target).val(attachment.url);
|
402 |
+
if(wt_file_attacher_choosed.length>0)
|
403 |
+
{
|
404 |
+
wt_file_attacher_choosed.css({'visibility':'visible'}).html(attachment.filename);
|
405 |
+
}
|
406 |
+
});
|
407 |
+
/* Finally, open the modal */
|
408 |
+
}
|
409 |
+
jQuery(this).data('file_frame').open();
|
410 |
+
});
|
411 |
+
function wf_update_file_choosed(wf_file_target, wt_file_attacher_choosed)
|
412 |
+
{
|
413 |
+
if(jQuery(wf_file_target).val()=="")
|
414 |
+
{
|
415 |
+
wt_file_attacher_choosed.css({'visibility':'hidden'});
|
416 |
+
}else
|
417 |
+
{
|
418 |
+
wt_file_attacher_choosed.css({'visibility':'visible'});
|
419 |
+
}
|
420 |
+
}
|
421 |
+
jQuery(".wt_iew_file_attacher").each(function(){
|
422 |
+
var wf_file_target=jQuery(this).attr('wt_iew_file_attacher_target');
|
423 |
+
var wt_file_attacher_choosed=jQuery(this).parent('.wt_iew_file_attacher_dv').find('.wt_iew_file_attacher_choosed');
|
424 |
+
if(wt_file_attacher_choosed.length>0)
|
425 |
+
{
|
426 |
+
wf_update_file_choosed(wf_file_target, wt_file_attacher_choosed);
|
427 |
+
jQuery(wf_file_target).change(function(){
|
428 |
+
wf_update_file_choosed(wf_file_target, wt_file_attacher_choosed);
|
429 |
+
});
|
430 |
+
}
|
431 |
+
});
|
432 |
+
}
|
433 |
+
}
|
434 |
+
|
435 |
+
var wt_iew_popover=
|
436 |
+
{
|
437 |
+
action_module:false,
|
438 |
+
Set:function()
|
439 |
+
{
|
440 |
+
jQuery('[data-wt_iew_popover="1"]').unbind('click').click(function(){
|
441 |
+
|
442 |
+
/* check popover is visible now */
|
443 |
+
if(jQuery('.wt_iew_popover').length>0 && jQuery('.wt_iew_popover').is(':visible'))
|
444 |
+
{
|
445 |
+
wt_iew_popover.remove_active_row();
|
446 |
+
}
|
447 |
+
|
448 |
+
var cr_elm=jQuery(this);
|
449 |
+
if(cr_elm.attr('data-popup-opened')==1)
|
450 |
+
{
|
451 |
+
jQuery('[data-wt_iew_popover="1"]').attr('data-popup-opened',0);
|
452 |
+
wt_iew_popover.closePop();
|
453 |
+
return false;
|
454 |
+
}else
|
455 |
+
{
|
456 |
+
jQuery('[data-wt_iew_popover="1"]').attr('data-popup-opened',0);
|
457 |
+
cr_elm.attr('data-popup-opened',1);
|
458 |
+
}
|
459 |
+
if(jQuery('.wt_iew_popover').length==0)
|
460 |
+
{
|
461 |
+
var template='<div class="wt_iew_popover"><h3 class="wt_iew_popover-title">'
|
462 |
+
+'<span class="wt_iew_popover-title-text"></span><span class="popover_close_icon_button popover_close">X</span></h3>'
|
463 |
+
+'<div class="wt_iew_popover-content"></div><div class="wt_iew_popover-footer">'
|
464 |
+
+'<button name="wt_iew_popover_do_action" type="button" class="button button-primary">'+wt_iew_basic_params.msgs.use_expression+'</button>'
|
465 |
+
+'<button name="popover_close" type="button" class="button button-secondary popover_close">'+wt_iew_basic_params.msgs.cancel+'</button>'
|
466 |
+
+'<span class="spinner" style="margin-top:5px"></span>'
|
467 |
+
+'</div></div>';
|
468 |
+
jQuery('body').append(template);
|
469 |
+
wt_iew_popover.regclosePop();
|
470 |
+
}
|
471 |
+
|
472 |
+
var ttle=jQuery.trim(cr_elm.attr('data-title'));
|
473 |
+
var pp_elm=jQuery('.wt_iew_popover');
|
474 |
+
var pp_html='';
|
475 |
+
var pp_html_cntr=cr_elm.attr('data-content-container');
|
476 |
+
if(typeof pp_html_cntr!==typeof undefined && pp_html_cntr!==false)
|
477 |
+
{
|
478 |
+
pp_html=jQuery(pp_html_cntr).html();
|
479 |
+
ttle=(ttle=="" ? jQuery(pp_html_cntr).attr('data-title') : ttle);
|
480 |
+
wt_iew_popover.action_module=jQuery(pp_html_cntr).attr('data-module');
|
481 |
+
}else
|
482 |
+
{
|
483 |
+
pp_html=cr_elm.attr('data-content');
|
484 |
+
}
|
485 |
+
pp_elm.css({'display':'block'}).find('.wt_iew_popover-content').html(pp_html);
|
486 |
+
pp_elm.find('.wt_iew_popover-footer').show();
|
487 |
+
var cr_elm_w=cr_elm.width();
|
488 |
+
var cr_elm_h=cr_elm.height();
|
489 |
+
var pp_elm_w=pp_elm.width();
|
490 |
+
var pp_elm_h=pp_elm.height();
|
491 |
+
var cr_elm_pos=cr_elm.offset();
|
492 |
+
var cr_elm_pos_t=cr_elm_pos.top-((pp_elm_h-cr_elm_h)/4);
|
493 |
+
var cr_elm_pos_l=cr_elm_pos.left+cr_elm_w;
|
494 |
+
|
495 |
+
cr_elm_pos_t=cr_elm_pos_t+10; /* 10 px buffer for input span element padding */
|
496 |
+
|
497 |
+
pp_elm.find('.wt_iew_popover-title-text').html(ttle);
|
498 |
+
var target_elm_label=cr_elm.parents('tr').find('.wt_iew_mapping_column_label').html();
|
499 |
+
jQuery('.wt_iew_target_column').html(target_elm_label);
|
500 |
+
jQuery('.wt_iew_popover-content').find('.wt_iew_mapping_field_editor_expression').val(cr_elm.siblings('.columns_val').val());
|
501 |
+
|
502 |
+
wt_iew_popover.set_active_row(cr_elm);
|
503 |
+
pp_elm.css({'display':'block','opacity':0, 'top':cr_elm_pos_t,'left':cr_elm_pos_l}).stop(true,true).animate({'left':cr_elm_pos_l+20,'opacity':1}, 500, function(){
|
504 |
+
jQuery('.wt_iew_mapping_field_editor_expression').focus();
|
505 |
+
});
|
506 |
+
|
507 |
+
jQuery('[name="wt_iew_popover_do_action"]').data('click-elm', cr_elm);
|
508 |
+
wt_iew_popover.do_action();
|
509 |
+
if(wt_iew_popover.action_module=='import')
|
510 |
+
{
|
511 |
+
wt_iew_basic_import.mapping_field_editor();
|
512 |
+
wt_iew_basic_import.mapping_field_editor_output_preview();
|
513 |
+
}
|
514 |
+
|
515 |
+
});
|
516 |
+
},
|
517 |
+
do_action:function()
|
518 |
+
{
|
519 |
+
jQuery('[name="wt_iew_popover_do_action"]').unbind('click').click(function(){
|
520 |
+
var click_elm=jQuery(this).data('click-elm');
|
521 |
+
var vl=jQuery.trim(jQuery('.wt_iew_popover-content').find('.wt_iew_mapping_field_editor_expression').val());
|
522 |
+
|
523 |
+
var html_vl=vl;
|
524 |
+
if(wt_iew_popover.action_module=='import')
|
525 |
+
{
|
526 |
+
var html_vl=wt_iew_basic_import.mapping_field_editor_validate_column_val(vl);
|
527 |
+
}
|
528 |
+
click_elm.html(html_vl);
|
529 |
+
click_elm.siblings('.columns_val').val(vl);
|
530 |
+
wt_iew_popover.closePop();
|
531 |
+
|
532 |
+
if(wt_iew_popover.action_module=='import')
|
533 |
+
{
|
534 |
+
if(vl=="")
|
535 |
+
{
|
536 |
+
click_elm.parents('tr').find('.wt_iew_mapping_checkbox_sub').prop('checked', false);
|
537 |
+
}else
|
538 |
+
{
|
539 |
+
click_elm.parents('tr').find('.wt_iew_mapping_checkbox_sub').prop('checked', true);
|
540 |
+
}
|
541 |
+
wt_iew_basic_import.mapping_fields_selected_count(click_elm.parents('table'));
|
542 |
+
}
|
543 |
+
});
|
544 |
+
},
|
545 |
+
regclosePop:function()
|
546 |
+
{
|
547 |
+
jQuery('.meta_mapping_box_toggle').click(function(){
|
548 |
+
wt_iew_popover.closePop();
|
549 |
+
});
|
550 |
+
jQuery('.popover_close').unbind('click').click(function(){
|
551 |
+
wt_iew_popover.closePop();
|
552 |
+
});
|
553 |
+
},
|
554 |
+
set_active_row:function(cr_elm)
|
555 |
+
{
|
556 |
+
cr_elm.parents('tr').find('td').css({'background':'#f6f6f6'});
|
557 |
+
},
|
558 |
+
remove_active_row:function()
|
559 |
+
{
|
560 |
+
var click_elm=jQuery('[name="wt_iew_popover_do_action"]').data('click-elm');
|
561 |
+
click_elm.parents('tr').find('td').css({'background':'#fff'});
|
562 |
+
},
|
563 |
+
closePop:function()
|
564 |
+
{
|
565 |
+
var pp_elm=jQuery('.wt_iew_popover');
|
566 |
+
if(pp_elm.length>0)
|
567 |
+
{
|
568 |
+
var pp_lft=pp_elm.offset().left-50;
|
569 |
+
jQuery('[data-wt_iew_popover="1"]').attr('data-popup-opened',0);
|
570 |
+
pp_elm.stop(true,true).animate({'opacity':0, 'left':pp_lft},300,function(){
|
571 |
+
jQuery(this).css({'display':'none'});
|
572 |
+
});
|
573 |
+
this.remove_active_row();
|
574 |
+
}
|
575 |
+
}
|
576 |
+
};
|
577 |
+
|
578 |
+
var wt_iew_custom_and_preset=
|
579 |
+
{
|
580 |
+
toggler:function(preset_elm, custom_elm, custom_val) /* Toggle between custom and preset value */
|
581 |
+
{
|
582 |
+
this.do_toggle(preset_elm, custom_elm, custom_val);
|
583 |
+
preset_elm.unbind('change').change(function(){
|
584 |
+
wt_iew_custom_and_preset.do_toggle(preset_elm, custom_elm, custom_val);
|
585 |
+
});
|
586 |
+
},
|
587 |
+
do_toggle:function(preset_elm, custom_elm, custom_val)
|
588 |
+
{
|
589 |
+
if(preset_elm.val()==custom_val)
|
590 |
+
{
|
591 |
+
custom_elm.prop('readonly', false).css({'background':'#ffffff'}).focus().val('');
|
592 |
+
}else
|
593 |
+
{
|
594 |
+
custom_elm.prop('readonly', true).css({'background':'#efefef'}).val(preset_elm.find('option:selected').attr('data-val'));
|
595 |
+
}
|
596 |
+
},
|
597 |
+
delimiter_toggler:function() /* function for delimiter toggle */
|
598 |
+
{
|
599 |
+
this.toggler(jQuery('.wt_iew_delimiter_preset'), jQuery('.wt_iew_custom_delimiter'), 'other');
|
600 |
+
},
|
601 |
+
date_format_toggler:function() /* function for date format toggle */
|
602 |
+
{
|
603 |
+
this.toggler(jQuery('.wt_iew_date_format_preset'), jQuery('.wt_iew_custom_date_format'), 'other');
|
604 |
+
}
|
605 |
+
}
|
606 |
+
var wt_iew_conditional_help_text=
|
607 |
+
{
|
608 |
+
Set:function(prnt)
|
609 |
+
{
|
610 |
+
prnt=prnt ? prnt : jQuery('body');
|
611 |
+
const regex = /\[(.*?)\]/gm;
|
612 |
+
let m;
|
613 |
+
prnt.find('.wt-iew_conditional_help_text').each(function()
|
614 |
+
{
|
615 |
+
var help_text_elm=jQuery(this);
|
616 |
+
var this_condition=jQuery(this).attr('data-iew-help-condition');
|
617 |
+
if(this_condition!='')
|
618 |
+
{
|
619 |
+
var condition_conf=new Array();
|
620 |
+
var field_arr=new Array();
|
621 |
+
while ((m = regex.exec(this_condition)) !== null)
|
622 |
+
{
|
623 |
+
/* This is necessary to avoid infinite loops with zero-width matches */
|
624 |
+
if(m.index === regex.lastIndex)
|
625 |
+
{
|
626 |
+
regex.lastIndex++;
|
627 |
+
}
|
628 |
+
condition_conf.push(m[1]);
|
629 |
+
condition_arr=m[1].split('=');
|
630 |
+
if(condition_arr.length>1) /* field value pair */
|
631 |
+
{
|
632 |
+
field_arr.push(condition_arr[0]);
|
633 |
+
}
|
634 |
+
}
|
635 |
+
if(field_arr.length>0)
|
636 |
+
{
|
637 |
+
var callback_fn=function()
|
638 |
+
{
|
639 |
+
var is_hide=true;
|
640 |
+
var previous_type='';
|
641 |
+
for(var c_i=0; c_i<condition_conf.length; c_i++)
|
642 |
+
{
|
643 |
+
var cr_conf=condition_conf[c_i]; /* conf */
|
644 |
+
var conf_arr=cr_conf.split('=');
|
645 |
+
if(conf_arr.length>1) /* field value pair */
|
646 |
+
{
|
647 |
+
if(previous_type!='field')
|
648 |
+
{
|
649 |
+
previous_type='field';
|
650 |
+
var elm=jQuery('[name="'+conf_arr[0]+'"]');
|
651 |
+
var vl='';
|
652 |
+
if(elm.prop('nodeName').toLowerCase()=='input' && elm.attr('type')=='radio')
|
653 |
+
{
|
654 |
+
vl=jQuery('[name="'+conf_arr[0]+'"]:checked').val();
|
655 |
+
}
|
656 |
+
else if(elm.prop('nodeName').toLowerCase()=='input' && elm.attr('type')=='checkbox')
|
657 |
+
{
|
658 |
+
if(elm.is(':checked'))
|
659 |
+
{
|
660 |
+
vl=elm.val();
|
661 |
+
}
|
662 |
+
}else
|
663 |
+
{
|
664 |
+
vl=elm.val();
|
665 |
+
}
|
666 |
+
is_hide=(vl==conf_arr[1] ? false : true);
|
667 |
+
}
|
668 |
+
}else /* glue */
|
669 |
+
{
|
670 |
+
if(previous_type!='glue')
|
671 |
+
{
|
672 |
+
previous_type='glue';
|
673 |
+
if(conf_arr[0]=='OR')
|
674 |
+
{
|
675 |
+
if(is_hide===false) /* one previous condition is okay, then stop the loop */
|
676 |
+
{
|
677 |
+
break;
|
678 |
+
}
|
679 |
+
|
680 |
+
}else if(conf_arr[0]=='AND')
|
681 |
+
{
|
682 |
+
if(is_hide===true && c_i>0) /* one previous condition is not okay, then stop the loop */
|
683 |
+
{
|
684 |
+
break;
|
685 |
+
}
|
686 |
+
}
|
687 |
+
}
|
688 |
+
}
|
689 |
+
}
|
690 |
+
if(is_hide)
|
691 |
+
{
|
692 |
+
help_text_elm.hide();
|
693 |
+
}else
|
694 |
+
{
|
695 |
+
help_text_elm.css({'display':'inline-block'});
|
696 |
+
}
|
697 |
+
}
|
698 |
+
callback_fn();
|
699 |
+
for(var f_i=0; f_i<field_arr.length; f_i++)
|
700 |
+
{
|
701 |
+
var elm=jQuery('[name="'+field_arr[f_i]+'"]');
|
702 |
+
if(elm.prop('nodeName')=='radio' || elm.prop('nodeName')=='checkbox')
|
703 |
+
{
|
704 |
+
elm.on('click', callback_fn);
|
705 |
+
}else
|
706 |
+
{
|
707 |
+
elm.on('change', callback_fn);
|
708 |
+
}
|
709 |
+
}
|
710 |
+
}
|
711 |
+
}
|
712 |
+
});
|
713 |
+
}
|
714 |
+
}
|
715 |
+
|
716 |
+
|
717 |
+
jQuery(document).ready(function(){
|
718 |
+
wt_iew_popup.Set();
|
719 |
+
wt_iew_settings_form_basic.Set('#'+wt_iew_basic_params.plugin_id);
|
720 |
+
wt_drp_menu.Set();
|
721 |
+
wt_iew_file_attacher.Set();
|
722 |
+
wt_iew_form_toggler.Set();
|
723 |
+
wt_field_group.Set();
|
724 |
+
});
|
admin/modules/coupon/coupon.php
ADDED
@@ -0,0 +1,514 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Coupon section of the plugin
|
5 |
+
*
|
6 |
+
* @link
|
7 |
+
*
|
8 |
+
* @package Wt_Import_Export_For_Woo
|
9 |
+
*/
|
10 |
+
if (!defined('ABSPATH')) {
|
11 |
+
exit;
|
12 |
+
}
|
13 |
+
|
14 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Basic_Coupon')){
|
15 |
+
class Wt_Import_Export_For_Woo_Basic_Coupon {
|
16 |
+
|
17 |
+
public $module_id = '';
|
18 |
+
public static $module_id_static = '';
|
19 |
+
public $module_base = 'coupon';
|
20 |
+
public $module_name = 'Coupon Import Export for WooCommerce';
|
21 |
+
public $min_base_version= '1.0.0'; /* Minimum `Import export plugin` required to run this add on plugin */
|
22 |
+
|
23 |
+
private $importer = null;
|
24 |
+
private $exporter = null;
|
25 |
+
private $all_meta_keys = array();
|
26 |
+
private $found_meta = array();
|
27 |
+
private $found_hidden_meta = array();
|
28 |
+
private $selected_column_names = null;
|
29 |
+
|
30 |
+
public function __construct()
|
31 |
+
{
|
32 |
+
/**
|
33 |
+
* Checking the minimum required version of `Import export plugin` plugin available
|
34 |
+
*/
|
35 |
+
if(!Wt_Import_Export_For_Woo_Basic_Common_Helper::check_base_version($this->module_base, $this->module_name, $this->min_base_version))
|
36 |
+
{
|
37 |
+
return;
|
38 |
+
}
|
39 |
+
if(!function_exists('is_plugin_active'))
|
40 |
+
{
|
41 |
+
include_once(ABSPATH.'wp-admin/includes/plugin.php');
|
42 |
+
}
|
43 |
+
if(!is_plugin_active('woocommerce/woocommerce.php'))
|
44 |
+
{
|
45 |
+
return;
|
46 |
+
}
|
47 |
+
|
48 |
+
$this->module_id = Wt_Import_Export_For_Woo_basic::get_module_id($this->module_base);
|
49 |
+
self::$module_id_static = $this->module_id;
|
50 |
+
|
51 |
+
add_filter('wt_iew_exporter_post_types_basic', array($this, 'wt_iew_exporter_post_types_basic'), 10, 1);
|
52 |
+
add_filter('wt_iew_importer_post_types_basic', array($this, 'wt_iew_exporter_post_types_basic'), 10, 1);
|
53 |
+
|
54 |
+
add_filter('wt_iew_exporter_alter_mapping_fields_basic', array($this, 'exporter_alter_mapping_fields'), 10, 3);
|
55 |
+
add_filter('wt_iew_importer_alter_mapping_fields_basic', array($this, 'get_importer_post_columns'), 10, 3);
|
56 |
+
|
57 |
+
add_filter('wt_iew_exporter_alter_filter_fields_basic', array($this, 'exporter_alter_filter_fields'), 10, 3);
|
58 |
+
|
59 |
+
add_filter('wt_iew_importer_alter_advanced_fields_basic', array($this, 'importer_alter_advanced_fields'), 10, 3);
|
60 |
+
|
61 |
+
add_filter('wt_iew_exporter_alter_meta_mapping_fields_basic', array($this, 'exporter_alter_meta_mapping_fields'), 10, 3);
|
62 |
+
add_filter('wt_iew_importer_alter_meta_mapping_fields_basic', array($this, 'importer_alter_meta_mapping_fields'), 10, 3);
|
63 |
+
|
64 |
+
add_filter('wt_iew_exporter_alter_mapping_enabled_fields_basic', array($this, 'exporter_alter_mapping_enabled_fields'), 10, 3);
|
65 |
+
add_filter('wt_iew_importer_alter_mapping_enabled_fields_basic', array($this, 'exporter_alter_mapping_enabled_fields'), 10, 3);
|
66 |
+
|
67 |
+
add_filter('wt_iew_exporter_do_export_basic', array($this, 'exporter_do_export'), 10, 7);
|
68 |
+
add_filter('wt_iew_importer_do_import_basic', array($this, 'importer_do_import'), 10, 8);
|
69 |
+
|
70 |
+
add_filter('wt_iew_importer_steps_basic', array($this, 'importer_steps'), 10, 2);
|
71 |
+
}
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Altering advanced step description
|
75 |
+
*/
|
76 |
+
public function importer_steps($steps, $base)
|
77 |
+
{
|
78 |
+
if($this->module_base==$base)
|
79 |
+
{
|
80 |
+
$steps['advanced']['description']=__('Use advanced options from below to decide updates to existing coupons, batch import count. You can also save the template file for future imports.');
|
81 |
+
}
|
82 |
+
return $steps;
|
83 |
+
}
|
84 |
+
|
85 |
+
public function importer_do_import($import_data, $base, $step, $form_data, $selected_template_data, $method_import, $batch_offset, $is_last_batch) {
|
86 |
+
if ($this->module_base != $base) {
|
87 |
+
return $import_data;
|
88 |
+
}
|
89 |
+
|
90 |
+
if(0 == $batch_offset){
|
91 |
+
$memory = size_format(wt_let_to_num_basic(ini_get('memory_limit')));
|
92 |
+
$wp_memory = size_format(wt_let_to_num_basic(WP_MEMORY_LIMIT));
|
93 |
+
Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->module_base, 'import', '---[ New import started at '.date('Y-m-d H:i:s').' ] PHP Memory: ' . $memory . ', WP Memory: ' . $wp_memory);
|
94 |
+
}
|
95 |
+
|
96 |
+
include plugin_dir_path(__FILE__) . 'import/import.php';
|
97 |
+
$import = new Wt_Import_Export_For_Woo_Basic_Coupon_Import($this);
|
98 |
+
|
99 |
+
$response = $import->prepare_data_to_import($import_data,$form_data,$batch_offset,$is_last_batch);
|
100 |
+
|
101 |
+
if($is_last_batch){
|
102 |
+
Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->module_base, 'import', '---[ Import ended at '.date('Y-m-d H:i:s').']---');
|
103 |
+
}
|
104 |
+
|
105 |
+
return $response;
|
106 |
+
}
|
107 |
+
|
108 |
+
|
109 |
+
public function exporter_do_export($export_data, $base, $step, $form_data, $selected_template_data, $method_export, $batch_offset) {
|
110 |
+
if ($this->module_base != $base) {
|
111 |
+
return $export_data;
|
112 |
+
}
|
113 |
+
|
114 |
+
switch ($method_export) {
|
115 |
+
case 'quick':
|
116 |
+
$this->set_export_columns_for_quick_export($form_data);
|
117 |
+
break;
|
118 |
+
|
119 |
+
case 'template':
|
120 |
+
case 'new':
|
121 |
+
$this->set_selected_column_names($form_data);
|
122 |
+
break;
|
123 |
+
|
124 |
+
default:
|
125 |
+
break;
|
126 |
+
}
|
127 |
+
|
128 |
+
include plugin_dir_path(__FILE__) . 'export/export.php';
|
129 |
+
$export = new Wt_Import_Export_For_Woo_Basic_Coupon_Export($this);
|
130 |
+
|
131 |
+
$header_row = $export->prepare_header();
|
132 |
+
|
133 |
+
$data_row = $export->prepare_data_to_export($form_data, $batch_offset);
|
134 |
+
|
135 |
+
$export_data = array(
|
136 |
+
'head_data' => $header_row,
|
137 |
+
'body_data' => $data_row['data'],
|
138 |
+
'total' => $data_row['total'],
|
139 |
+
);
|
140 |
+
|
141 |
+
return $export_data;
|
142 |
+
}
|
143 |
+
|
144 |
+
/*
|
145 |
+
* Setting default export columns for quick export
|
146 |
+
*/
|
147 |
+
|
148 |
+
public function set_export_columns_for_quick_export($form_data) {
|
149 |
+
|
150 |
+
$post_columns = self::get_coupon_post_columns();
|
151 |
+
|
152 |
+
$this->selected_column_names = array_combine(array_keys($post_columns), array_keys($post_columns));
|
153 |
+
|
154 |
+
if (isset($form_data['method_export_form_data']['mapping_enabled_fields']) && !empty($form_data['method_export_form_data']['mapping_enabled_fields'])) {
|
155 |
+
foreach ($form_data['method_export_form_data']['mapping_enabled_fields'] as $value) {
|
156 |
+
$additional_quick_export_fields[$value] = array('fields' => array());
|
157 |
+
}
|
158 |
+
|
159 |
+
$export_additional_columns = $this->exporter_alter_meta_mapping_fields($additional_quick_export_fields, $this->module_base, array());
|
160 |
+
foreach ($export_additional_columns as $value) {
|
161 |
+
$this->selected_column_names = array_merge($this->selected_column_names, $value['fields']);
|
162 |
+
}
|
163 |
+
}
|
164 |
+
}
|
165 |
+
|
166 |
+
|
167 |
+
/**
|
168 |
+
* Adding current post type to export list
|
169 |
+
*
|
170 |
+
*/
|
171 |
+
public function wt_iew_exporter_post_types_basic($arr) {
|
172 |
+
$arr['coupon'] = __('Coupon');
|
173 |
+
return $arr;
|
174 |
+
}
|
175 |
+
|
176 |
+
public static function get_coupon_types() {
|
177 |
+
$coupon_types = wc_get_coupon_types();
|
178 |
+
return apply_filters('wt_iew_export_coupon_types', $coupon_types);
|
179 |
+
|
180 |
+
}
|
181 |
+
|
182 |
+
public static function get_coupon_statuses() {
|
183 |
+
$statuses = array('publish', 'private', 'draft', 'pending', 'future');
|
184 |
+
return apply_filters('wt_iew_export_coupon_statuses', array_combine($statuses, $statuses));
|
185 |
+
}
|
186 |
+
|
187 |
+
public static function get_coupon_sort_columns() {
|
188 |
+
$sort_columns = array('ID', 'post_parent', 'post_title', 'post_date', 'post_modified', 'post_author', 'menu_order', 'comment_count');
|
189 |
+
return apply_filters('wt_iew_export_coupon_sort_columns', array_combine($sort_columns, $sort_columns));
|
190 |
+
}
|
191 |
+
|
192 |
+
public static function get_coupon_post_columns() {
|
193 |
+
return include plugin_dir_path(__FILE__) . 'data/data-coupon-post-columns.php';
|
194 |
+
}
|
195 |
+
|
196 |
+
public function get_importer_post_columns($fields, $base, $step_page_form_data) {
|
197 |
+
if ($base != $this->module_base) {
|
198 |
+
return $fields;
|
199 |
+
}
|
200 |
+
$colunm = include plugin_dir_path(__FILE__) . 'data/data/data-wf-reserved-fields-pair.php';
|
201 |
+
// $colunm = array_map(function($vl){ return array('title'=>$vl, 'description'=>$vl); }, $arr);
|
202 |
+
return $colunm;
|
203 |
+
}
|
204 |
+
|
205 |
+
public function exporter_alter_mapping_enabled_fields($mapping_enabled_fields, $base, $form_data_mapping_enabled_fields) {
|
206 |
+
if ($base == $this->module_base) {
|
207 |
+
$mapping_enabled_fields = array();
|
208 |
+
}
|
209 |
+
return $mapping_enabled_fields;
|
210 |
+
}
|
211 |
+
|
212 |
+
|
213 |
+
public function exporter_alter_meta_mapping_fields($fields, $base, $step_page_form_data) {
|
214 |
+
if ($base != $this->module_base) {
|
215 |
+
return $fields;
|
216 |
+
}
|
217 |
+
|
218 |
+
foreach ($fields as $key => $value) {
|
219 |
+
switch ($key) {
|
220 |
+
default:
|
221 |
+
break;
|
222 |
+
}
|
223 |
+
}
|
224 |
+
|
225 |
+
return $fields;
|
226 |
+
}
|
227 |
+
|
228 |
+
public function importer_alter_meta_mapping_fields($fields, $base, $step_page_form_data) {
|
229 |
+
if ($base != $this->module_base) {
|
230 |
+
return $fields;
|
231 |
+
}
|
232 |
+
$fields=$this->exporter_alter_meta_mapping_fields($fields, $base, $step_page_form_data);
|
233 |
+
$out=array();
|
234 |
+
foreach ($fields as $key => $value)
|
235 |
+
{
|
236 |
+
$value['fields']=array_map(function($vl){ return array('title'=>$vl, 'description'=>$vl); }, $value['fields']);
|
237 |
+
$out[$key]=$value;
|
238 |
+
}
|
239 |
+
return $out;
|
240 |
+
}
|
241 |
+
|
242 |
+
public function wt_get_found_meta() {
|
243 |
+
|
244 |
+
if (!empty($this->found_meta)) {
|
245 |
+
return $this->found_meta;
|
246 |
+
}
|
247 |
+
|
248 |
+
// Loop products and load meta data
|
249 |
+
$found_meta = array();
|
250 |
+
// Some of the values may not be usable (e.g. arrays of arrays) but the worse
|
251 |
+
// that can happen is we get an empty column.
|
252 |
+
|
253 |
+
$all_meta_keys = $this->wt_get_all_meta_keys();
|
254 |
+
|
255 |
+
|
256 |
+
$csv_columns = self::get_coupon_post_columns();
|
257 |
+
|
258 |
+
|
259 |
+
foreach ($all_meta_keys as $meta) {
|
260 |
+
|
261 |
+
if (!$meta || (substr((string) $meta, 0, 1) == '_') || in_array($meta, array_keys($csv_columns)) || in_array('meta:' . $meta, array_keys($csv_columns)))
|
262 |
+
continue;
|
263 |
+
|
264 |
+
$found_meta[] = $meta;
|
265 |
+
}
|
266 |
+
|
267 |
+
$found_meta = array_diff($found_meta, array_keys($csv_columns));
|
268 |
+
$this->found_meta = $found_meta;
|
269 |
+
return $this->found_meta;
|
270 |
+
}
|
271 |
+
|
272 |
+
public function wt_get_found_hidden_meta() {
|
273 |
+
|
274 |
+
if (!empty($this->found_hidden_meta)) {
|
275 |
+
return $this->found_hidden_meta;
|
276 |
+
}
|
277 |
+
|
278 |
+
// Loop products and load meta data
|
279 |
+
$found_hidden_meta = array();
|
280 |
+
// Some of the values may not be usable (e.g. arrays of arrays) but the worse
|
281 |
+
// that can happen is we get an empty column.
|
282 |
+
|
283 |
+
$all_meta_keys = $this->wt_get_all_meta_keys();
|
284 |
+
$csv_columns = self::get_coupon_post_columns();
|
285 |
+
foreach ($all_meta_keys as $meta) {
|
286 |
+
|
287 |
+
if (!$meta || (substr((string) $meta, 0, 1) != '_') || in_array($meta, array_keys($csv_columns)) || in_array('meta:' . $meta, array_keys($csv_columns)))
|
288 |
+
continue;
|
289 |
+
|
290 |
+
$found_hidden_meta[] = $meta;
|
291 |
+
}
|
292 |
+
|
293 |
+
$found_hidden_meta = array_diff($found_hidden_meta, array_keys($csv_columns));
|
294 |
+
|
295 |
+
$this->found_hidden_meta = $found_hidden_meta;
|
296 |
+
return $this->found_hidden_meta;
|
297 |
+
}
|
298 |
+
|
299 |
+
|
300 |
+
public function wt_get_all_meta_keys() {
|
301 |
+
|
302 |
+
if (!empty($this->all_meta_keys)) {
|
303 |
+
return $this->all_meta_keys;
|
304 |
+
}
|
305 |
+
|
306 |
+
$all_meta_keys = self::get_all_metakeys('shop_coupon');
|
307 |
+
|
308 |
+
$this->all_meta_keys = $all_meta_keys;
|
309 |
+
return $this->all_meta_keys;
|
310 |
+
}
|
311 |
+
|
312 |
+
|
313 |
+
public static function get_all_metakeys($post_type = 'shop_coupon') {
|
314 |
+
global $wpdb;
|
315 |
+
|
316 |
+
$meta = $wpdb->get_col($wpdb->prepare(
|
317 |
+
"SELECT DISTINCT pm.meta_key
|
318 |
+
FROM {$wpdb->postmeta} AS pm
|
319 |
+
LEFT JOIN {$wpdb->posts} AS p ON p.ID = pm.post_id
|
320 |
+
WHERE p.post_type = %s
|
321 |
+
AND p.post_status IN ( 'publish', 'pending', 'private', 'draft' )", $post_type
|
322 |
+
));
|
323 |
+
|
324 |
+
sort($meta);
|
325 |
+
|
326 |
+
return $meta;
|
327 |
+
}
|
328 |
+
|
329 |
+
|
330 |
+
public function set_selected_column_names($full_form_data) {
|
331 |
+
if (is_null($this->selected_column_names)) {
|
332 |
+
if (isset($full_form_data['mapping_form_data']['mapping_selected_fields']) && !empty($full_form_data['mapping_form_data']['mapping_selected_fields'])) {
|
333 |
+
$this->selected_column_names = $full_form_data['mapping_form_data']['mapping_selected_fields'];
|
334 |
+
}
|
335 |
+
if (isset($full_form_data['meta_step_form_data']['mapping_selected_fields']) && !empty($full_form_data['meta_step_form_data']['mapping_selected_fields'])) {
|
336 |
+
$export_additional_columns = $full_form_data['meta_step_form_data']['mapping_selected_fields'];
|
337 |
+
foreach ($export_additional_columns as $value) {
|
338 |
+
$this->selected_column_names = array_merge($this->selected_column_names, $value);
|
339 |
+
}
|
340 |
+
}
|
341 |
+
}
|
342 |
+
|
343 |
+
return $full_form_data;
|
344 |
+
}
|
345 |
+
|
346 |
+
public function get_selected_column_names() {
|
347 |
+
|
348 |
+
return $this->selected_column_names;
|
349 |
+
}
|
350 |
+
|
351 |
+
public function exporter_alter_mapping_fields($fields, $base, $mapping_form_data) {
|
352 |
+
if ($base == $this->module_base) {
|
353 |
+
$fields = self::get_coupon_post_columns();
|
354 |
+
}
|
355 |
+
return $fields;
|
356 |
+
}
|
357 |
+
|
358 |
+
public function importer_alter_advanced_fields($fields, $base, $advanced_form_data) {
|
359 |
+
if ($this->module_base != $base) {
|
360 |
+
return $fields;
|
361 |
+
}
|
362 |
+
$out = array();
|
363 |
+
$out['found_action_merge'] = array(
|
364 |
+
'label' => __("If the coupon exists in the store"),
|
365 |
+
'type' => 'radio',
|
366 |
+
'radio_fields' => array(
|
367 |
+
'skip' => __('Skip'),
|
368 |
+
'update' => __('Update'),
|
369 |
+
),
|
370 |
+
'value' => 'skip',
|
371 |
+
'field_name' => 'found_action',
|
372 |
+
'help_text_conditional'=>array(
|
373 |
+
array(
|
374 |
+
'help_text'=> __('Retains the coupon in the store as is and skips the matching coupon from the input file.'),
|
375 |
+
'condition'=>array(
|
376 |
+
array('field'=>'wt_iew_found_action', 'value'=>'skip')
|
377 |
+
)
|
378 |
+
),
|
379 |
+
array(
|
380 |
+
'help_text'=> __('Update coupon as per data from the input file'),
|
381 |
+
'condition'=>array(
|
382 |
+
array('field'=>'wt_iew_found_action', 'value'=>'update')
|
383 |
+
)
|
384 |
+
)
|
385 |
+
),
|
386 |
+
'form_toggler'=>array(
|
387 |
+
'type'=>'parent',
|
388 |
+
'target'=>'wt_iew_found_action'
|
389 |
+
)
|
390 |
+
);
|
391 |
+
|
392 |
+
|
393 |
+
foreach ($fields as $fieldk => $fieldv) {
|
394 |
+
$out[$fieldk] = $fieldv;
|
395 |
+
}
|
396 |
+
return $out;
|
397 |
+
}
|
398 |
+
|
399 |
+
/**
|
400 |
+
* Customize the items in filter export page
|
401 |
+
*/
|
402 |
+
public function exporter_alter_filter_fields($fields, $base, $filter_form_data) {
|
403 |
+
|
404 |
+
if ($base == $this->module_base)
|
405 |
+
{
|
406 |
+
/* altering help text of default fields */
|
407 |
+
$fields['limit']['label']=__('Total number of coupons to export');
|
408 |
+
$fields['limit']['help_text']=__('Exports specified number of coupons. e.g. Entering 500 with a skip count of 10 will export coupons from 11th to 510th position.');
|
409 |
+
$fields['offset']['label']=__('Skip first <i>n</i> coupons');
|
410 |
+
$fields['offset']['help_text']=__('Skips specified number of coupons from the beginning. e.g. Enter 10 to skip first 10 coupons from export.');
|
411 |
+
|
412 |
+
$fields['statuses'] = array(
|
413 |
+
'label' => __('Coupon Statuses'),
|
414 |
+
'placeholder' => __('All Statuses'),
|
415 |
+
'field_name' => 'statuses',
|
416 |
+
'sele_vals' => self::get_coupon_statuses(),
|
417 |
+
'help_text' => __('Export coupons by their status. You can specify more than one status if required.'),
|
418 |
+
'type' => 'multi_select',
|
419 |
+
'css_class' => 'wc-enhanced-select',
|
420 |
+
'validation_rule' => array('type'=>'text_arr')
|
421 |
+
);
|
422 |
+
$fields['types'] = array(
|
423 |
+
'label' => __('Coupon Type'),
|
424 |
+
'placeholder' => __('All Types'),
|
425 |
+
'field_name' => 'types',
|
426 |
+
'sele_vals' => self::get_coupon_types(),
|
427 |
+
'help_text' => __('Select the coupon type e.g, fixed cart, recurring etc to export only coupon of a specific type.'),
|
428 |
+
'type' => 'multi_select',
|
429 |
+
'css_class' => 'wc-enhanced-select',
|
430 |
+
'validation_rule' => array('type'=>'text_arr')
|
431 |
+
);
|
432 |
+
|
433 |
+
|
434 |
+
$fields['coupon_amount_from'] = array(
|
435 |
+
'label'=>__("Coupon amount: From"),
|
436 |
+
'placeholder' => __('From amount'),
|
437 |
+
'type'=>'number',
|
438 |
+
'value' =>'',
|
439 |
+
'attr' =>array(
|
440 |
+
'min'=>0,
|
441 |
+
),
|
442 |
+
'field_name'=>'coupon_amount_from',
|
443 |
+
'help_text'=>__('Export coupons by their discount amount. Specify the minimum discount amount for which the coupon was levied.'),
|
444 |
+
'validation_rule'=>array('type'=>'floatval'),
|
445 |
+
|
446 |
+
);
|
447 |
+
|
448 |
+
|
449 |
+
$fields['coupon_amount_to'] = array(
|
450 |
+
'label'=>__("Coupon amount: To"),
|
451 |
+
'placeholder' => __('To amount'),
|
452 |
+
'type'=>'number',
|
453 |
+
'value' =>'',
|
454 |
+
'attr' =>array(
|
455 |
+
'min'=>0,
|
456 |
+
),
|
457 |
+
'field_name'=>'coupon_amount_to',
|
458 |
+
'help_text'=>__('Export coupons by their discount amount. Specify the maximum discount amount for which the coupon was levied.'),
|
459 |
+
'validation_rule'=>array('type'=>'floatval'),
|
460 |
+
|
461 |
+
);
|
462 |
+
|
463 |
+
|
464 |
+
|
465 |
+
$fields['coupon_exp_date_from'] = array(
|
466 |
+
'label' => __('Coupon Expiry Date: From'),
|
467 |
+
'placeholder' => __('From date'),
|
468 |
+
'field_name' => 'coupon_exp_date_from',
|
469 |
+
'sele_vals' => '',
|
470 |
+
'help_text' => __('Date on which the coupon will expire. Export coupons with expiry date equal to or greater than the specified date.'),
|
471 |
+
'type' => 'text',
|
472 |
+
'css_class' => 'wt_iew_datepicker',
|
473 |
+
);
|
474 |
+
|
475 |
+
$fields['coupon_exp_date_to'] = array(
|
476 |
+
'label' => __('Coupon Expiry Date: To'),
|
477 |
+
'placeholder' => __('To date'),
|
478 |
+
'field_name' => 'coupon_exp_date_to',
|
479 |
+
'sele_vals' => '',
|
480 |
+
'help_text' => __('Date on which the coupon will expire. Export coupons with expiry date equal to or less than the specified date.'),
|
481 |
+
'type' => 'text',
|
482 |
+
'css_class' => 'wt_iew_datepicker',
|
483 |
+
);
|
484 |
+
|
485 |
+
$fields['sort_columns'] = array(
|
486 |
+
'label' => __('Sort columns'),
|
487 |
+
'placeholder' => __('ID'),
|
488 |
+
'field_name' => 'sort_columns',
|
489 |
+
'sele_vals' => self::get_coupon_sort_columns(),
|
490 |
+
'help_text' => __('Sort the exported data based on the selected columns in order specified. Defaulted to ascending order.'),
|
491 |
+
'type' => 'multi_select',
|
492 |
+
'css_class' => 'wc-enhanced-select',
|
493 |
+
'validation_rule' => array('type'=>'text_arr')
|
494 |
+
);
|
495 |
+
|
496 |
+
$fields['order_by'] = array(
|
497 |
+
'label' => __('Sort By'),
|
498 |
+
'placeholder' => __('ASC'),
|
499 |
+
'field_name' => 'order_by',
|
500 |
+
'sele_vals' => array('ASC' => 'Ascending', 'DESC' => 'Descending'),
|
501 |
+
'help_text' => __('Defaulted to Ascending. Applicable to above selected columns in the order specified.'),
|
502 |
+
'type' => 'select',
|
503 |
+
);
|
504 |
+
}
|
505 |
+
return $fields;
|
506 |
+
}
|
507 |
+
public function get_item_by_id($id) {
|
508 |
+
$post['edit_url']=get_edit_post_link($id);
|
509 |
+
$post['title'] = get_the_title($id);
|
510 |
+
return $post;
|
511 |
+
}
|
512 |
+
}
|
513 |
+
}
|
514 |
+
new Wt_Import_Export_For_Woo_Basic_Coupon();
|
includes/exporter/data/data-wf-post-columns-coupon.php → admin/modules/coupon/data/data-coupon-post-columns.php
RENAMED
@@ -16,12 +16,13 @@ return apply_filters('coupon_csv_coupon_post_columns', array(
|
|
16 |
'coupon_amount' => 'coupon_amount',
|
17 |
'individual_use' => 'individual_use',
|
18 |
'product_ids' => 'product_ids',
|
|
|
19 |
'exclude_product_ids' => 'exclude_product_ids',
|
|
|
|
|
20 |
'usage_limit' => 'usage_limit',
|
21 |
'usage_limit_per_user' => 'usage_limit_per_user',
|
22 |
-
'usage_count' => 'usage_count',
|
23 |
'limit_usage_to_x_items' => 'limit_usage_to_x_items',
|
24 |
-
//'expiry_date' => 'expiry_date',
|
25 |
'date_expires' => 'date_expires',
|
26 |
'free_shipping' => 'free_shipping',
|
27 |
'exclude_sale_items' => 'exclude_sale_items',
|
@@ -30,5 +31,4 @@ return apply_filters('coupon_csv_coupon_post_columns', array(
|
|
30 |
'minimum_amount' => 'minimum_amount',
|
31 |
'maximum_amount' => 'maximum_amount',
|
32 |
'customer_email' => 'customer_email',
|
33 |
-
|
34 |
) );
|
16 |
'coupon_amount' => 'coupon_amount',
|
17 |
'individual_use' => 'individual_use',
|
18 |
'product_ids' => 'product_ids',
|
19 |
+
'product_SKUs' => 'product_SKUs',
|
20 |
'exclude_product_ids' => 'exclude_product_ids',
|
21 |
+
'exclude_product_SKUs' => 'exclude_product_SKUs',
|
22 |
+
'usage_count' => 'usage_count',
|
23 |
'usage_limit' => 'usage_limit',
|
24 |
'usage_limit_per_user' => 'usage_limit_per_user',
|
|
|
25 |
'limit_usage_to_x_items' => 'limit_usage_to_x_items',
|
|
|
26 |
'date_expires' => 'date_expires',
|
27 |
'free_shipping' => 'free_shipping',
|
28 |
'exclude_sale_items' => 'exclude_sale_items',
|
31 |
'minimum_amount' => 'minimum_amount',
|
32 |
'maximum_amount' => 'maximum_amount',
|
33 |
'customer_email' => 'customer_email',
|
|
|
34 |
) );
|
admin/modules/coupon/data/data/data-wf-reserved-fields-pair.php
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
// Reserved column names
|
4 |
+
return apply_filters('woocommerce_csv_product_import_reserved_fields_pair',array(
|
5 |
+
'ID' => array('title'=>'Coupon ID','description'=>'Coupon ID'),
|
6 |
+
'post_title' => array('title'=>'Coupon Title','description'=>'Name of the coupon '),
|
7 |
+
//'post_name' => array('title'=>'Coupon Permalink','description'=>'Unique part of the coupon URL'),
|
8 |
+
'post_status' => array('title'=>'Coupon Status','description'=>'Coupon Status ( published , draft ...)'),
|
9 |
+
//'post_content' => array('title'=>'Coupon Description','description'=>'Description about the Coupon'),
|
10 |
+
'post_excerpt' => array('title'=>'Coupon Short Description','description'=>'Short description about the Coupon'),
|
11 |
+
'post_date' => array('title'=>'Post Date','description'=>'Coupon posted date', 'type' => 'date'),
|
12 |
+
'discount_type' => array('title'=>'Coupon Type','description'=>'fixed_cart OR percent OR fixed_product OR percent_product'),
|
13 |
+
'coupon_amount' => array('title'=>'Coupon Amount','description'=>'Numeric values'),
|
14 |
+
'individual_use' => array('title'=>'Individual Use?','description'=>'yes or no'),
|
15 |
+
'product_ids' => array('title'=>'Associated Product Ids','description'=>'With comma(,) Separator'),
|
16 |
+
'exclude_product_ids' => array('title'=>'Exclude Product Ids','description'=>'With comma(,) Separator'),
|
17 |
+
'usage_count' => array('title'=>'No of times used','description'=>'Numeric Values'),
|
18 |
+
'usage_limit' => array('title'=>'Usage Limit Per Coupon','description'=>'Numeric Values'),
|
19 |
+
'usage_limit_per_user' => array('title'=>'Usage Limit Per User','description'=>'Numeric Values'),
|
20 |
+
'limit_usage_to_x_items' => array('title'=>'Limit Usage To X Items','description'=>'Maximum Number Of Individual Items This Coupon Can Apply'),
|
21 |
+
'date_expires' => array('title'=>'Expiry Date','description'=>'YYYY-MM-DD', 'type' => 'date'),
|
22 |
+
'free_shipping' => array('title'=>'Is Free Shipping?','description'=>'yes or no'),
|
23 |
+
'exclude_sale_items' => array('title'=>'Is Exclude Sale Items?','description'=>'yes or no'),
|
24 |
+
'product_categories' => array('title'=>'Product Categories','description'=>'with comma(,) Separator'),
|
25 |
+
'exclude_product_categories' => array('title'=>'Exclude Product Categories','description'=>'With comma(,) Separator'),
|
26 |
+
'minimum_amount' => array('title'=>'Minimum Amount','description'=>'Numeric'),
|
27 |
+
'maximum_amount' => array('title'=>'Maximum Amount','description'=>'Numeric'),
|
28 |
+
'customer_email' => array('title'=>'Restricted Customers Email Ids','description'=>'With comma(,) Separator'),
|
29 |
+
));
|
admin/modules/coupon/export/export.php
ADDED
@@ -0,0 +1,265 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if (!defined('WPINC')) {
|
4 |
+
exit;
|
5 |
+
}
|
6 |
+
|
7 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Basic_Coupon_Export')){
|
8 |
+
class Wt_Import_Export_For_Woo_Basic_Coupon_Export {
|
9 |
+
|
10 |
+
public $parent_module = null;
|
11 |
+
|
12 |
+
public function __construct($parent_object) {
|
13 |
+
|
14 |
+
$this->parent_module = $parent_object;
|
15 |
+
}
|
16 |
+
|
17 |
+
public function prepare_header() {
|
18 |
+
|
19 |
+
$export_columns = $this->parent_module->get_selected_column_names();
|
20 |
+
|
21 |
+
return apply_filters('hf_alter_coupon_csv_header', $export_columns);
|
22 |
+
}
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Prepare data that will be exported.
|
26 |
+
*/
|
27 |
+
public function prepare_data_to_export($form_data, $batch_offset) {
|
28 |
+
|
29 |
+
|
30 |
+
$export_statuses = !empty($form_data['filter_form_data']['wt_iew_statuses']) ? $form_data['filter_form_data']['wt_iew_statuses'] : array('publish', 'pending', 'private', 'draft','future');
|
31 |
+
$cpn_categories = !empty($form_data['filter_form_data']['wt_iew_types']) ? $form_data['filter_form_data']['wt_iew_types'] : array('fixed_cart', 'percent', 'fixed_product', 'percent_product');
|
32 |
+
$coupon_amount_from = !empty($form_data['filter_form_data']['wt_iew_coupon_amount_from']) ? $form_data['filter_form_data']['wt_iew_coupon_amount_from'] : 0;
|
33 |
+
$coupon_amount_to = !empty($form_data['filter_form_data']['wt_iew_coupon_amount_to']) ? $form_data['filter_form_data']['wt_iew_coupon_amount_to'] : 0;
|
34 |
+
$coupon_exp_date_from = !empty($form_data['filter_form_data']['wt_iew_coupon_exp_date_from']) ? $form_data['filter_form_data']['wt_iew_coupon_exp_date_from'] : '0000-00-00';
|
35 |
+
$coupon_exp_date_to = !empty($form_data['filter_form_data']['wt_iew_coupon_exp_date_to']) ? $form_data['filter_form_data']['wt_iew_coupon_exp_date_to'] : '0000-00-00';
|
36 |
+
|
37 |
+
$export_sortby = !empty($form_data['filter_form_data']['wt_iew_sort_columns']) ? implode(' ', $form_data['filter_form_data']['wt_iew_sort_columns']) : 'ID'; // get_post accept spaced string
|
38 |
+
$export_sort_order = !empty($form_data['filter_form_data']['wt_iew_order_by']) ? $form_data['filter_form_data']['wt_iew_order_by'] : 'ASC';
|
39 |
+
|
40 |
+
$export_limit = !empty($form_data['filter_form_data']['wt_iew_limit']) ? intval($form_data['filter_form_data']['wt_iew_limit']) : 999999999; //user limit
|
41 |
+
$current_offset = !empty($form_data['filter_form_data']['wt_iew_offset']) ? intval($form_data['filter_form_data']['wt_iew_offset']) : 0; //user offset
|
42 |
+
$batch_count = !empty($form_data['advanced_form_data']['wt_iew_batch_count']) ? $form_data['advanced_form_data']['wt_iew_batch_count'] : 10;
|
43 |
+
|
44 |
+
$this->export_shortcodes = (!empty($form_data['advanced_form_data']['wt_iew_export_shortcode_tohtml']) && $form_data['advanced_form_data']['wt_iew_export_shortcode_tohtml'] == 'Yes') ? true : false;
|
45 |
+
|
46 |
+
$real_offset = ($current_offset + $batch_offset);
|
47 |
+
|
48 |
+
if($batch_count<=$export_limit)
|
49 |
+
{
|
50 |
+
if(($batch_offset+$batch_count)>$export_limit) //last offset
|
51 |
+
{
|
52 |
+
$limit=$export_limit-$batch_offset;
|
53 |
+
}else
|
54 |
+
{
|
55 |
+
$limit=$batch_count;
|
56 |
+
}
|
57 |
+
}else
|
58 |
+
{
|
59 |
+
$limit=$export_limit;
|
60 |
+
}
|
61 |
+
|
62 |
+
$data_array = array();
|
63 |
+
if ($batch_offset < $export_limit)
|
64 |
+
{
|
65 |
+
$coupon_args = array(
|
66 |
+
'post_status' => $export_statuses,
|
67 |
+
'post_type' => 'shop_coupon',
|
68 |
+
'order' => $export_sort_order,
|
69 |
+
'orderby' => $export_sortby,
|
70 |
+
);
|
71 |
+
|
72 |
+
if (!empty($cpn_categories)) {
|
73 |
+
$coupon_args['meta_query'] = array(
|
74 |
+
array(
|
75 |
+
'key' => 'discount_type',
|
76 |
+
'value' => $cpn_categories,
|
77 |
+
'compare' => 'IN',
|
78 |
+
));
|
79 |
+
}
|
80 |
+
if ($coupon_amount_from != 0 && $coupon_amount_to == 0) {
|
81 |
+
$coupon_args['meta_query'] = array(
|
82 |
+
array(
|
83 |
+
'key' => 'coupon_amount',
|
84 |
+
'value' => $coupon_amount_from,
|
85 |
+
'compare' => '>=',
|
86 |
+
'type' => 'NUMERIC'
|
87 |
+
));
|
88 |
+
}
|
89 |
+
if ($coupon_amount_to != 0 && $coupon_amount_from == 0) {
|
90 |
+
$coupon_args['meta_query'] = array(
|
91 |
+
array(
|
92 |
+
'key' => 'coupon_amount',
|
93 |
+
'value' => $coupon_amount_to,
|
94 |
+
'compare' => '<=',
|
95 |
+
'type' => 'NUMERIC'
|
96 |
+
));
|
97 |
+
}
|
98 |
+
if ($coupon_amount_to != 0 && $coupon_amount_from != 0) {
|
99 |
+
$coupon_args['meta_query'] = array(
|
100 |
+
array(
|
101 |
+
'key' => 'coupon_amount',
|
102 |
+
'value' => array($coupon_amount_from, $coupon_amount_to),
|
103 |
+
'compare' => 'BETWEEN',
|
104 |
+
'type' => 'NUMERIC'
|
105 |
+
));
|
106 |
+
}
|
107 |
+
if ($coupon_exp_date_from != '0000-00-00' && $coupon_exp_date_to == '0000-00-00') {
|
108 |
+
$coupon_args['meta_query'] = array(
|
109 |
+
array(
|
110 |
+
'key' => 'date_expires',
|
111 |
+
'value' => strtotime($coupon_exp_date_from),
|
112 |
+
'compare' => '>=',
|
113 |
+
));
|
114 |
+
}
|
115 |
+
if ($coupon_exp_date_to != '0000-00-00' && $coupon_exp_date_from == '0000-00-00') {
|
116 |
+
$coupon_args['meta_query'] = array(
|
117 |
+
array(
|
118 |
+
'key' => 'date_expires',
|
119 |
+
'value' => strtotime($coupon_exp_date_to),
|
120 |
+
'compare' => '<=',
|
121 |
+
));
|
122 |
+
}
|
123 |
+
if ($coupon_exp_date_to != '0000-00-00' && $coupon_exp_date_from != '0000-00-00') {
|
124 |
+
$coupon_args['meta_query'] = array(
|
125 |
+
array(
|
126 |
+
'key' => 'date_expires',
|
127 |
+
'value' => array(strtotime($coupon_exp_date_from), strtotime($coupon_exp_date_to)),
|
128 |
+
'compare' => 'BETWEEN',
|
129 |
+
));
|
130 |
+
}
|
131 |
+
|
132 |
+
if (!empty($selected_coupon_ids)) {
|
133 |
+
$coupon_args['meta_query'] = array();
|
134 |
+
$coupon_args['post__in'] = $selected_coupon_ids;
|
135 |
+
}
|
136 |
+
|
137 |
+
$coupon_args = apply_filters('coupon_csv_product_export_args', $coupon_args);
|
138 |
+
$coupon_args['offset'] = $real_offset;
|
139 |
+
$coupon_args['posts_per_page'] = $limit;
|
140 |
+
|
141 |
+
$coupons = get_posts($coupon_args);
|
142 |
+
|
143 |
+
foreach ($coupons as $coupon) {
|
144 |
+
if (!$coupons || is_wp_error($coupons))
|
145 |
+
break;
|
146 |
+
|
147 |
+
$data_array[] = $this->generate_row_data($coupon);
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* taking total records
|
152 |
+
*/
|
153 |
+
$total_records=0;
|
154 |
+
if($batch_offset==0) //first batch
|
155 |
+
{
|
156 |
+
$total_item_args = $coupon_args;
|
157 |
+
$total_item_args['fields'] = 'ids';
|
158 |
+
$total_item_args['posts_per_page'] = $export_limit; //user given limit
|
159 |
+
$total_item_args['offset'] = $current_offset; //user given offset
|
160 |
+
|
161 |
+
$coupons = get_posts($total_item_args);
|
162 |
+
$total_records = count($coupons);
|
163 |
+
}
|
164 |
+
|
165 |
+
$return['total'] = $total_records;
|
166 |
+
$return['data'] = $data_array;
|
167 |
+
return $return;
|
168 |
+
}
|
169 |
+
}
|
170 |
+
|
171 |
+
public function generate_row_data($coupon) {
|
172 |
+
$csv_columns = $this->parent_module->get_selected_column_names();
|
173 |
+
$row = array();
|
174 |
+
|
175 |
+
foreach ($csv_columns as $column => $value) {
|
176 |
+
|
177 |
+
if (isset($coupon->$column)) {
|
178 |
+
if (is_array($coupon->$column)) {
|
179 |
+
$coupon->$column = implode(",", $coupon->$column);
|
180 |
+
}
|
181 |
+
if($column == 'product_ids'){
|
182 |
+
$hf_val = $coupon->$column;
|
183 |
+
$sku = self::get_sku_from_id($hf_val);
|
184 |
+
$row[$column] = str_replace(',', '|', $hf_val);
|
185 |
+
continue;
|
186 |
+
}
|
187 |
+
if($column == 'exclude_product_ids'){
|
188 |
+
$ex_val = $coupon->$column;
|
189 |
+
$exsku = self::get_sku_from_id($ex_val);
|
190 |
+
$row[$column] = str_replace(',', '|', $ex_val);
|
191 |
+
continue;
|
192 |
+
}
|
193 |
+
|
194 |
+
if('date_expires' == $column && !empty($coupon->$column)){
|
195 |
+
$row[$column] = date('Y-m-d',$coupon->$column);
|
196 |
+
continue;
|
197 |
+
}
|
198 |
+
|
199 |
+
$row[$column] = $coupon->$column;
|
200 |
+
continue;
|
201 |
+
} elseif (isset($coupon->$column) && !is_array($coupon->$column)) {
|
202 |
+
if ($column === 'post_title') {
|
203 |
+
$row[$column] = sanitize_text_field($coupon->$column);
|
204 |
+
} else {
|
205 |
+
$row[$column] = $coupon->$column;
|
206 |
+
}
|
207 |
+
continue;
|
208 |
+
}
|
209 |
+
elseif ($column === 'product_SKUs') {
|
210 |
+
$row[$column] = !empty($sku) ? $sku : '';
|
211 |
+
unset($sku);
|
212 |
+
continue;
|
213 |
+
}
|
214 |
+
elseif ($column === 'exclude_product_SKUs') {
|
215 |
+
$row[$column] = !empty($exsku) ? $exsku : '';
|
216 |
+
unset($exsku);
|
217 |
+
continue;
|
218 |
+
}
|
219 |
+
|
220 |
+
if ($this->export_shortcodes && ( 'post_content' == $column || 'post_excerpt' == $column )) {
|
221 |
+
//Convert Shortcodes to html for Description and Short Description
|
222 |
+
$row[$column] = do_shortcode($coupon->$column);
|
223 |
+
continue;
|
224 |
+
}
|
225 |
+
|
226 |
+
// Export meta data
|
227 |
+
if ('meta:' == substr($column, 0, 5)) {
|
228 |
+
|
229 |
+
$meta = substr($column, 5);
|
230 |
+
if (isset($coupon->$meta)) {
|
231 |
+
$row[$column] = maybe_serialize($coupon->$meta);
|
232 |
+
} else {
|
233 |
+
$row[$column] = '';
|
234 |
+
}
|
235 |
+
|
236 |
+
continue;
|
237 |
+
}
|
238 |
+
|
239 |
+
$row[$column] = '';
|
240 |
+
}
|
241 |
+
return apply_filters('hf_alter_coupon_csv_data', $row, $csv_columns);
|
242 |
+
|
243 |
+
}
|
244 |
+
|
245 |
+
public static function get_sku_from_id($val){
|
246 |
+
$pro_id = explode(",", $val);
|
247 |
+
$sku_arr = array();
|
248 |
+
if($pro_id){
|
249 |
+
foreach ($pro_id as $value){
|
250 |
+
$product_exist = get_post_type($value);
|
251 |
+
if ($product_exist == 'product' || $product_exist == 'product_variation'){
|
252 |
+
$psku = get_post_meta($value,'_sku',TRUE);
|
253 |
+
if(!empty($psku)){
|
254 |
+
$sku_arr[] = $psku;
|
255 |
+
}
|
256 |
+
}
|
257 |
+
}
|
258 |
+
}
|
259 |
+
$new_sku = implode("|", $sku_arr);
|
260 |
+
return $new_sku;
|
261 |
+
}
|
262 |
+
|
263 |
+
|
264 |
+
}
|
265 |
+
}
|
admin/modules/coupon/import/import.php
ADDED
@@ -0,0 +1,893 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if (!defined('WPINC')) {
|
4 |
+
exit;
|
5 |
+
}
|
6 |
+
|
7 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Basic_Coupon_Import')){
|
8 |
+
class Wt_Import_Export_For_Woo_Basic_Coupon_Import {
|
9 |
+
|
10 |
+
public $post_type = 'shop_coupon';
|
11 |
+
public $parent_module = null;
|
12 |
+
public $parsed_data = array();
|
13 |
+
public $import_columns = array();
|
14 |
+
public $merge;
|
15 |
+
public $skip_new;
|
16 |
+
public $merge_empty_cells;
|
17 |
+
public $delete_existing;
|
18 |
+
public $use_sku;
|
19 |
+
public $merge_with = 'id';
|
20 |
+
public $found_action = 'skip';
|
21 |
+
public $id_conflict = 'skip';
|
22 |
+
|
23 |
+
// Results
|
24 |
+
var $import_results = array();
|
25 |
+
|
26 |
+
public $is_coupon_exist = false;
|
27 |
+
|
28 |
+
public function __construct($parent_object) {
|
29 |
+
|
30 |
+
$this->parent_module = $parent_object;
|
31 |
+
}
|
32 |
+
|
33 |
+
/* WC object based import */
|
34 |
+
|
35 |
+
public function prepare_data_to_import($import_data, $form_data,$batch_offset,$is_last_batch) {
|
36 |
+
|
37 |
+
$this->merge_with = !empty($form_data['advanced_form_data']['wt_iew_merge_with']) ? $form_data['advanced_form_data']['wt_iew_merge_with'] : 'id';
|
38 |
+
$this->found_action = !empty($form_data['advanced_form_data']['wt_iew_found_action']) ? $form_data['advanced_form_data']['wt_iew_found_action'] : 'skip';
|
39 |
+
$this->id_conflict = !empty($form_data['advanced_form_data']['wt_iew_id_conflict']) ? $form_data['advanced_form_data']['wt_iew_id_conflict'] : 'skip';
|
40 |
+
$this->merge_empty_cells = !empty($form_data['advanced_form_data']['wt_iew_merge_empty_cells']) ? 1 : 0;
|
41 |
+
$this->skip_new = !empty($form_data['advanced_form_data']['wt_iew_skip_new']) ? 1 : 0;
|
42 |
+
|
43 |
+
$this->delete_existing = !empty($form_data['advanced_form_data']['wt_iew_delete_existing']) ? 1 : 0;
|
44 |
+
$this->use_sku = !empty($form_data['advanced_form_data']['wt_iew_use_sku']) ? 1 : 0;
|
45 |
+
|
46 |
+
Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Preparing for import.");
|
47 |
+
|
48 |
+
$success = 0;
|
49 |
+
$failed = 0;
|
50 |
+
$msg = 'Coupon imported successfully.';
|
51 |
+
foreach ($import_data as $key => $data) {
|
52 |
+
$row = $batch_offset+$key+1;
|
53 |
+
Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Row :$row - Parsing item.");
|
54 |
+
$parsed_data = $this->parse_data($data);
|
55 |
+
if (!is_wp_error($parsed_data)){
|
56 |
+
Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Row :$row - Processing item.");
|
57 |
+
$result = $this->process_item($parsed_data);
|
58 |
+
if(!is_wp_error($result)){
|
59 |
+
if($this->is_coupon_exist){
|
60 |
+
$msg = 'Coupon updated successfully.';
|
61 |
+
}
|
62 |
+
$this->import_results[$row] = array('row'=>$row, 'message'=>$msg, 'status'=>true, 'post_id'=>$result['id']);
|
63 |
+
Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Row :$row - ".$msg);
|
64 |
+
$success++;
|
65 |
+
}else{
|
66 |
+
$this->import_results[$row] = array('row'=>$row, 'message'=>$result->get_error_message(), 'status'=>false, 'post_id'=>'');
|
67 |
+
Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Row :$row - Processing failed. Reason: ".$result->get_error_message());
|
68 |
+
$failed++;
|
69 |
+
}
|
70 |
+
}else{
|
71 |
+
$this->import_results[$row] = array('row'=>$row, 'message'=>$parsed_data->get_error_message(), 'status'=>false, 'post_id'=>'');
|
72 |
+
Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Row :$row - Parsing failed. Reason: ".$parsed_data->get_error_message());
|
73 |
+
$failed++;
|
74 |
+
}
|
75 |
+
}
|
76 |
+
|
77 |
+
if($is_last_batch && $this->delete_existing){
|
78 |
+
$this->delete_existing();
|
79 |
+
}
|
80 |
+
|
81 |
+
$this->clean_after_import();
|
82 |
+
|
83 |
+
$import_response=array(
|
84 |
+
'total_success'=>$success,
|
85 |
+
'total_failed'=>$failed,
|
86 |
+
'log_data'=>$this->import_results,
|
87 |
+
);
|
88 |
+
|
89 |
+
return $import_response;
|
90 |
+
}
|
91 |
+
|
92 |
+
public function clean_after_import() {
|
93 |
+
global $wpdb;
|
94 |
+
$posts = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_status = '%s' AND post_type = '%s' ", 'importing' ,$this->post_type));
|
95 |
+
if($posts){
|
96 |
+
array_map('wp_delete_post',$posts);
|
97 |
+
}
|
98 |
+
}
|
99 |
+
|
100 |
+
public function delete_existing() {
|
101 |
+
|
102 |
+
$posts = new WP_Query([
|
103 |
+
'post_type' => $this->post_type,
|
104 |
+
'fields' => 'ids',
|
105 |
+
'posts_per_page' => -1,
|
106 |
+
'post_status' => array('publish', 'private', 'draft', 'pending', 'future'),
|
107 |
+
'meta_query' => [
|
108 |
+
[
|
109 |
+
'key' => '_wt_delete_existing',
|
110 |
+
'compare' => 'NOT EXISTS',
|
111 |
+
]
|
112 |
+
]
|
113 |
+
]);
|
114 |
+
|
115 |
+
foreach ($posts->posts as $post) {
|
116 |
+
$this->import_results['detele_results'][$post] = wp_trash_post($post);
|
117 |
+
}
|
118 |
+
|
119 |
+
|
120 |
+
$posts = new WP_Query([
|
121 |
+
'post_type' => $this->post_type,
|
122 |
+
'fields' => 'ids',
|
123 |
+
'posts_per_page' => -1,
|
124 |
+
'post_status' => array('publish', 'private', 'draft', 'pending', 'future'),
|
125 |
+
'meta_query' => [
|
126 |
+
[
|
127 |
+
'key' => '_wt_delete_existing',
|
128 |
+
'compare' => 'EXISTS',
|
129 |
+
]
|
130 |
+
]
|
131 |
+
]);
|
132 |
+
foreach ($posts->posts as $post) {
|
133 |
+
delete_post_meta($post,'_wt_delete_existing');
|
134 |
+
}
|
135 |
+
|
136 |
+
}
|
137 |
+
|
138 |
+
/**
|
139 |
+
* Parse the data.
|
140 |
+
*
|
141 |
+
*
|
142 |
+
* @param array $data value.
|
143 |
+
*
|
144 |
+
* @return array
|
145 |
+
*/
|
146 |
+
public function parse_data($data) {
|
147 |
+
try {
|
148 |
+
$data = apply_filters("wt_woocommerce_{$this->parent_module->module_base}_importer_pre_parse_data", $data);
|
149 |
+
|
150 |
+
$mapping_fields = $data['mapping_fields'];
|
151 |
+
foreach ($data['meta_mapping_fields'] as $value) {
|
152 |
+
$mapping_fields = array_merge($mapping_fields, $value);
|
153 |
+
}
|
154 |
+
$item_data = array();
|
155 |
+
$default_data = $this->get_default_data();
|
156 |
+
|
157 |
+
$item_data = $default_data;
|
158 |
+
|
159 |
+
if($this->merge && !$this->merge_empty_cells){
|
160 |
+
$item_data = array();
|
161 |
+
}
|
162 |
+
|
163 |
+
$item_data['id'] = $this->wt_parse_id_field($mapping_fields);
|
164 |
+
|
165 |
+
foreach ($mapping_fields as $column => $value) {
|
166 |
+
if($this->merge && !$this->merge_empty_cells && $value == ''){
|
167 |
+
continue;
|
168 |
+
}
|
169 |
+
$column = strtolower($column);
|
170 |
+
|
171 |
+
if ('status' == $column || 'post_status' == $column) {
|
172 |
+
$item_data['status'] = $this->wt_parse_status_field($value);
|
173 |
+
continue;
|
174 |
+
}
|
175 |
+
|
176 |
+
if ('code' == $column || 'post_title' == $column ) {
|
177 |
+
$item_data['code'] = ($value);
|
178 |
+
continue;
|
179 |
+
}
|
180 |
+
|
181 |
+
if ('coupon_amount' == $column) {
|
182 |
+
$item_data['amount'] = (isset($value) && !empty($value) ? wc_format_decimal($value) : '');
|
183 |
+
continue;
|
184 |
+
}
|
185 |
+
if ('post_date' == $column) {
|
186 |
+
$item_data['date_created'] = ($value);
|
187 |
+
continue;
|
188 |
+
}
|
189 |
+
if ('date_expires' == $column ) {
|
190 |
+
$item_data['date_expires'] = (isset($value) && !empty($value) ? strtotime($value) : '');
|
191 |
+
continue;
|
192 |
+
}
|
193 |
+
if ('discount_type' == $column ) {
|
194 |
+
$item_data['discount_type'] = $this->wt_parse_discount_type_field($value);
|
195 |
+
continue;
|
196 |
+
}
|
197 |
+
if ('description' == $column || 'post_excerpt' == $column ) {
|
198 |
+
$item_data['description'] = $value;
|
199 |
+
continue;
|
200 |
+
}
|
201 |
+
if ('usage_count' == $column ) {
|
202 |
+
$item_data['usage_count'] = $this->wt_parse_int_field($value);
|
203 |
+
continue;
|
204 |
+
}
|
205 |
+
if ('individual_use' == $column ) {
|
206 |
+
$item_data['individual_use'] = $value;
|
207 |
+
continue;
|
208 |
+
}
|
209 |
+
if ('product_ids' == $column || 'product_SKUs' == $column) {
|
210 |
+
$item_data['product_ids'] = $this->wt_parse_product_ids_field($value,$column);
|
211 |
+
continue;
|
212 |
+
}
|
213 |
+
if ('exclude_product_ids' == $column || 'exclude_product_SKUs' == $column ) {
|
214 |
+
$item_data['excluded_product_ids'] = $this->wt_parse_product_ids_field($value,$column);
|
215 |
+
continue;
|
216 |
+
}
|
217 |
+
if ('usage_limit' == $column ) {
|
218 |
+
$item_data['usage_limit'] = $this->wt_parse_int_field($value);
|
219 |
+
continue;
|
220 |
+
}
|
221 |
+
if ('usage_limit_per_user' == $column ) {
|
222 |
+
$item_data['usage_limit_per_user'] = $this->wt_parse_int_field($value);
|
223 |
+
continue;
|
224 |
+
}
|
225 |
+
if ('limit_usage_to_x_items' == $column ) {
|
226 |
+
$item_data['limit_usage_to_x_items'] = ($value);
|
227 |
+
continue;
|
228 |
+
}
|
229 |
+
if ('free_shipping' == $column ) {
|
230 |
+
$item_data['free_shipping'] = ($value);
|
231 |
+
continue;
|
232 |
+
}
|
233 |
+
if ('exclude_sale_items' == $column ) {
|
234 |
+
$item_data['exclude_sale_items'] = ($value);
|
235 |
+
continue;
|
236 |
+
}
|
237 |
+
if ('product_categories' == $column ) {
|
238 |
+
$item_data['product_categories'] = $this->wt_explode_values($value,',');
|
239 |
+
continue;
|
240 |
+
}
|
241 |
+
if ('exclude_product_categories' == $column) {
|
242 |
+
$item_data['excluded_product_categories'] = $this->wt_explode_values($value,',');
|
243 |
+
continue;
|
244 |
+
}
|
245 |
+
if ('minimum_amount' == $column ) {
|
246 |
+
$item_data['minimum_amount'] = (isset($value) && !empty($value) ? wc_format_decimal($value) : '');
|
247 |
+
continue;
|
248 |
+
}
|
249 |
+
if ('maximum_amount' == $column) {
|
250 |
+
$item_data['maximum_amount'] = (isset($value) && !empty($value) ? wc_format_decimal($value) : '');
|
251 |
+
continue;
|
252 |
+
}
|
253 |
+
if ('customer_email' == $column ) {
|
254 |
+
$item_data['email_restrictions'] = $this->wt_explode_values($value,',');
|
255 |
+
continue;
|
256 |
+
}
|
257 |
+
if (strstr($column, 'meta:')) {
|
258 |
+
$item_data['meta_data'][] = $this->wt_parse_meta_field($value, $column);
|
259 |
+
continue;
|
260 |
+
}
|
261 |
+
}
|
262 |
+
return $item_data;
|
263 |
+
|
264 |
+
} catch (Exception $e) {
|
265 |
+
return new WP_Error('woocommerce_product_importer_error', $e->getMessage(), array('status' => $e->getCode()));
|
266 |
+
}
|
267 |
+
|
268 |
+
}
|
269 |
+
|
270 |
+
/**
|
271 |
+
* Explode CSV cell values using commas by default, and handling escaped
|
272 |
+
* separators.
|
273 |
+
*
|
274 |
+
* @since 3.2.0
|
275 |
+
* @param string $value Value to explode.
|
276 |
+
* @param string $separator Separator separating each value. Defaults to comma.
|
277 |
+
* @return array
|
278 |
+
*/
|
279 |
+
protected function wt_explode_values($value, $separator = ',') {
|
280 |
+
|
281 |
+
if($value){
|
282 |
+
$value = str_replace('\\,', '::separator::', $value);
|
283 |
+
$values = explode($separator, $value);
|
284 |
+
$values = array_map(array($this, 'wt_explode_values_formatter'), $values);
|
285 |
+
return $values;
|
286 |
+
}
|
287 |
+
|
288 |
+
|
289 |
+
}
|
290 |
+
|
291 |
+
/**
|
292 |
+
* Remove formatting and trim each value.
|
293 |
+
*
|
294 |
+
* @since 3.2.0
|
295 |
+
* @param string $value Value to format.
|
296 |
+
* @return string
|
297 |
+
*/
|
298 |
+
protected function wt_explode_values_formatter($value) {
|
299 |
+
return trim(str_replace('::separator::', ',', $value));
|
300 |
+
}
|
301 |
+
|
302 |
+
|
303 |
+
/**
|
304 |
+
* Parse discount type.
|
305 |
+
*
|
306 |
+
* @since 3.0.0
|
307 |
+
* @param string $discount_type Discount type.
|
308 |
+
*/
|
309 |
+
public function wt_parse_discount_type_field( $discount_type ) {
|
310 |
+
if ( 'percent_product' === $discount_type ) {
|
311 |
+
$discount_type = 'percent'; // Backwards compatibility.
|
312 |
+
}
|
313 |
+
if ( ! in_array( $discount_type, array_keys( wc_get_coupon_types() ), true ) ) {
|
314 |
+
$this->error( 'coupon_invalid_discount_type', __( 'Invalid discount type', 'woocommerce' ) );
|
315 |
+
throw new Exception(sprintf('Invalid discount type. Type: %s',$discount_type ));
|
316 |
+
}
|
317 |
+
|
318 |
+
return $discount_type;
|
319 |
+
|
320 |
+
}
|
321 |
+
|
322 |
+
public function wt_parse_product_ids_field($value, $column) {
|
323 |
+
$product_ids =array();
|
324 |
+
if($this->use_sku && !empty($value)){
|
325 |
+
$prod_skus = explode("|",$value );
|
326 |
+
foreach ($prod_skus as $sku_val){
|
327 |
+
$product_ids[] = wc_get_product_id_by_sku($sku_val);
|
328 |
+
}
|
329 |
+
|
330 |
+
}else{
|
331 |
+
|
332 |
+
if(!empty($value)){
|
333 |
+
$product_ids = explode("|",$value );
|
334 |
+
}
|
335 |
+
}
|
336 |
+
return $product_ids;
|
337 |
+
}
|
338 |
+
|
339 |
+
public function wt_parse_type_field($value) {
|
340 |
+
|
341 |
+
$value = array_map('strtolower', $value);
|
342 |
+
if (!$value) {
|
343 |
+
$value = $this->post_type;
|
344 |
+
}
|
345 |
+
|
346 |
+
return $value;
|
347 |
+
}
|
348 |
+
|
349 |
+
public function wt_parse_meta_field($value, $column) {
|
350 |
+
$meta_key = trim(str_replace('meta:', '', $column));
|
351 |
+
return array('key' => $meta_key, 'value' => $value);
|
352 |
+
}
|
353 |
+
|
354 |
+
public function wt_parse_email_field($value) {
|
355 |
+
return is_email($value) ? $value : '';
|
356 |
+
}
|
357 |
+
|
358 |
+
/**
|
359 |
+
* Parse relative field and return ID.
|
360 |
+
*
|
361 |
+
* Handles `id` and Coupon code.
|
362 |
+
*
|
363 |
+
* If we're not doing an update, create a prost and return ID
|
364 |
+
* for rows following this one.
|
365 |
+
*
|
366 |
+
* @param array $data mapped data.
|
367 |
+
*
|
368 |
+
* @return int|Exception
|
369 |
+
*/
|
370 |
+
public function wt_parse_id_field($data ) {
|
371 |
+
global $wpdb;
|
372 |
+
$coupon_id = 0;
|
373 |
+
$this->is_coupon_exist = false;
|
374 |
+
|
375 |
+
$id = isset($data['ID']) && !empty($data['ID']) ? absint($data['ID']) : 0;
|
376 |
+
$id_found_with_id = '';
|
377 |
+
if($id && 'id' == $this->merge_with ){
|
378 |
+
$id_found_with_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' ) AND ID = %d;", $id)); // WPCS: db call ok, cache ok.
|
379 |
+
if($id_found_with_id){
|
380 |
+
if($this->post_type == get_post_type($id_found_with_id)){
|
381 |
+
$this->is_coupon_exist = true;
|
382 |
+
$coupon_id = $id_found_with_id;
|
383 |
+
}
|
384 |
+
}
|
385 |
+
}
|
386 |
+
|
387 |
+
$code = isset($data['post_title']) ? $data['post_title'] : '';
|
388 |
+
$id_found_with_code = '';
|
389 |
+
if(!empty($code && 'code' == $this->merge_with)){
|
390 |
+
$post_db_type = $this->post_type;
|
391 |
+
$post_pass_type = '"'.$post_db_type.'"';
|
392 |
+
$db_query = $wpdb->prepare("
|
393 |
+
SELECT $wpdb->posts.ID
|
394 |
+
FROM $wpdb->posts
|
395 |
+
WHERE $wpdb->posts.post_type = $post_pass_type
|
396 |
+
AND $wpdb->posts.post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )
|
397 |
+
AND $wpdb->posts.post_title = '%s'
|
398 |
+
", $code);
|
399 |
+
$id_found_with_code = $wpdb->get_var($db_query);
|
400 |
+
$this->is_coupon_exist = true;
|
401 |
+
$coupon_id = $id_found_with_code;
|
402 |
+
}
|
403 |
+
|
404 |
+
if($this->is_coupon_exist){
|
405 |
+
if('skip' == $this->found_action){
|
406 |
+
if($id && $id_found_with_id ){
|
407 |
+
throw new Exception(sprintf('Coupon with same ID already exists. ID: %d',$id ));
|
408 |
+
}elseif($code && $id_found_with_code ){
|
409 |
+
throw new Exception(sprintf('%s with same Code already exists. Code: %s',ucfirst($this->parent_module->module_base),$code ));
|
410 |
+
}else{
|
411 |
+
throw new Exception('Coupon already exists.');
|
412 |
+
}
|
413 |
+
}elseif('update' == $this->found_action){
|
414 |
+
$this->merge = true;
|
415 |
+
return $coupon_id;
|
416 |
+
}
|
417 |
+
}
|
418 |
+
|
419 |
+
if($this->skip_new){
|
420 |
+
throw new Exception('Skipping new item' );
|
421 |
+
}
|
422 |
+
|
423 |
+
if($id && $id_found_with_id && !$this->is_coupon_exist && 'skip' == $this->id_conflict){
|
424 |
+
throw new Exception(sprintf('Importing Coupon(ID) conflicts with an existing post. ID: %d',$id ));
|
425 |
+
}
|
426 |
+
|
427 |
+
if(empty($code)){
|
428 |
+
throw new Exception(sprintf('Cannot insert without %s Code', ucfirst($this->parent_module->module_base)) );
|
429 |
+
}
|
430 |
+
|
431 |
+
$postdata = array( // if not specifiying id (id is empty) or if not found by given id or coupon
|
432 |
+
'post_title' => $code,
|
433 |
+
'post_status' => 'importing',
|
434 |
+
'post_type' => $this->post_type,
|
435 |
+
);
|
436 |
+
if(isset($id) && !empty($id)){
|
437 |
+
$postdata['import_id'] = $id;
|
438 |
+
}
|
439 |
+
$post_id = wp_insert_post( $postdata, true );
|
440 |
+
if($post_id && !is_wp_error($post_id)){
|
441 |
+
Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', sprintf('Importing as new '. ($this->parent_module->module_base).' ID:%d',$post_id ));
|
442 |
+
return $post_id;
|
443 |
+
}else{
|
444 |
+
throw new Exception($post_id->get_error_message());
|
445 |
+
}
|
446 |
+
|
447 |
+
}
|
448 |
+
|
449 |
+
public function wt_parse_id_field_old($data ) {
|
450 |
+
global $wpdb;
|
451 |
+
|
452 |
+
$id = isset($data['ID']) && !empty($data['ID']) ? absint($data['ID']) : 0;
|
453 |
+
$id_found_with_id = '';
|
454 |
+
if($id){
|
455 |
+
$id_found_with_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' ) AND ID = %d;", $id)); // WPCS: db call ok, cache ok.
|
456 |
+
if($id_found_with_id){
|
457 |
+
if($this->post_type == get_post_type($id_found_with_id)){
|
458 |
+
$this->is_coupon_exist = true;
|
459 |
+
}
|
460 |
+
}
|
461 |
+
}
|
462 |
+
|
463 |
+
$code = isset($data['post_title']) ? $data['post_title'] : '';
|
464 |
+
$id_found_with_code = '';
|
465 |
+
if(!empty($code)){
|
466 |
+
$post_db_type = $this->post_type;
|
467 |
+
$post_pass_type = '"'.$post_db_type.'"';
|
468 |
+
$db_query = $wpdb->prepare("
|
469 |
+
SELECT $wpdb->posts.ID
|
470 |
+
FROM $wpdb->posts
|
471 |
+
WHERE $wpdb->posts.post_type = $post_pass_type
|
472 |
+
AND $wpdb->posts.post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )
|
473 |
+
AND $wpdb->posts.post_title = '%s'
|
474 |
+
", $code);
|
475 |
+
$id_found_with_code = $wpdb->get_var($db_query);
|
476 |
+
}
|
477 |
+
|
478 |
+
if( !$this->merge ){
|
479 |
+
|
480 |
+
if(empty($code)){
|
481 |
+
throw new Exception(sprintf('Cannot insert without %s Code', ucfirst($this->parent_module->module_base)) );
|
482 |
+
}
|
483 |
+
|
484 |
+
if('skip' == $this->found_action){ // skip if found
|
485 |
+
|
486 |
+
if($id && $id_found_with_id && $this->is_coupon_exist){
|
487 |
+
throw new Exception(sprintf('Coupon with same ID already exists. ID: %d',$id ));
|
488 |
+
}elseif($id && $id_found_with_id && !$this->is_coupon_exist){
|
489 |
+
throw new Exception(sprintf('Importing %s(ID) conflicts with an existing post. ID: %d',ucfirst($this->parent_module->module_base),$id ));
|
490 |
+
}elseif($code && $id_found_with_code){
|
491 |
+
throw new Exception(sprintf('%s with same Code already exists. Code: %s',ucfirst($this->parent_module->module_base),$code ));
|
492 |
+
}
|
493 |
+
|
494 |
+
|
495 |
+
$postdata = array( // if not specifiying id (id is empty) or if not found by given id or coupon
|
496 |
+
'post_title' => $code,
|
497 |
+
'post_status' => 'importing',
|
498 |
+
'post_type' => $this->post_type,
|
499 |
+
);
|
500 |
+
if(isset($id) && !empty($id)){
|
501 |
+
$postdata['import_id'] = $id;
|
502 |
+
}
|
503 |
+
$post_id = wp_insert_post( $postdata, true );
|
504 |
+
if($post_id && !is_wp_error($post_id)){
|
505 |
+
$post = get_post($post_id);
|
506 |
+
return $post_id;
|
507 |
+
}else{
|
508 |
+
throw new Exception($post_id->get_error_message());
|
509 |
+
}
|
510 |
+
|
511 |
+
throw new Exception('fasil !merge, found_action skip');
|
512 |
+
|
513 |
+
}elseif('import' == $this->found_action){ // import if not found
|
514 |
+
|
515 |
+
if($id && $id_found_with_id && $this->is_coupon_exist){
|
516 |
+
throw new Exception(sprintf('%s with same ID already exists. ID: %d',ucfirst($this->parent_module->module_base),$id ));
|
517 |
+
}elseif($id && $id_found_with_id && !$this->is_coupon_exist && $this->use_same_id ){
|
518 |
+
throw new Exception(sprintf('Importing %s(ID) conflicts with an existing post. ID: %d',ucfirst($this->parent_module->module_base),$id ));
|
519 |
+
}elseif($code && $id_found_with_code){
|
520 |
+
throw new Exception(sprintf('%s with same Code already exists. Code: %s',ucfirst($this->parent_module->module_base),$code ));
|
521 |
+
}
|
522 |
+
|
523 |
+
|
524 |
+
$postdata = array( // try to import
|
525 |
+
'post_title' => $code,
|
526 |
+
'post_status' => 'importing',
|
527 |
+
'post_type' => $this->post_type,
|
528 |
+
);
|
529 |
+
if(isset($id) && !empty($id)){
|
530 |
+
$postdata['import_id'] = $id;
|
531 |
+
}
|
532 |
+
$post_id = wp_insert_post( $postdata, true );
|
533 |
+
if($post_id && !is_wp_error($post_id)){
|
534 |
+
return $post_id;
|
535 |
+
}else{
|
536 |
+
throw new Exception($post_id->get_error_message());
|
537 |
+
}
|
538 |
+
}
|
539 |
+
|
540 |
+
|
541 |
+
}elseif($this->merge){
|
542 |
+
|
543 |
+
if(empty($id) && empty($code)){
|
544 |
+
throw new Exception(sprintf('Cannot update/insert without ID and %s Code',ucfirst($this->parent_module->module_base)) );
|
545 |
+
}
|
546 |
+
|
547 |
+
if('id' == $this->merge_with){
|
548 |
+
|
549 |
+
if('skip' == $this->found_action){ // skip if not found or update
|
550 |
+
|
551 |
+
if($id && $id_found_with_id && $this->is_coupon_exist){ //found coupon by id
|
552 |
+
return $id; // update
|
553 |
+
}elseif($id && $id_found_with_id && !$this->is_coupon_exist){ // found an item by id ,but not a coupon
|
554 |
+
throw new Exception(sprintf('Importing %s(ID) conflicts with an existing post. ID: %d',ucfirst($this->parent_module->module_base),$id ));
|
555 |
+
}elseif(($id && !$id_found_with_id) || !$id){
|
556 |
+
throw new Exception(sprintf('Cannot find %s with given ID %d',ucfirst($this->parent_module->module_base),$id ));
|
557 |
+
}elseif($code && $id_found_with_code){
|
558 |
+
throw new Exception(sprintf('%s with same Code already exists. Code: %s',ucfirst($this->parent_module->module_base),$code ));
|
559 |
+
}
|
560 |
+
|
561 |
+
if(empty($code)){
|
562 |
+
throw new Exception(sprintf('Cannot insert without %s Code',ucfirst($this->parent_module->module_base)) );
|
563 |
+
}
|
564 |
+
if($this->skip_new){
|
565 |
+
throw new Exception('Skipping new item' );
|
566 |
+
}
|
567 |
+
$postdata = array(
|
568 |
+
'post_title' => $code,
|
569 |
+
'post_status' => 'importing',
|
570 |
+
'post_type' => $this->post_type,
|
571 |
+
);
|
572 |
+
if(isset($id) && !empty($id)){
|
573 |
+
$postdata['import_id'] = $id;
|
574 |
+
}
|
575 |
+
$post_id = wp_insert_post( $postdata, true );
|
576 |
+
if($post_id && !is_wp_error($post_id)){
|
577 |
+
return $post_id;
|
578 |
+
}else{
|
579 |
+
throw new Exception($post_id->get_error_message());
|
580 |
+
}
|
581 |
+
|
582 |
+
|
583 |
+
}elseif('import' == $this->found_action){ // import if not found
|
584 |
+
if($id && $id_found_with_id && $this->is_coupon_exist){ //found coupon by id
|
585 |
+
return $id; // update
|
586 |
+
}elseif($id && $id_found_with_id && !$this->is_coupon_exist && $this->use_same_id ){ // found an item by id ,but not a coupon, but should use the same id
|
587 |
+
throw new Exception(sprintf('Importing %s(ID) conflicts with an existing post. ID: %d',ucfirst($this->parent_module->module_base),$id ));
|
588 |
+
}elseif($code && $id_found_with_code){
|
589 |
+
throw new Exception(sprintf('%s with same Code already exists. Code: %s',ucfirst($this->parent_module->module_base),$code ));
|
590 |
+
}
|
591 |
+
|
592 |
+
if(empty($code)){
|
593 |
+
throw new Exception(sprintf('Cannot insert without %s Code',ucfirst($this->parent_module->module_base)) );
|
594 |
+
}
|
595 |
+
if($this->skip_new){
|
596 |
+
throw new Exception('Skipping new item' );
|
597 |
+
}
|
598 |
+
$postdata = array(
|
599 |
+
'post_title' => $code,
|
600 |
+
'post_status' => 'importing',
|
601 |
+
'post_type' => $this->post_type,
|
602 |
+
);
|
603 |
+
if(isset($id) && !empty($id)){
|
604 |
+
$postdata['import_id'] = $id;
|
605 |
+
}
|
606 |
+
$post_id = wp_insert_post( $postdata, true );
|
607 |
+
if($post_id && !is_wp_error($post_id)){
|
608 |
+
return $post_id;
|
609 |
+
}else{
|
610 |
+
throw new Exception($post_id->get_error_message());
|
611 |
+
}
|
612 |
+
}
|
613 |
+
|
614 |
+
}elseif('coupon_code' == $this->merge_with){
|
615 |
+
if(empty($code)){
|
616 |
+
throw new Exception(sprintf('Cannot update/insert without %s Code',ucfirst($this->parent_module->module_base)) );
|
617 |
+
}
|
618 |
+
|
619 |
+
if('skip' == $this->found_action){ // skip if not found
|
620 |
+
|
621 |
+
if($code && $id_found_with_code ){ // found coupon by Code
|
622 |
+
return $id_found_with_code; // update
|
623 |
+
}elseif($code && !$id_found_with_code ){ // found an item by id ,but not a coupon
|
624 |
+
throw new Exception(sprintf('Cannot find %s with given Coupon Code %s',ucfirst($this->parent_module->module_base),$code ));
|
625 |
+
}
|
626 |
+
throw new Exception('fasil, merge, merge_with coupon_code, found_action skip');
|
627 |
+
|
628 |
+
}elseif('import' == $this->found_action){ // import as new if not found
|
629 |
+
if($code && $id_found_with_code ){ // found coupon by Code
|
630 |
+
return $id_found_with_code; // update
|
631 |
+
}elseif($id && $id_found_with_id && !$this->is_coupon_exist && $this->use_same_id ){ // the given id is already used by other post
|
632 |
+
throw new Exception(sprintf('Importing %s(ID) conflicts with an existing post. ID: %d',ucfirst($this->parent_module->module_base),$id ));
|
633 |
+
}elseif($id && $id_found_with_id && $this->is_coupon_exist && $this->use_same_id ){ // the given id is already used by othere coupon
|
634 |
+
throw new Exception(sprintf('%s with same ID already exists. ID: %d',ucfirst($this->parent_module->module_base),$id ));
|
635 |
+
}
|
636 |
+
|
637 |
+
if($this->skip_new){
|
638 |
+
throw new Exception('Skipping new item' );
|
639 |
+
}
|
640 |
+
$postdata = array(
|
641 |
+
'post_title' => $code,
|
642 |
+
'post_status' => 'importing',
|
643 |
+
'post_type' => $this->post_type,
|
644 |
+
);
|
645 |
+
if(isset($id) && !empty($id)){
|
646 |
+
$postdata['import_id'] = $id;
|
647 |
+
}
|
648 |
+
$post_id = wp_insert_post( $postdata, true );
|
649 |
+
if($post_id && !is_wp_error($post_id)){
|
650 |
+
return $post_id;
|
651 |
+
}else{
|
652 |
+
throw new Exception($post_id->get_error_message());
|
653 |
+
}
|
654 |
+
}
|
655 |
+
}
|
656 |
+
}
|
657 |
+
|
658 |
+
}
|
659 |
+
|
660 |
+
|
661 |
+
/**
|
662 |
+
* Parse relative comma-delineated field and return product ID.
|
663 |
+
*
|
664 |
+
* @param string $value Field value.
|
665 |
+
*
|
666 |
+
* @return array
|
667 |
+
*/
|
668 |
+
public function wt_parse_relative_comma_field($value) {
|
669 |
+
if (empty($value)) {
|
670 |
+
return array();
|
671 |
+
}
|
672 |
+
|
673 |
+
return array_filter(array_map(array($this, 'wt_parse_relative_field'), $this->wt_explode_values($value)));
|
674 |
+
}
|
675 |
+
|
676 |
+
/**
|
677 |
+
* Parse a comma-delineated field from a CSV.
|
678 |
+
*
|
679 |
+
* @param string $value Field value.
|
680 |
+
*
|
681 |
+
* @return array
|
682 |
+
*/
|
683 |
+
public function parse_comma_field($value) {
|
684 |
+
if (empty($value) && '0' !== $value) {
|
685 |
+
return array();
|
686 |
+
}
|
687 |
+
|
688 |
+
$value = $this->unescape_data($value);
|
689 |
+
return array_map('wc_clean', $this->wt_explode_values($value));
|
690 |
+
}
|
691 |
+
|
692 |
+
/**
|
693 |
+
* Parse a field that is generally '1' or '0' but can be something else.
|
694 |
+
*
|
695 |
+
* @param string $value Field value.
|
696 |
+
*
|
697 |
+
* @return bool|string
|
698 |
+
*/
|
699 |
+
public function wt_parse_bool_field($value) {
|
700 |
+
if ('0' === $value) {
|
701 |
+
return false;
|
702 |
+
}
|
703 |
+
|
704 |
+
if ('1' === $value) {
|
705 |
+
return true;
|
706 |
+
}
|
707 |
+
|
708 |
+
// Don't return explicit true or false for empty fields or values like 'notify'.
|
709 |
+
return wc_clean($value);
|
710 |
+
}
|
711 |
+
|
712 |
+
|
713 |
+
/**
|
714 |
+
* Parse an int value field
|
715 |
+
*
|
716 |
+
* @param int $value field value.
|
717 |
+
*
|
718 |
+
* @return int
|
719 |
+
*/
|
720 |
+
public function wt_parse_int_field($value) {
|
721 |
+
// Remove the ' prepended to fields that start with - if needed.
|
722 |
+
// $value = $this->unescape_data( $value );
|
723 |
+
|
724 |
+
return intval($value);
|
725 |
+
}
|
726 |
+
|
727 |
+
/**
|
728 |
+
* Parse the published field. 1 is published, 0 is private, -1 is draft.
|
729 |
+
* Alternatively, 'true' can be used for published and 'false' for draft.
|
730 |
+
*
|
731 |
+
* @param string $value Field value.
|
732 |
+
*
|
733 |
+
* @return float|string
|
734 |
+
*/
|
735 |
+
public function wt_parse_status_field($value) {
|
736 |
+
|
737 |
+
$post_status = array('publish', 'private', 'draft', 'pending', 'future', 'trash' );
|
738 |
+
|
739 |
+
$found_status = false;
|
740 |
+
|
741 |
+
foreach ($post_status as $status_name) {
|
742 |
+
if (0 == strcasecmp($status_name, $value))
|
743 |
+
$found_status = true;
|
744 |
+
}
|
745 |
+
|
746 |
+
if ($found_status) {
|
747 |
+
return $value;
|
748 |
+
}else{
|
749 |
+
return 'draft';
|
750 |
+
}
|
751 |
+
|
752 |
+
}
|
753 |
+
|
754 |
+
|
755 |
+
public function get_default_data() {
|
756 |
+
|
757 |
+
return array(
|
758 |
+
// 'id' => 0,
|
759 |
+
'code' => '',
|
760 |
+
'amount' => 0,
|
761 |
+
'date_created' => null,
|
762 |
+
'date_modified' => null,
|
763 |
+
'date_expires' => null,
|
764 |
+
'discount_type' => 'fixed_cart',
|
765 |
+
'description' => '',
|
766 |
+
'usage_count' => 0,
|
767 |
+
'individual_use' => false,
|
768 |
+
'product_ids' => array(),
|
769 |
+
'excluded_product_ids' => array(),
|
770 |
+
'usage_limit' => 0,
|
771 |
+
'usage_limit_per_user' => 0,
|
772 |
+
'limit_usage_to_x_items' => null,
|
773 |
+
'free_shipping' => false,
|
774 |
+
'product_categories' => array(),
|
775 |
+
'excluded_product_categories' => array(),
|
776 |
+
'exclude_sale_items' => false,
|
777 |
+
'minimum_amount' => '',
|
778 |
+
'maximum_amount' => '',
|
779 |
+
'email_restrictions' => array(),
|
780 |
+
'used_by' => array(),
|
781 |
+
'virtual' => false,
|
782 |
+
);
|
783 |
+
}
|
784 |
+
|
785 |
+
public function process_item($data) {
|
786 |
+
try {
|
787 |
+
do_action('wt_woocommerce_coupon_import_before_process_item', $data);
|
788 |
+
$data = apply_filters('wt_woocommerce_coupon_import_process_item', $data);
|
789 |
+
|
790 |
+
$post_id = $data['id'];
|
791 |
+
$object = new WC_Coupon($post_id);
|
792 |
+
|
793 |
+
// $object = $this->get_object($data);
|
794 |
+
|
795 |
+
if (is_wp_error($object)) {
|
796 |
+
return $object;
|
797 |
+
}
|
798 |
+
|
799 |
+
Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Found coupon object. ID:".$object->get_id());
|
800 |
+
|
801 |
+
foreach ($data as $key => $value) {
|
802 |
+
if(!empty($value)){
|
803 |
+
$fn ='set_'.$key;
|
804 |
+
if(method_exists($object,'set_'.$key)){
|
805 |
+
$object->$fn($value);
|
806 |
+
// unset($data[$key]);
|
807 |
+
}
|
808 |
+
}
|
809 |
+
}
|
810 |
+
|
811 |
+
$this->set_meta_data($object, $data);
|
812 |
+
|
813 |
+
$update_post = array(
|
814 |
+
'ID' => $post_id,
|
815 |
+
'post_status' => $data['status'],
|
816 |
+
);
|
817 |
+
wp_update_post($update_post);
|
818 |
+
|
819 |
+
if($this->delete_existing){
|
820 |
+
update_post_meta($post_id, '_wt_delete_existing', 1);
|
821 |
+
}
|
822 |
+
|
823 |
+
$object = apply_filters('wt_woocommerce_import_pre_insert_coupon_object', $object, $data);
|
824 |
+
$object->save();
|
825 |
+
|
826 |
+
do_action('wt_woocommerce_import_inserted_coupon_object', $object, $data);
|
827 |
+
|
828 |
+
$result = array(
|
829 |
+
'id' => $object->get_id(),
|
830 |
+
'updated' => $this->merge,
|
831 |
+
);
|
832 |
+
return $result;
|
833 |
+
} catch (Exception $e) {
|
834 |
+
return new WP_Error('woocommerce_product_importer_error', $e->getMessage(), array('status' => $e->getCode()));
|
835 |
+
}
|
836 |
+
}
|
837 |
+
function get_object($data) {
|
838 |
+
$id = isset($data['id']) ? absint($data['id']) : 0;
|
839 |
+
|
840 |
+
// Type is the most important part here because we need to be using the correct class and methods.
|
841 |
+
if (isset($data['type'])) {
|
842 |
+
$types = array_keys(wc_get_product_types());
|
843 |
+
$types[] = 'variation';
|
844 |
+
|
845 |
+
if (!in_array($data['type'], $types, true)) {
|
846 |
+
return new WP_Error('woocommerce_product_importer_invalid_type', __('Invalid product type.', 'woocommerce'), array('status' => 401));
|
847 |
+
}
|
848 |
+
|
849 |
+
try {
|
850 |
+
// Prevent getting "variation_invalid_id" error message from Variation Data Store.
|
851 |
+
if ('variation' === $data['type']) {
|
852 |
+
$id = wp_update_post(
|
853 |
+
array(
|
854 |
+
'ID' => $id,
|
855 |
+
'post_type' => 'product_variation',
|
856 |
+
)
|
857 |
+
);
|
858 |
+
}
|
859 |
+
|
860 |
+
$product = wc_get_product_object($data['type'], $id);
|
861 |
+
} catch (WC_Data_Exception $e) {
|
862 |
+
return new WP_Error('woocommerce_product_csv_importer_' . $e->getErrorCode(), $e->getMessage(), array('status' => 401));
|
863 |
+
}
|
864 |
+
} elseif (!empty($data['id'])) {
|
865 |
+
$product = wc_get_product($id);
|
866 |
+
|
867 |
+
if (!$product) {
|
868 |
+
return new WP_Error(
|
869 |
+
'woocommerce_product_csv_importer_invalid_id',
|
870 |
+
/* translators: %d: product ID */ sprintf(__('Invalid product ID %d.', 'woocommerce'), $id), array(
|
871 |
+
'id' => $id,
|
872 |
+
'status' => 401,
|
873 |
+
)
|
874 |
+
);
|
875 |
+
}
|
876 |
+
} else {
|
877 |
+
$product = wc_get_product_object('simple', $id);
|
878 |
+
}
|
879 |
+
|
880 |
+
return apply_filters('wt_woocommerce_order_import_get_product_object', $product, $data);
|
881 |
+
}
|
882 |
+
|
883 |
+
function set_meta_data(&$object, $data) {
|
884 |
+
if (isset($data['meta_data'])) {
|
885 |
+
foreach ($data['meta_data'] as $meta) {
|
886 |
+
$object->update_meta_data($meta['key'], $meta['value']);
|
887 |
+
}
|
888 |
+
}
|
889 |
+
}
|
890 |
+
|
891 |
+
|
892 |
+
}
|
893 |
+
}
|
admin/modules/export/assets/js/main.js
ADDED
@@ -0,0 +1,906 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var wt_iew_basic_export=(function( $ ) {
|
2 |
+
//'use strict';
|
3 |
+
var wt_iew_basic_export=
|
4 |
+
{
|
5 |
+
ajax_data:{},
|
6 |
+
selected_template:0,
|
7 |
+
selected_template_name:'',
|
8 |
+
to_export:'',
|
9 |
+
to_export_title:'',
|
10 |
+
export_method:'',
|
11 |
+
current_step:'',
|
12 |
+
loaded_status_arr:{'loaded':1, 'loading':2, 'not_loaded':0},
|
13 |
+
page_overlay:false,
|
14 |
+
step_keys:[],
|
15 |
+
form_data:{},
|
16 |
+
only_enabled_data:false,
|
17 |
+
on_rerun:false,
|
18 |
+
rerun_id:0,
|
19 |
+
Set:function()
|
20 |
+
{
|
21 |
+
this.step_keys=Object.keys(wt_iew_export_basic_params.steps);
|
22 |
+
if(this.on_rerun)
|
23 |
+
{
|
24 |
+
this.rerun();
|
25 |
+
}else
|
26 |
+
{
|
27 |
+
var first_step=this.step_keys[0];
|
28 |
+
this.load_steps([first_step], first_step);
|
29 |
+
this.show_step_page(first_step, false); /* just to show a loading */
|
30 |
+
}
|
31 |
+
},
|
32 |
+
rerun:function()
|
33 |
+
{
|
34 |
+
var last_step=this.step_keys[this.step_keys.length-1];
|
35 |
+
this.load_steps(this.step_keys, last_step);
|
36 |
+
this.show_step_page(last_step, false); /* just to show a loading */
|
37 |
+
},
|
38 |
+
load_steps:function(steps, step_to_show)
|
39 |
+
{
|
40 |
+
this.prepare_ajax_data('get_steps', 'json');
|
41 |
+
this.ajax_data.steps=steps;
|
42 |
+
if(this.on_rerun)
|
43 |
+
{
|
44 |
+
this.ajax_data.rerun_id=this.rerun_id;
|
45 |
+
}
|
46 |
+
this.set_step_loading_status(steps, 'loading');
|
47 |
+
this.set_ajax_page_loader(steps, 'loading');
|
48 |
+
$.ajax({
|
49 |
+
type: 'POST',
|
50 |
+
url:wt_iew_basic_params.ajax_url,
|
51 |
+
data:this.ajax_data,
|
52 |
+
dataType:'json',
|
53 |
+
success:function(data)
|
54 |
+
{
|
55 |
+
if(data.status==1)
|
56 |
+
{
|
57 |
+
wt_iew_basic_export.set_step_page(data);
|
58 |
+
wt_iew_basic_export.set_step_loading_status(steps, 'loaded');
|
59 |
+
if(step_to_show)
|
60 |
+
{
|
61 |
+
wt_iew_basic_export.show_step_page(step_to_show, true);
|
62 |
+
}
|
63 |
+
if(wt_iew_basic_export.on_rerun)
|
64 |
+
{
|
65 |
+
wt_iew_basic_export.load_meta_mapping_fields();
|
66 |
+
wt_iew_basic_export.on_rerun=false;
|
67 |
+
wt_iew_basic_export.rerun_id=0;
|
68 |
+
}
|
69 |
+
}else
|
70 |
+
{
|
71 |
+
// wt_iew_basic_import.set_step_loading_status(steps, 'not_loaded');
|
72 |
+
wt_iew_basic_export.set_step_loading_status(steps, 'not_loaded');
|
73 |
+
wt_iew_basic_export.set_ajax_page_loader(steps, 'error');
|
74 |
+
}
|
75 |
+
wt_iew_basic_export.remove_ajax_page_loader();
|
76 |
+
},
|
77 |
+
error:function()
|
78 |
+
{
|
79 |
+
// wt_iew_basic_import.set_step_loading_status(steps, 'not_loaded');
|
80 |
+
wt_iew_basic_export.set_step_loading_status(steps, 'not_loaded');
|
81 |
+
wt_iew_basic_export.remove_ajax_page_loader();
|
82 |
+
wt_iew_basic_export.set_ajax_page_loader(steps, 'error');
|
83 |
+
}
|
84 |
+
});
|
85 |
+
},
|
86 |
+
load_meta_mapping_fields:function()
|
87 |
+
{
|
88 |
+
if($('.meta_mapping_box_con').length>0)
|
89 |
+
{
|
90 |
+
if($('.meta_mapping_box_con[data-loaded="0"]').length==0)
|
91 |
+
{
|
92 |
+
return false;
|
93 |
+
}
|
94 |
+
}else
|
95 |
+
{
|
96 |
+
return false;
|
97 |
+
}
|
98 |
+
|
99 |
+
this.prepare_ajax_data('get_meta_mapping_fields', 'json');
|
100 |
+
$('.meta_mapping_box_con[data-loaded="0"]').html('<div class="wt_iew_export_step_loader">'+wt_iew_basic_params.msgs.loading+'</div>');
|
101 |
+
$.ajax({
|
102 |
+
type: 'POST',
|
103 |
+
url:wt_iew_basic_params.ajax_url,
|
104 |
+
data:this.ajax_data,
|
105 |
+
dataType:'json',
|
106 |
+
success:function(data)
|
107 |
+
{
|
108 |
+
if(data.status==1)
|
109 |
+
{
|
110 |
+
$.each(data.meta_html, function(meta_id, meta_content){
|
111 |
+
$('.meta_mapping_box_con[data-key="'+meta_id+'"]').html(meta_content).attr('data-loaded', 1);
|
112 |
+
});
|
113 |
+
wt_iew_basic_export.enable_sortable();
|
114 |
+
wt_iew_basic_export.reg_mapping_field_bulk_action();
|
115 |
+
}else
|
116 |
+
{
|
117 |
+
$('.meta_mapping_box_con[data-loaded="0"]').html('<div class="wt_iew_export_step_loader">'+wt_iew_basic_params.msgs.error+'</div>');
|
118 |
+
}
|
119 |
+
},
|
120 |
+
error:function()
|
121 |
+
{
|
122 |
+
$('.meta_mapping_box_con[data-loaded="0"]').html('<div class="wt_iew_export_step_loader">'+wt_iew_basic_params.msgs.loading+'</div>');
|
123 |
+
}
|
124 |
+
});
|
125 |
+
},
|
126 |
+
console_formdata:function()
|
127 |
+
{
|
128 |
+
console.log(this.form_data);
|
129 |
+
},
|
130 |
+
refresh_step:function(no_overlay)
|
131 |
+
{
|
132 |
+
if(!no_overlay){
|
133 |
+
this.page_overlay=true;
|
134 |
+
}
|
135 |
+
this.load_steps([this.current_step], this.current_step);
|
136 |
+
},
|
137 |
+
load_pending_steps:function(no_overlay)
|
138 |
+
{
|
139 |
+
if(!no_overlay){
|
140 |
+
this.page_overlay=true;
|
141 |
+
}
|
142 |
+
var rest_steps=this.step_keys.slice(0);
|
143 |
+
rest_steps.shift(); /* remove first step. no need to load it agian */
|
144 |
+
this.load_steps(rest_steps, this.current_step);
|
145 |
+
},
|
146 |
+
get_page_dom_object:function(step)
|
147 |
+
{
|
148 |
+
return $('.wt_iew_export_step_'+step);
|
149 |
+
},
|
150 |
+
remove_ajax_page_loader:function()
|
151 |
+
{
|
152 |
+
$('.wt_iew_loader_info_box').hide();
|
153 |
+
$('.wt_iew_overlayed_loader').hide();
|
154 |
+
$('.spinner').css({'visibility':'hidden'});
|
155 |
+
this.page_overlay=false;
|
156 |
+
},
|
157 |
+
set_ajax_page_loader:function(steps, msg_type)
|
158 |
+
{
|
159 |
+
if(this.page_overlay)
|
160 |
+
{
|
161 |
+
var h=parseInt($('.wt_iew_export_step_main').outerHeight());
|
162 |
+
var w=parseInt($('.wt_iew_export_step_main').outerWidth());
|
163 |
+
$('.wt_iew_overlayed_loader').show().css({'height':h,'width':w,'margin-top':'30px','margin-left':'30px'});
|
164 |
+
$('.spinner').css({'visibility':'visible'});
|
165 |
+
}else
|
166 |
+
{
|
167 |
+
var msg='';
|
168 |
+
if(msg_type=='loading')
|
169 |
+
{
|
170 |
+
msg=wt_iew_basic_params.msgs.loading;
|
171 |
+
}else if(msg_type=='error')
|
172 |
+
{
|
173 |
+
msg=wt_iew_basic_params.msgs.error;
|
174 |
+
}
|
175 |
+
$.each(steps, function(step_ind, step){
|
176 |
+
wt_iew_basic_export.get_page_dom_object(step).html('<div class="wt_iew_export_step_loader">'+msg+'</div>');
|
177 |
+
});
|
178 |
+
}
|
179 |
+
},
|
180 |
+
hide_export_info_box:function()
|
181 |
+
{
|
182 |
+
$('.wt_iew_loader_info_box').hide();
|
183 |
+
},
|
184 |
+
set_export_progress_info:function(msg)
|
185 |
+
{
|
186 |
+
$('.wt_iew_loader_info_box').show().html(msg);
|
187 |
+
},
|
188 |
+
nonstep_actions:function(action)
|
189 |
+
{
|
190 |
+
if(this.export_method=='template' && this.selected_template==0)
|
191 |
+
{
|
192 |
+
$('.wt_iew_warn').hide();
|
193 |
+
$('.wt_iew_export_template_wrn').show();
|
194 |
+
return false;
|
195 |
+
}
|
196 |
+
|
197 |
+
this.prepare_ajax_data(action, 'json');
|
198 |
+
|
199 |
+
if(action=='save_template' || action=='save_template_as' || action=='update_template')
|
200 |
+
{
|
201 |
+
$('.wt_iew_template_name_wrn').hide();
|
202 |
+
var pop_elm=$('.wt_iew_template_name');
|
203 |
+
var popup_label=pop_elm.attr('data-save-label');
|
204 |
+
if(action=='save_template_as')
|
205 |
+
{
|
206 |
+
var popup_label=pop_elm.attr('data-saveas-label');
|
207 |
+
}
|
208 |
+
pop_elm.find('.wt_iew_popup_hd_label, .wt_iew_template_create_btn').text(popup_label);
|
209 |
+
wt_iew_popup.showPopup(pop_elm);
|
210 |
+
$('[name="wt_iew_template_name_field"]').val(this.selected_template_name).focus();
|
211 |
+
|
212 |
+
$('.wt_iew_template_create_btn').unbind('click').click(function(){
|
213 |
+
var name=$.trim($('.wt_iew_template_name_field').val());
|
214 |
+
if(name=='')
|
215 |
+
{
|
216 |
+
$('.wt_iew_template_name_wrn').show();
|
217 |
+
$('.wt_iew_template_name_field').focus();
|
218 |
+
}else
|
219 |
+
{
|
220 |
+
$('.wt_iew_template_name_wrn').hide();
|
221 |
+
wt_iew_popup.hidePopup();
|
222 |
+
|
223 |
+
wt_iew_basic_export.prepare_form_data();
|
224 |
+
wt_iew_basic_export.ajax_data['template_name']=name;
|
225 |
+
wt_iew_basic_export.ajax_data['form_data']=wt_iew_basic_export.form_data;
|
226 |
+
wt_iew_basic_export.do_nonstep_action(action);
|
227 |
+
}
|
228 |
+
});
|
229 |
+
}else if(action=='export' || action=='upload' || action=='export_image')
|
230 |
+
{
|
231 |
+
if(action=='export' || action=='export_image')
|
232 |
+
{
|
233 |
+
this.ajax_data['offset']=0;
|
234 |
+
this.prepare_form_data();
|
235 |
+
this.ajax_data['form_data']=this.form_data;
|
236 |
+
}
|
237 |
+
wt_iew_basic_export.do_nonstep_action(action);
|
238 |
+
}else
|
239 |
+
{
|
240 |
+
/* custom action section for other modules */
|
241 |
+
this.prepare_form_data();
|
242 |
+
this.ajax_data['form_data']=this.form_data;
|
243 |
+
wt_iew_custom_action_basic(this.ajax_data, action, this.selected_template);
|
244 |
+
}
|
245 |
+
},
|
246 |
+
do_nonstep_action:function(action)
|
247 |
+
{
|
248 |
+
this.page_overlay=true;
|
249 |
+
this.set_ajax_page_loader();
|
250 |
+
$.ajax({
|
251 |
+
type: 'POST',
|
252 |
+
url:wt_iew_basic_params.ajax_url,
|
253 |
+
data:this.ajax_data,
|
254 |
+
dataType:'json',
|
255 |
+
success:function(data)
|
256 |
+
{
|
257 |
+
wt_iew_basic_export.remove_ajax_page_loader();
|
258 |
+
if(data.status==1)
|
259 |
+
{
|
260 |
+
if(action=='save_template' || action=='save_template_as' || action=='update_template')
|
261 |
+
{
|
262 |
+
wt_iew_basic_export.selected_template=data.id;
|
263 |
+
wt_iew_basic_export.selected_template_name=data.name;
|
264 |
+
wt_iew_notify_msg.success(data.msg);
|
265 |
+
//wt_iew_notify_msg.success(wt_iew_basic_params.msgs.success);
|
266 |
+
|
267 |
+
}else if(action=='export' || action=='upload' || action=='export_image')
|
268 |
+
{
|
269 |
+
if(data.finished==1)
|
270 |
+
{
|
271 |
+
wt_iew_basic_export.set_export_progress_info(data.msg);
|
272 |
+
wt_iew_notify_msg.success(wt_iew_basic_params.msgs.success);
|
273 |
+
|
274 |
+
}
|
275 |
+
else if(data.finished==2) /* Remote export */
|
276 |
+
{
|
277 |
+
wt_iew_basic_export.set_export_progress_info(data.msg);
|
278 |
+
wt_iew_basic_export.ajax_data['export_id']=data.export_id;
|
279 |
+
wt_iew_basic_export.ajax_data['total_records']=data.total_records;
|
280 |
+
wt_iew_basic_export.ajax_data['export_action']='upload';
|
281 |
+
wt_iew_basic_export.ajax_data['form_data']={};
|
282 |
+
wt_iew_basic_export.do_nonstep_action('upload');
|
283 |
+
}
|
284 |
+
else
|
285 |
+
{
|
286 |
+
wt_iew_basic_export.set_export_progress_info(data.msg);
|
287 |
+
wt_iew_basic_export.ajax_data['offset']=data.new_offset;
|
288 |
+
wt_iew_basic_export.ajax_data['export_id']=data.export_id;
|
289 |
+
wt_iew_basic_export.ajax_data['total_records']=data.total_records;
|
290 |
+
wt_iew_basic_export.do_nonstep_action(action);
|
291 |
+
}
|
292 |
+
}else
|
293 |
+
{
|
294 |
+
|
295 |
+
}
|
296 |
+
}else
|
297 |
+
{
|
298 |
+
if(data.msg!="")
|
299 |
+
{
|
300 |
+
wt_iew_notify_msg.error(data.msg);
|
301 |
+
}else
|
302 |
+
{
|
303 |
+
wt_iew_notify_msg.error(wt_iew_basic_params.msgs.error);
|
304 |
+
}
|
305 |
+
}
|
306 |
+
},
|
307 |
+
error:function()
|
308 |
+
{
|
309 |
+
wt_iew_basic_export.remove_ajax_page_loader();
|
310 |
+
wt_iew_notify_msg.error(wt_iew_basic_params.msgs.error);
|
311 |
+
}
|
312 |
+
});
|
313 |
+
},
|
314 |
+
reg_button_actions:function()
|
315 |
+
{
|
316 |
+
$('.wt_iew_export_action_btn').unbind('click').click(function(e){
|
317 |
+
e.preventDefault();
|
318 |
+
var action=$(this).attr('data-action');
|
319 |
+
var action_type=$(this).attr('data-action-type');
|
320 |
+
var is_previous_step=wt_iew_basic_export.is_previous_step(action);
|
321 |
+
// if(!wt_iew_exporter_validate(action, action_type, is_previous_step))
|
322 |
+
// {
|
323 |
+
// return false;
|
324 |
+
// }
|
325 |
+
|
326 |
+
if(action_type=='step')
|
327 |
+
{
|
328 |
+
wt_iew_basic_export.change_step(action);
|
329 |
+
}else
|
330 |
+
{
|
331 |
+
wt_iew_basic_export.nonstep_actions(action);
|
332 |
+
}
|
333 |
+
});
|
334 |
+
},
|
335 |
+
change_step:function(step_to_go)
|
336 |
+
{
|
337 |
+
/* validation section */
|
338 |
+
if(this.current_step=='post_type')
|
339 |
+
{
|
340 |
+
if(this.to_export=='')
|
341 |
+
{
|
342 |
+
$('.wt_iew_post_type_wrn').show();
|
343 |
+
return false;
|
344 |
+
}
|
345 |
+
}else if(this.current_step=='method_export') /* method export page */
|
346 |
+
{
|
347 |
+
if(this.export_method=='template' && this.selected_template==0 && !this.is_previous_step(step_to_go))
|
348 |
+
{
|
349 |
+
$('.wt_iew_warn').hide();
|
350 |
+
$('.wt_iew_export_template_wrn').show();
|
351 |
+
return false;
|
352 |
+
}
|
353 |
+
}
|
354 |
+
|
355 |
+
/* setting fromdata */
|
356 |
+
this.prepare_form_data();
|
357 |
+
|
358 |
+
/* step changing section */
|
359 |
+
this.show_step_page(step_to_go, true);
|
360 |
+
},
|
361 |
+
reset_form_data:function()
|
362 |
+
{
|
363 |
+
this.form_data={};
|
364 |
+
this.selected_template=0;
|
365 |
+
this.selected_template_name='';
|
366 |
+
this.export_method='';
|
367 |
+
},
|
368 |
+
prepare_form_data:function()
|
369 |
+
{
|
370 |
+
if(this.current_step=='post_type')
|
371 |
+
{
|
372 |
+
this.form_data['post_type_form_data']=JSON.stringify({'item_type':wt_iew_basic_export.to_export});
|
373 |
+
}
|
374 |
+
else if(this.current_step=='method_export')
|
375 |
+
{
|
376 |
+
var mapping_enabled_fields=new Array();
|
377 |
+
$('.wt_iew_export_step_method_export [name="wt_iew_include_these_fields[]"]').each(function(){
|
378 |
+
if($(this).is(':checked'))
|
379 |
+
{
|
380 |
+
mapping_enabled_fields.push($(this).val());
|
381 |
+
}
|
382 |
+
});
|
383 |
+
this.form_data['method_export_form_data']=JSON.stringify({'method_export':wt_iew_basic_export.export_method, 'mapping_enabled_fields':mapping_enabled_fields, 'selected_template':this.selected_template});
|
384 |
+
}
|
385 |
+
else if(this.current_step=='filter')
|
386 |
+
{
|
387 |
+
if($('.wt_iew_export_filter_form').length>0)
|
388 |
+
{
|
389 |
+
var form_data=$('.wt_iew_export_filter_form').serializeArray();
|
390 |
+
var filter_form_data={};
|
391 |
+
$.each(form_data, function(){
|
392 |
+
if(filter_form_data[this.name])
|
393 |
+
{
|
394 |
+
if(!filter_form_data[this.name].push)
|
395 |
+
{
|
396 |
+
filter_form_data[this.name] = [filter_form_data[this.name]];
|
397 |
+
}
|
398 |
+
filter_form_data[this.name].push(this.value || '');
|
399 |
+
}else
|
400 |
+
{
|
401 |
+
if(wt_iew_basic_export.is_multi_select(this.name))
|
402 |
+
{
|
403 |
+
filter_form_data[this.name] = [(this.value || '')];
|
404 |
+
}else
|
405 |
+
{
|
406 |
+
filter_form_data[this.name] = this.value || '';
|
407 |
+
}
|
408 |
+
}
|
409 |
+
});
|
410 |
+
this.form_data['filter_form_data']=JSON.stringify(filter_form_data);
|
411 |
+
}
|
412 |
+
}
|
413 |
+
else if(this.current_step=='mapping')
|
414 |
+
{
|
415 |
+
|
416 |
+
/**
|
417 |
+
* Default mapping fields //===============================================
|
418 |
+
*/
|
419 |
+
|
420 |
+
var mapping_form_data={};
|
421 |
+
var mapping_fields={};
|
422 |
+
var mapping_selected_fields={}; /* this value is only for backend processing */
|
423 |
+
|
424 |
+
$('.wt-iew-exporter-default-mapping-tb tbody tr').each(function(){
|
425 |
+
|
426 |
+
var columns_key=$(this).find('.columns_key').val();
|
427 |
+
var columns_val=$(this).find('.columns_val').val();
|
428 |
+
|
429 |
+
if(wt_iew_basic_export.only_enabled_data===false) /* get whole keys instead of enabled/disabled */
|
430 |
+
{
|
431 |
+
var enabled=($(this).find('.columns_key').is(':checked') ? 1 : 0);
|
432 |
+
mapping_fields[columns_key]=[columns_val,enabled];
|
433 |
+
|
434 |
+
if(enabled==1)
|
435 |
+
{
|
436 |
+
mapping_selected_fields[columns_key]=columns_val;
|
437 |
+
}
|
438 |
+
|
439 |
+
}else
|
440 |
+
{
|
441 |
+
if($(this).find('.columns_key').is(':checked'))
|
442 |
+
{
|
443 |
+
mapping_fields[columns_key]=columns_val;
|
444 |
+
mapping_selected_fields[columns_key]=columns_val;
|
445 |
+
}
|
446 |
+
}
|
447 |
+
});
|
448 |
+
|
449 |
+
var mapping_enabled_fields=new Array();
|
450 |
+
/*
|
451 |
+
$('.wt_iew_export_step_mapping [name="wt_iew_include_these_fields[]"]').each(function(){
|
452 |
+
|
453 |
+
if($(this).is(':checked'))
|
454 |
+
{
|
455 |
+
mapping_enabled_fields.push($(this).val());
|
456 |
+
}
|
457 |
+
|
458 |
+
});
|
459 |
+
*/
|
460 |
+
|
461 |
+
mapping_form_data={'mapping_fields':mapping_fields,'mapping_enabled_fields':mapping_enabled_fields, 'mapping_selected_fields':mapping_selected_fields};
|
462 |
+
this.form_data['mapping_form_data']=JSON.stringify(mapping_form_data);
|
463 |
+
|
464 |
+
|
465 |
+
|
466 |
+
/**
|
467 |
+
* meta mapping fields //===============================================
|
468 |
+
*/
|
469 |
+
|
470 |
+
var meta_step_form_data={};
|
471 |
+
var mapping_fields={};
|
472 |
+
var mapping_selected_fields={}; /* this value is only for backend processing */
|
473 |
+
|
474 |
+
$('.wt-iew-exporter-meta-mapping-tb').each(function(){
|
475 |
+
var mapping_key=$(this).attr('data-field-type');
|
476 |
+
mapping_fields[mapping_key]={};
|
477 |
+
mapping_selected_fields[mapping_key]={};
|
478 |
+
|
479 |
+
$(this).find('tbody tr').each(function(){
|
480 |
+
if($(this).find('.columns_key').length>0 && $(this).find('.columns_val').length>0)
|
481 |
+
{
|
482 |
+
var columns_key=$(this).find('.columns_key').val();
|
483 |
+
var columns_val=$(this).find('.columns_val').val();
|
484 |
+
|
485 |
+
if(wt_iew_basic_export.only_enabled_data===false) /* get whole keys instead of enabled/disabled */
|
486 |
+
{
|
487 |
+
var enabled=($(this).find('.columns_key').is(':checked') ? 1 : 0);
|
488 |
+
mapping_fields[mapping_key][columns_key]=[columns_val,enabled];
|
489 |
+
|
490 |
+
if(enabled==1)
|
491 |
+
{
|
492 |
+
mapping_selected_fields[mapping_key][columns_key]=columns_val;
|
493 |
+
}
|
494 |
+
|
495 |
+
}else
|
496 |
+
{
|
497 |
+
if($(this).find('.columns_key').is(':checked'))
|
498 |
+
{
|
499 |
+
mapping_fields[mapping_key][columns_key]=columns_val;
|
500 |
+
mapping_selected_fields[mapping_key][columns_key]=columns_val;
|
501 |
+
}
|
502 |
+
}
|
503 |
+
}
|
504 |
+
});
|
505 |
+
});
|
506 |
+
|
507 |
+
meta_step_form_data={'mapping_fields':mapping_fields, 'mapping_selected_fields':mapping_selected_fields};
|
508 |
+
this.form_data['meta_step_form_data']=JSON.stringify(meta_step_form_data);
|
509 |
+
|
510 |
+
}
|
511 |
+
else
|
512 |
+
{
|
513 |
+
var current_form_data={};
|
514 |
+
if($('.wt_iew_export_'+this.current_step+'_form').length>0) /* may be user hit the back button */
|
515 |
+
{
|
516 |
+
var form_data=$('.wt_iew_export_'+this.current_step+'_form').serializeArray();
|
517 |
+
$.each(form_data, function(){
|
518 |
+
|
519 |
+
if(current_form_data[this.name])
|
520 |
+
{
|
521 |
+
if(!current_form_data[this.name].push)
|
522 |
+
{
|
523 |
+
current_form_data[this.name] = [current_form_data[this.name]];
|
524 |
+
}
|
525 |
+
current_form_data[this.name].push(this.value || '');
|
526 |
+
}else
|
527 |
+
{
|
528 |
+
current_form_data[this.name] = this.value || '';
|
529 |
+
}
|
530 |
+
|
531 |
+
});
|
532 |
+
|
533 |
+
this.form_data[this.current_step+'_form_data']=JSON.stringify(current_form_data);
|
534 |
+
}
|
535 |
+
}
|
536 |
+
|
537 |
+
/* we are resetting formdata on second step. If user not going to first step then post type formdata will be empty. */
|
538 |
+
if(this.current_step!='post_type')
|
539 |
+
{
|
540 |
+
this.form_data['post_type_form_data']=JSON.stringify({'item_type':wt_iew_basic_export.to_export});
|
541 |
+
}
|
542 |
+
|
543 |
+
},
|
544 |
+
is_multi_select:function(name)
|
545 |
+
{
|
546 |
+
var elm=$('[name="'+name+'"]');
|
547 |
+
if(elm.prop("tagName").toLowerCase()=='select' && this.has_attr(elm,'multiple'))
|
548 |
+
{
|
549 |
+
return true;
|
550 |
+
}else
|
551 |
+
{
|
552 |
+
return false;
|
553 |
+
}
|
554 |
+
},
|
555 |
+
has_attr:function(elm,attr_name)
|
556 |
+
{
|
557 |
+
var attr = elm.attr(attr_name);
|
558 |
+
if(typeof attr!==typeof undefined && attr!==false)
|
559 |
+
{
|
560 |
+
return true;
|
561 |
+
}else
|
562 |
+
{
|
563 |
+
return false;
|
564 |
+
}
|
565 |
+
},
|
566 |
+
is_previous_step:function(step_key)
|
567 |
+
{
|
568 |
+
if(wt_iew_export_basic_params.steps.hasOwnProperty(step_key))
|
569 |
+
{
|
570 |
+
if(this.step_keys.indexOf(step_key)<this.step_keys.indexOf(this.current_step))
|
571 |
+
{
|
572 |
+
return true;
|
573 |
+
}
|
574 |
+
}
|
575 |
+
return false;
|
576 |
+
},
|
577 |
+
is_step_loaded:function(step)
|
578 |
+
{
|
579 |
+
if(this.get_page_dom_object(step).length==0){ return true; } /* block infinite loop, if element is not available */
|
580 |
+
return (this.get_page_dom_object(step).attr('data-loaded')==this.loaded_status_arr['loaded']);
|
581 |
+
},
|
582 |
+
set_step_loading_status:function(steps, status)
|
583 |
+
{
|
584 |
+
$.each(steps, function(step_ind, step){
|
585 |
+
wt_iew_basic_export.get_page_dom_object(step).attr('data-loaded', wt_iew_basic_export.loaded_status_arr[status]);
|
586 |
+
});
|
587 |
+
},
|
588 |
+
show_step_page:function(step, force_check_loaded)
|
589 |
+
{
|
590 |
+
$('.wt_iew_export_step').hide();
|
591 |
+
this.get_page_dom_object(step).show();
|
592 |
+
this.current_step=step;
|
593 |
+
if(force_check_loaded)
|
594 |
+
{
|
595 |
+
if(this.is_step_loaded(step))
|
596 |
+
{
|
597 |
+
this.current_step_actions();
|
598 |
+
}else
|
599 |
+
{
|
600 |
+
this.refresh_step(true);
|
601 |
+
}
|
602 |
+
}else
|
603 |
+
{
|
604 |
+
this.current_step_actions();
|
605 |
+
}
|
606 |
+
wt_iew_form_toggler.runToggler();
|
607 |
+
},
|
608 |
+
current_step_actions:function() /* current page actions after page is visible */
|
609 |
+
{
|
610 |
+
if(this.current_step=='filter')
|
611 |
+
{
|
612 |
+
this.load_meta_mapping_fields();
|
613 |
+
}else if(this.current_step=='advanced')
|
614 |
+
{
|
615 |
+
wt_field_group.Set();
|
616 |
+
}
|
617 |
+
},
|
618 |
+
show_post_type_name:function()
|
619 |
+
{
|
620 |
+
if(this.to_export!="" && this.to_export_title=='')
|
621 |
+
{
|
622 |
+
$('[name="wt_iew_export_post_type"]').val(this.to_export);
|
623 |
+
this.to_export_title=$('[name="wt_iew_export_post_type"] option:selected').text();
|
624 |
+
}
|
625 |
+
$('.wt_iew_step_head_post_type_name').html(this.to_export_title);
|
626 |
+
},
|
627 |
+
page_actions:function(step)
|
628 |
+
{
|
629 |
+
if(step=='post_type') /* post type page */
|
630 |
+
{
|
631 |
+
$('[name="wt_iew_export_post_type"]').unbind('change').change(function(){
|
632 |
+
wt_iew_basic_export.to_export=$(this).val();
|
633 |
+
wt_iew_basic_export.to_export_title='';
|
634 |
+
wt_iew_basic_export.reset_form_data();
|
635 |
+
$('.wt_iew_post_type_name').html('');
|
636 |
+
if(wt_iew_basic_export.to_export=='')
|
637 |
+
{
|
638 |
+
$('.wt_iew_post_type_wrn').show();
|
639 |
+
}else
|
640 |
+
{
|
641 |
+
$('.wt_iew_post_type_wrn').hide();
|
642 |
+
var post_type_name=$('[name="wt_iew_export_post_type"] option:selected').text();
|
643 |
+
/* $('.wt_iew_post_type_name').html(': '+post_type_name); */
|
644 |
+
wt_iew_basic_export.to_export_title=post_type_name;
|
645 |
+
wt_iew_basic_export.load_pending_steps(true);
|
646 |
+
}
|
647 |
+
});
|
648 |
+
}
|
649 |
+
else if(step=='method_export') /* method export page */
|
650 |
+
{
|
651 |
+
this.export_method=$('[name="wt_iew_export_method_export"]:checked').val();
|
652 |
+
this.toggle_export_method_options();
|
653 |
+
|
654 |
+
$('[name="wt_iew_export_method_export"]').unbind('click').click(function(){
|
655 |
+
var vl=$(this).val();
|
656 |
+
if(wt_iew_basic_export.export_method==vl)
|
657 |
+
{
|
658 |
+
return false;
|
659 |
+
}
|
660 |
+
wt_iew_basic_export.reset_form_data();
|
661 |
+
wt_iew_basic_export.export_method=vl;
|
662 |
+
if(wt_iew_basic_export.export_method=='template')
|
663 |
+
{
|
664 |
+
if($('.wt-iew-export-template-sele').val()==0)
|
665 |
+
{
|
666 |
+
wt_iew_basic_export.refresh_step();
|
667 |
+
}else
|
668 |
+
{
|
669 |
+
wt_iew_basic_export.selected_template=$('.wt-iew-export-template-sele').val();
|
670 |
+
wt_iew_basic_export.selected_template_name=$.trim($('.wt-iew-export-template-sele option:selected').text());
|
671 |
+
wt_iew_basic_export.load_pending_steps();
|
672 |
+
}
|
673 |
+
}else
|
674 |
+
{
|
675 |
+
wt_iew_basic_export.load_pending_steps();
|
676 |
+
}
|
677 |
+
});
|
678 |
+
|
679 |
+
$('.wt-iew-export-template-sele').unbind('change').change(function(){
|
680 |
+
wt_iew_basic_export.selected_template=$(this).val();
|
681 |
+
$('.wt_iew_warn').hide();
|
682 |
+
if(wt_iew_basic_export.selected_template==0)
|
683 |
+
{
|
684 |
+
$('.wt_iew_export_template_wrn').show();
|
685 |
+
}else
|
686 |
+
{
|
687 |
+
wt_iew_basic_export.selected_template_name=$.trim($('.wt-iew-export-template-sele option:selected').text());
|
688 |
+
wt_iew_basic_export.load_pending_steps();
|
689 |
+
}
|
690 |
+
});
|
691 |
+
}
|
692 |
+
else if(step=='filter') /* filter page */
|
693 |
+
{
|
694 |
+
$('.wc-enhanced-select').select2();
|
695 |
+
$( document.body ).trigger( 'wc-enhanced-select-init' );
|
696 |
+
}
|
697 |
+
else if(step=='mapping') /* mapping page */
|
698 |
+
{
|
699 |
+
this.enable_sortable();
|
700 |
+
this.mapping_box_accordian();
|
701 |
+
this.reg_mapping_field_bulk_action();
|
702 |
+
}
|
703 |
+
else if(step=='advanced')
|
704 |
+
{
|
705 |
+
/* callback for external adapters */
|
706 |
+
if($('select[name="wt_iew_file_into"]').length>0) /* multiple adapter exists so select box */
|
707 |
+
{
|
708 |
+
var file_into=$('[name="wt_iew_file_into"]').val();
|
709 |
+
$('[name="wt_iew_file_into"]').unbind('change').on('change',function(){
|
710 |
+
var file_into=$(this).val();
|
711 |
+
wt_iew_set_file_into_fields(file_into);
|
712 |
+
});
|
713 |
+
}else /* radio button */
|
714 |
+
{
|
715 |
+
var file_into=$('[name="wt_iew_file_into"]:checked').val();
|
716 |
+
$('[name="wt_iew_file_into"]').on('click',function(){
|
717 |
+
var file_into=$('[name="wt_iew_file_into"]:checked').val();
|
718 |
+
wt_iew_set_file_into_fields(file_into);
|
719 |
+
});
|
720 |
+
}
|
721 |
+
wt_iew_set_file_into_fields(file_into);
|
722 |
+
|
723 |
+
/* separate image export option */
|
724 |
+
if($('.wt_iew_separate_image_export').length>0) /* separate image export option available */
|
725 |
+
{
|
726 |
+
if($('.wt_iew_separate_image_export:checked').val()=='Yes')
|
727 |
+
{
|
728 |
+
$('.iew_export_image_btn').show();
|
729 |
+
}else
|
730 |
+
{
|
731 |
+
$('.iew_export_image_btn').hide();
|
732 |
+
}
|
733 |
+
}else
|
734 |
+
{
|
735 |
+
$('.iew_export_image_btn').hide();
|
736 |
+
}
|
737 |
+
$('.wt_iew_separate_image_export').unbind('click').click(function(){
|
738 |
+
if($(this).val()=='Yes')
|
739 |
+
{
|
740 |
+
$('.iew_export_image_btn').show();
|
741 |
+
}else
|
742 |
+
{
|
743 |
+
$('.iew_export_image_btn').hide();
|
744 |
+
}
|
745 |
+
});
|
746 |
+
|
747 |
+
/* CSV delimiter form toggler. Custom and preset delimiter */
|
748 |
+
wt_iew_custom_and_preset.delimiter_toggler();
|
749 |
+
|
750 |
+
/* file extension info box */
|
751 |
+
$('.wt_iew_file_ext_info').html('.'+$('[name="wt_iew_file_as"]').val());
|
752 |
+
$('[name="wt_iew_file_as"]').unbind('change').change(function(){
|
753 |
+
$('.wt_iew_file_ext_info').html('.'+$(this).val());
|
754 |
+
});
|
755 |
+
}
|
756 |
+
|
757 |
+
/* common events */
|
758 |
+
if($('.wt_iew_datepicker').length>0)
|
759 |
+
{
|
760 |
+
$('.wt_iew_datepicker').datepicker({dateFormat: 'yy-mm-dd'});
|
761 |
+
}
|
762 |
+
wt_field_group.Set();
|
763 |
+
wt_iew_form_toggler.Set();
|
764 |
+
wt_iew_conditional_help_text.Set(this.get_page_dom_object(step));
|
765 |
+
|
766 |
+
},
|
767 |
+
enable_sortable:function()
|
768 |
+
{
|
769 |
+
$('.meta_mapping_box_con[data-sortable="0"]').each(function(){
|
770 |
+
var tb=$(this).find(".wt-iew-mapping-tb tbody");
|
771 |
+
if(tb.length>0)
|
772 |
+
{
|
773 |
+
tb.sortable({
|
774 |
+
handle: ".wt_iew_sort_handle",
|
775 |
+
placeholder: "wt-iew-sortable-placeholder",
|
776 |
+
forcePlaceholderSize: true,
|
777 |
+
revert:true
|
778 |
+
});
|
779 |
+
$(this).attr('data-sortable', 1);
|
780 |
+
}
|
781 |
+
});
|
782 |
+
},
|
783 |
+
toggle_export_method_options:function()
|
784 |
+
{
|
785 |
+
$('.wt-iew-export-method-options').hide();
|
786 |
+
$('.wt-iew-export-method-options-'+this.export_method).show();
|
787 |
+
},
|
788 |
+
mapping_box_accordian:function()
|
789 |
+
{
|
790 |
+
$('.meta_mapping_box_hd').unbind('click').click(function()
|
791 |
+
{
|
792 |
+
var c_dv=$(this).parents('.meta_mapping_box').find('.meta_mapping_box_con');
|
793 |
+
if(c_dv.is(':visible'))
|
794 |
+
{
|
795 |
+
c_dv.hide();
|
796 |
+
$(this).find('.dashicons').removeClass('dashicons-arrow-down').addClass('dashicons-arrow-right');
|
797 |
+
}else
|
798 |
+
{
|
799 |
+
c_dv.show();
|
800 |
+
c_dv.find(".wt-iew-mapping-tb tbody tr td").each(function(){
|
801 |
+
$(this).css({'width':$(this).width()});
|
802 |
+
});
|
803 |
+
$(this).find('.dashicons').removeClass('dashicons-arrow-right').addClass('dashicons-arrow-down');
|
804 |
+
}
|
805 |
+
});
|
806 |
+
},
|
807 |
+
mapping_fields_selected_count:function(tb_elm)
|
808 |
+
{
|
809 |
+
tb_elm.parents('.meta_mapping_box').find('.meta_mapping_box_selected_count_box_num').text(tb_elm.find('.wt_iew_mapping_checkbox_sub:checked').length);
|
810 |
+
},
|
811 |
+
reg_mapping_field_bulk_action:function()
|
812 |
+
{
|
813 |
+
$('.wt_iew_mapping_checkbox_main').each(function()
|
814 |
+
{
|
815 |
+
var tb=$(this).parents('.wt-iew-mapping-tb');
|
816 |
+
if(tb.find('.wt_iew_mapping_checkbox_sub:checked').length==tb.find('.wt_iew_mapping_checkbox_sub').length)
|
817 |
+
{
|
818 |
+
tb.find('.wt_iew_mapping_checkbox_main').prop('checked',true);
|
819 |
+
}else
|
820 |
+
{
|
821 |
+
tb.find('.wt_iew_mapping_checkbox_main').prop('checked',false);
|
822 |
+
}
|
823 |
+
wt_iew_basic_export.mapping_fields_selected_count(tb);
|
824 |
+
});
|
825 |
+
|
826 |
+
$('.wt_iew_mapping_checkbox_main').unbind('click').click(function()
|
827 |
+
{
|
828 |
+
var tb=$(this).parents('.wt-iew-mapping-tb');
|
829 |
+
if($(this).is(':checked'))
|
830 |
+
{
|
831 |
+
tb.find('.wt_iew_mapping_checkbox_sub').prop('checked',true);
|
832 |
+
}else
|
833 |
+
{
|
834 |
+
tb.find('.wt_iew_mapping_checkbox_sub').prop('checked',false);
|
835 |
+
}
|
836 |
+
wt_iew_basic_export.mapping_fields_selected_count(tb);
|
837 |
+
});
|
838 |
+
$('.wt_iew_mapping_checkbox_sub').unbind('click').click(function()
|
839 |
+
{
|
840 |
+
var tb=$(this).parents('.wt-iew-mapping-tb');
|
841 |
+
if($(this).is(':checked') && tb.find('.wt_iew_mapping_checkbox_sub:checked').length==tb.find('.wt_iew_mapping_checkbox_sub').length)
|
842 |
+
{
|
843 |
+
tb.find('.wt_iew_mapping_checkbox_main').prop('checked',true);
|
844 |
+
}else
|
845 |
+
{
|
846 |
+
tb.find('.wt_iew_mapping_checkbox_main').prop('checked',false);
|
847 |
+
}
|
848 |
+
wt_iew_basic_export.mapping_fields_selected_count(tb);
|
849 |
+
});
|
850 |
+
},
|
851 |
+
set_step_page:function(data)
|
852 |
+
{
|
853 |
+
page_html=data.page_html;
|
854 |
+
$.each(page_html, function(step_id, page_content){
|
855 |
+
wt_iew_basic_export.get_page_dom_object(step_id).html(page_content);
|
856 |
+
wt_iew_basic_export.page_actions(step_id);
|
857 |
+
|
858 |
+
if(step_id=='method_export' && (wt_iew_basic_export.selected_template>0 || wt_iew_basic_export.on_rerun))
|
859 |
+
{
|
860 |
+
wt_iew_basic_export.form_data=data.template_data;
|
861 |
+
|
862 |
+
if(wt_iew_basic_export.on_rerun)
|
863 |
+
{
|
864 |
+
if($('.wt-iew-export-template-sele').val()==0)
|
865 |
+
{
|
866 |
+
wt_iew_basic_export.selected_template=0;
|
867 |
+
wt_iew_basic_export.selected_template_name='';
|
868 |
+
}else
|
869 |
+
{
|
870 |
+
wt_iew_basic_export.selected_template=$('.wt-iew-export-template-sele').val();
|
871 |
+
wt_iew_basic_export.selected_template_name=$.trim($('.wt-iew-export-template-sele option:selected').text());
|
872 |
+
}
|
873 |
+
}
|
874 |
+
}
|
875 |
+
wt_iew_basic_export.show_post_type_name();
|
876 |
+
});
|
877 |
+
this.reg_button_actions();
|
878 |
+
},
|
879 |
+
prepare_ajax_data:function(action, data_type)
|
880 |
+
{
|
881 |
+
this.ajax_data = {
|
882 |
+
'_wpnonce': wt_iew_basic_params.nonces.main,
|
883 |
+
'action': "iew_export_ajax_basic",
|
884 |
+
'export_action': action,
|
885 |
+
'selected_template': this.selected_template,
|
886 |
+
'to_export': this.to_export,
|
887 |
+
'data_type': data_type,
|
888 |
+
'export_method': this.export_method,
|
889 |
+
};
|
890 |
+
}
|
891 |
+
}
|
892 |
+
return wt_iew_basic_export;
|
893 |
+
|
894 |
+
})( jQuery );
|
895 |
+
|
896 |
+
jQuery(function() {
|
897 |
+
|
898 |
+
if(wt_iew_export_basic_params.rerun_id>0)
|
899 |
+
{
|
900 |
+
wt_iew_basic_export.to_export=wt_iew_export_basic_params.to_export;
|
901 |
+
wt_iew_basic_export.export_method=wt_iew_export_basic_params.export_method;
|
902 |
+
wt_iew_basic_export.rerun_id=wt_iew_export_basic_params.rerun_id;
|
903 |
+
wt_iew_basic_export.on_rerun=true;
|
904 |
+
}
|
905 |
+
wt_iew_basic_export.Set();
|
906 |
+
});
|
admin/modules/export/classes/class-export-ajax.php
ADDED
@@ -0,0 +1,707 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Ajax section of the Export module
|
4 |
+
*
|
5 |
+
* @link
|
6 |
+
*
|
7 |
+
* @package Wt_Import_Export_For_Woo
|
8 |
+
*/
|
9 |
+
if (!defined('ABSPATH')) {
|
10 |
+
exit;
|
11 |
+
}
|
12 |
+
|
13 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Basic_Export_Ajax')){
|
14 |
+
class Wt_Import_Export_For_Woo_Basic_Export_Ajax
|
15 |
+
{
|
16 |
+
public $step='';
|
17 |
+
public $steps=array();
|
18 |
+
public $step_btns=array();
|
19 |
+
public $export_method='';
|
20 |
+
public $to_export='';
|
21 |
+
|
22 |
+
protected $step_title='';
|
23 |
+
protected $step_keys=array();
|
24 |
+
protected $current_step_index=0;
|
25 |
+
protected $current_step_number=1;
|
26 |
+
protected $last_page=false;
|
27 |
+
protected $total_steps=0;
|
28 |
+
protected $step_summary='';
|
29 |
+
protected $mapping_enabled_fields=array();
|
30 |
+
protected $mapping_templates=array();
|
31 |
+
protected $selected_template=0;
|
32 |
+
protected $selected_template_form_data=array(); /* this variable is using to store form_data of selected template or selected history entry */
|
33 |
+
protected $export_obj=null;
|
34 |
+
protected $rerun_id=0;
|
35 |
+
|
36 |
+
public function __construct($export_obj, $to_export, $steps, $export_method, $selected_template, $rerun_id)
|
37 |
+
{
|
38 |
+
$this->export_obj=$export_obj;
|
39 |
+
$this->to_export=$to_export;
|
40 |
+
$this->steps=$steps;
|
41 |
+
$this->export_method=$export_method;
|
42 |
+
$this->selected_template=$selected_template;
|
43 |
+
$this->rerun_id=$rerun_id;
|
44 |
+
}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Ajax main function to retrive steps HTML
|
48 |
+
*/
|
49 |
+
public function get_steps($out)
|
50 |
+
{
|
51 |
+
//sleep(3);
|
52 |
+
$steps=(is_array($_POST['steps']) ? $_POST['steps'] : array($_POST['steps']));
|
53 |
+
$steps=Wt_Iew_Sh::sanitize_item($steps, 'text_arr');
|
54 |
+
$page_html=array();
|
55 |
+
|
56 |
+
if($this->selected_template>0) /* taking selected tamplate form_data */
|
57 |
+
{
|
58 |
+
$this->get_template_form_data($this->selected_template);
|
59 |
+
|
60 |
+
}elseif($this->rerun_id>0)
|
61 |
+
{
|
62 |
+
$this->selected_template_form_data=$this->export_obj->form_data;
|
63 |
+
}
|
64 |
+
|
65 |
+
foreach($steps as $step)
|
66 |
+
{
|
67 |
+
$method_name=$step.'_page';
|
68 |
+
if(method_exists($this, $method_name))
|
69 |
+
{
|
70 |
+
$page_html[$step]=$this->{$method_name}();
|
71 |
+
|
72 |
+
if($step=='method_export' && ($this->selected_template>0 || $this->rerun_id>0))
|
73 |
+
{
|
74 |
+
$out['template_data']=$this->selected_template_form_data;
|
75 |
+
}
|
76 |
+
}
|
77 |
+
}
|
78 |
+
$out['status']=1;
|
79 |
+
$out['page_html']=$page_html;
|
80 |
+
return $out;
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Ajax function to retrive meta step data
|
85 |
+
*/
|
86 |
+
public function get_meta_mapping_fields($out)
|
87 |
+
{
|
88 |
+
if($this->selected_template>0) /* taking selected tamplate form_data */
|
89 |
+
{
|
90 |
+
$this->get_template_form_data($this->selected_template);
|
91 |
+
|
92 |
+
}elseif($this->rerun_id>0)
|
93 |
+
{
|
94 |
+
$this->selected_template_form_data=$this->export_obj->form_data;
|
95 |
+
}
|
96 |
+
|
97 |
+
$this->get_mapping_enabled_fields();
|
98 |
+
|
99 |
+
$meta_mapping_screen_fields=array();
|
100 |
+
foreach($this->mapping_enabled_fields as $field_key=>$field_vl)
|
101 |
+
{
|
102 |
+
$field_vl=(!is_array($field_vl) ? array($field_vl, 0) : $field_vl);
|
103 |
+
$meta_mapping_screen_fields[$field_key]=array(
|
104 |
+
'title'=>'',
|
105 |
+
'checked'=>$field_vl[1],
|
106 |
+
'fields'=>array(),
|
107 |
+
);
|
108 |
+
}
|
109 |
+
|
110 |
+
//taking current page form data
|
111 |
+
$meta_step_form_data=(isset($this->selected_template_form_data['meta_step_form_data']) ? $this->selected_template_form_data['meta_step_form_data'] : array());
|
112 |
+
|
113 |
+
/* form_data/template data of fields in mapping page */
|
114 |
+
$form_data_meta_mapping_fields=isset($meta_step_form_data['mapping_fields']) ? $meta_step_form_data['mapping_fields'] : array();
|
115 |
+
|
116 |
+
|
117 |
+
$meta_mapping_screen_fields=apply_filters('wt_iew_exporter_alter_meta_mapping_fields_basic', $meta_mapping_screen_fields, $this->to_export, $form_data_meta_mapping_fields);
|
118 |
+
|
119 |
+
$draggable_tooltip=__("Drag to rearrange the columns");
|
120 |
+
$module_url=plugin_dir_url(dirname(__FILE__));
|
121 |
+
|
122 |
+
$meta_html=array();
|
123 |
+
if($meta_mapping_screen_fields && is_array($meta_mapping_screen_fields))
|
124 |
+
{
|
125 |
+
/* loop through mapping fields */
|
126 |
+
foreach($meta_mapping_screen_fields as $meta_mapping_screen_field_key=>$meta_mapping_screen_field_val)
|
127 |
+
{
|
128 |
+
$current_meta_step_form_data=(isset($form_data_meta_mapping_fields[$meta_mapping_screen_field_key]) ? $form_data_meta_mapping_fields[$meta_mapping_screen_field_key] : array());
|
129 |
+
ob_start();
|
130 |
+
include dirname(plugin_dir_path(__FILE__)).'/views/_export_meta_step_page.php';
|
131 |
+
$meta_html[$meta_mapping_screen_field_key]=ob_get_clean();
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
$out['status']=1;
|
136 |
+
$out['meta_html']=$meta_html;
|
137 |
+
return $out;
|
138 |
+
}
|
139 |
+
|
140 |
+
public function save_template($out)
|
141 |
+
{
|
142 |
+
return $this->do_save_template('save', $out);
|
143 |
+
}
|
144 |
+
|
145 |
+
public function save_template_as($out)
|
146 |
+
{
|
147 |
+
return $this->do_save_template('save_as', $out);
|
148 |
+
}
|
149 |
+
|
150 |
+
public function update_template($out)
|
151 |
+
{
|
152 |
+
return $this->do_save_template('update', $out);
|
153 |
+
}
|
154 |
+
|
155 |
+
/**
|
156 |
+
* Ajax hook to upload the exported file.
|
157 |
+
*
|
158 |
+
*/
|
159 |
+
public function upload($out)
|
160 |
+
{
|
161 |
+
$export_id=(isset($_POST['export_id']) ? intval($_POST['export_id']) : 0);
|
162 |
+
$out=$this->export_obj->process_upload('upload', $export_id, $this->to_export);
|
163 |
+
if($out['response']===true)
|
164 |
+
{
|
165 |
+
$out['status']=1;
|
166 |
+
}else
|
167 |
+
{
|
168 |
+
$out['status']=0;
|
169 |
+
}
|
170 |
+
return $out;
|
171 |
+
}
|
172 |
+
|
173 |
+
|
174 |
+
/**
|
175 |
+
* Process the export data
|
176 |
+
*
|
177 |
+
* @return array
|
178 |
+
*/
|
179 |
+
public function export($out)
|
180 |
+
{
|
181 |
+
$offset=(isset($_POST['offset']) ? intval($_POST['offset']) : 0);
|
182 |
+
$export_id=(isset($_POST['export_id']) ? intval($_POST['export_id']) : 0);
|
183 |
+
$file_name='';
|
184 |
+
|
185 |
+
if($export_id==0) /* first batch */
|
186 |
+
{
|
187 |
+
/* process form data */
|
188 |
+
$form_data=(isset($_POST['form_data']) ? Wt_Import_Export_For_Woo_Basic_Common_Helper::process_formdata(maybe_unserialize(($_POST['form_data']))) : array());
|
189 |
+
|
190 |
+
//sanitize form data
|
191 |
+
$form_data=Wt_Iew_IE_Basic_Helper::sanitize_formdata($form_data, $this->export_obj);
|
192 |
+
|
193 |
+
/* taking file name from user input. (If given) */
|
194 |
+
if(isset($form_data['advanced_form_data']) && isset($form_data['advanced_form_data']['wt_iew_file_name']) && $form_data['advanced_form_data']['wt_iew_file_name']!="")
|
195 |
+
{
|
196 |
+
$file_name=$form_data['advanced_form_data']['wt_iew_file_name'];
|
197 |
+
}
|
198 |
+
|
199 |
+
}else
|
200 |
+
{
|
201 |
+
/* no need to send form_data. It will take from history table by `process_action` method */
|
202 |
+
$form_data=array();
|
203 |
+
}
|
204 |
+
|
205 |
+
/* do the export process */
|
206 |
+
$out=$this->export_obj->process_action($form_data, 'export', $this->to_export, $file_name, $export_id, $offset);
|
207 |
+
if($out['response']===true)
|
208 |
+
{
|
209 |
+
$out['status']=1;
|
210 |
+
}else
|
211 |
+
{
|
212 |
+
$out['status']=0;
|
213 |
+
}
|
214 |
+
return $out;
|
215 |
+
}
|
216 |
+
|
217 |
+
/**
|
218 |
+
* Save/Update template (Ajax sub function)
|
219 |
+
* @param boolean $is_update is update existing template or save as new
|
220 |
+
* @return array response status, name, id
|
221 |
+
*/
|
222 |
+
public function do_save_template($step, $out)
|
223 |
+
{
|
224 |
+
$is_update=($step=='update' ? true : false);
|
225 |
+
|
226 |
+
/* take template name from post data, if not then create from time stamp */
|
227 |
+
$template_name=(isset($_POST['template_name']) ? sanitize_text_field($_POST['template_name']) : date('d-M-Y h:i:s A'));
|
228 |
+
|
229 |
+
$template_name = stripslashes($template_name);
|
230 |
+
$out['name']= $template_name;
|
231 |
+
$out['id']=0;
|
232 |
+
$out['status']=1;
|
233 |
+
|
234 |
+
if($this->to_export!='')
|
235 |
+
{
|
236 |
+
global $wpdb;
|
237 |
+
|
238 |
+
/* checking: just saved and again click the button so shift the action as update */
|
239 |
+
if($step=='save' && $this->selected_template>0)
|
240 |
+
{
|
241 |
+
$is_update=true;
|
242 |
+
}
|
243 |
+
|
244 |
+
/* checking template with same name exists */
|
245 |
+
$template_data=$this->get_mapping_template_by_name($template_name);
|
246 |
+
if($template_data)
|
247 |
+
{
|
248 |
+
$is_throw_warn=false;
|
249 |
+
if($is_update)
|
250 |
+
{
|
251 |
+
if($template_data['id']!=$this->selected_template)
|
252 |
+
{
|
253 |
+
$is_throw_warn=true;
|
254 |
+
}
|
255 |
+
}else
|
256 |
+
{
|
257 |
+
$is_throw_warn=true;
|
258 |
+
}
|
259 |
+
|
260 |
+
if($is_throw_warn)
|
261 |
+
{
|
262 |
+
$out['status']=0;
|
263 |
+
if($step=='save_as')
|
264 |
+
{
|
265 |
+
$out['msg']=__('Please enter a different name');
|
266 |
+
}else
|
267 |
+
{
|
268 |
+
$out['msg']=__('Template with same name already exists');
|
269 |
+
}
|
270 |
+
return $out;
|
271 |
+
}
|
272 |
+
}
|
273 |
+
|
274 |
+
$tb=$wpdb->prefix. Wt_Import_Export_For_Woo_Basic::$template_tb;
|
275 |
+
|
276 |
+
/* process form data */
|
277 |
+
$form_data=(isset($_POST['form_data']) ? Wt_Import_Export_For_Woo_Basic_Common_Helper::process_formdata(maybe_unserialize(($_POST['form_data']))) : array());
|
278 |
+
|
279 |
+
//sanitize form data
|
280 |
+
$form_data=Wt_Iew_IE_Basic_Helper::sanitize_formdata($form_data, $this->export_obj);
|
281 |
+
|
282 |
+
/* upadte the template */
|
283 |
+
if($is_update)
|
284 |
+
{
|
285 |
+
|
286 |
+
$update_data=array(
|
287 |
+
'data'=>maybe_serialize($form_data),
|
288 |
+
'name'=>$template_name, //may be a rename
|
289 |
+
);
|
290 |
+
$update_data_type=array(
|
291 |
+
'%s',
|
292 |
+
'%s'
|
293 |
+
);
|
294 |
+
$update_where=array(
|
295 |
+
'id'=>$this->selected_template
|
296 |
+
);
|
297 |
+
$update_where_type=array(
|
298 |
+
'%d'
|
299 |
+
);
|
300 |
+
if($wpdb->update($tb, $update_data, $update_where, $update_data_type, $update_where_type)!==false)
|
301 |
+
{
|
302 |
+
$out['id']=$this->selected_template;
|
303 |
+
$out['msg']=__('Template updated successfully');
|
304 |
+
$out['name']=$template_name;
|
305 |
+
return $out;
|
306 |
+
}
|
307 |
+
}else
|
308 |
+
{
|
309 |
+
$insert_data=array(
|
310 |
+
'template_type'=>'export',
|
311 |
+
'item_type'=>$this->to_export,
|
312 |
+
'name'=>$template_name,
|
313 |
+
'data'=>maybe_serialize($form_data),
|
314 |
+
);
|
315 |
+
$insert_data_type=array(
|
316 |
+
'%s','%s','%s','%s'
|
317 |
+
);
|
318 |
+
if($wpdb->insert($tb, $insert_data, $insert_data_type)) //success
|
319 |
+
{
|
320 |
+
$out['id']=$wpdb->insert_id;
|
321 |
+
$out['msg']=__('Template saved successfully');
|
322 |
+
return $out;
|
323 |
+
}
|
324 |
+
}
|
325 |
+
}
|
326 |
+
$out['status']=0;
|
327 |
+
return $out;
|
328 |
+
}
|
329 |
+
|
330 |
+
/**
|
331 |
+
* Step 1 (Ajax sub function)
|
332 |
+
* Built in steps, post type choosing page
|
333 |
+
*/
|
334 |
+
public function post_type_page()
|
335 |
+
{
|
336 |
+
$post_types=apply_filters('wt_iew_exporter_post_types_basic', array());
|
337 |
+
$post_types=(!is_array($post_types) ? array() : $post_types);
|
338 |
+
$this->step='post_type';
|
339 |
+
$step_info=$this->steps[$this->step];
|
340 |
+
$item_type=$this->to_export;
|
341 |
+
|
342 |
+
$this->prepare_step_summary();
|
343 |
+
$this->prepare_footer_button_list();
|
344 |
+
|
345 |
+
ob_start();
|
346 |
+
$this->prepare_step_header_html();
|
347 |
+
include_once dirname(plugin_dir_path(__FILE__)).'/views/_export_post_type_page.php';
|
348 |
+
$this->prepare_step_footer_html();
|
349 |
+
return ob_get_clean();
|
350 |
+
}
|
351 |
+
|
352 |
+
/**
|
353 |
+
* Step 2 (Ajax sub function)
|
354 |
+
* Built in steps, export method choosing page
|
355 |
+
*/
|
356 |
+
public function method_export_page()
|
357 |
+
{
|
358 |
+
$this->step='method_export';
|
359 |
+
$step_info=$this->steps[$this->step];
|
360 |
+
if($this->to_export!="")
|
361 |
+
{
|
362 |
+
/* setting a default export method */
|
363 |
+
$this->export_method=($this->export_method=='' ? $this->export_obj->default_export_method : $this->export_method);
|
364 |
+
$this->export_obj->export_method=$this->export_method;
|
365 |
+
$this->steps=$this->export_obj->get_steps();
|
366 |
+
|
367 |
+
$form_data_export_template=$this->selected_template;
|
368 |
+
$form_data_mapping_enabled=array();
|
369 |
+
if($this->rerun_id>0)
|
370 |
+
{
|
371 |
+
if(isset($this->selected_template_form_data['method_export_form_data']))
|
372 |
+
{
|
373 |
+
if(isset($this->selected_template_form_data['method_export_form_data']['selected_template']))
|
374 |
+
{
|
375 |
+
/* do not set this value to `$this->selected_template` */
|
376 |
+
$form_data_export_template=$this->selected_template_form_data['method_export_form_data']['selected_template'];
|
377 |
+
}
|
378 |
+
if(isset($this->selected_template_form_data['method_export_form_data']['mapping_enabled_fields']))
|
379 |
+
{
|
380 |
+
$form_data_mapping_enabled=$this->selected_template_form_data['method_export_form_data']['mapping_enabled_fields'];
|
381 |
+
$form_data_mapping_enabled=(is_array($form_data_mapping_enabled) ? $form_data_mapping_enabled : array());
|
382 |
+
}
|
383 |
+
}
|
384 |
+
}
|
385 |
+
|
386 |
+
$this->prepare_step_summary();
|
387 |
+
$this->prepare_footer_button_list();
|
388 |
+
|
389 |
+
/* meta field list for quick export */
|
390 |
+
$this->get_mapping_enabled_fields();
|
391 |
+
|
392 |
+
/* template list for template export */
|
393 |
+
$this->get_mapping_templates();
|
394 |
+
|
395 |
+
ob_start();
|
396 |
+
$this->prepare_step_header_html();
|
397 |
+
include_once dirname(plugin_dir_path(__FILE__)).'/views/_export_method_export_page.php';
|
398 |
+
$this->prepare_step_footer_html();
|
399 |
+
return ob_get_clean();
|
400 |
+
}else
|
401 |
+
{
|
402 |
+
return '';
|
403 |
+
}
|
404 |
+
}
|
405 |
+
|
406 |
+
/*
|
407 |
+
* Get step information
|
408 |
+
* @param string $step
|
409 |
+
*/
|
410 |
+
|
411 |
+
public function get_step_info( $step ) {
|
412 |
+
return isset( $this->steps[ $step ] ) ? $this->steps[ $step ] : array( 'title' => ' ', 'description' => ' ' );
|
413 |
+
}
|
414 |
+
|
415 |
+
/**
|
416 |
+
* Step 3 (Ajax sub function)
|
417 |
+
* Built in steps, filter page
|
418 |
+
*/
|
419 |
+
public function filter_page()
|
420 |
+
{
|
421 |
+
$this->step='filter';
|
422 |
+
$step_info= $this->get_step_info($this->step);
|
423 |
+
if($this->to_export!='')
|
424 |
+
{
|
425 |
+
|
426 |
+
$this->prepare_step_summary();
|
427 |
+
$this->prepare_footer_button_list();
|
428 |
+
|
429 |
+
//taking current page form data
|
430 |
+
$filter_form_data=(isset($this->selected_template_form_data['filter_form_data']) ? $this->selected_template_form_data['filter_form_data'] : array());
|
431 |
+
|
432 |
+
$filter_screen_fields=$this->export_obj->get_filter_screen_fields($filter_form_data);
|
433 |
+
|
434 |
+
ob_start();
|
435 |
+
$this->prepare_step_header_html();
|
436 |
+
include_once dirname(plugin_dir_path(__FILE__)).'/views/_export_filter_page.php';
|
437 |
+
$this->prepare_step_footer_html();
|
438 |
+
return ob_get_clean();
|
439 |
+
|
440 |
+
}else
|
441 |
+
{
|
442 |
+
return '';
|
443 |
+
}
|
444 |
+
}
|
445 |
+
|
446 |
+
|
447 |
+
/**
|
448 |
+
* Step 4 (Ajax sub function)
|
449 |
+
* Built in steps, mapping page
|
450 |
+
*/
|
451 |
+
public function mapping_page()
|
452 |
+
{
|
453 |
+
$this->step='mapping';
|
454 |
+
$step_info= $this->get_step_info($this->step);
|
455 |
+
if($this->to_export!='')
|
456 |
+
{
|
457 |
+
|
458 |
+
$this->prepare_step_summary();
|
459 |
+
$this->prepare_footer_button_list();
|
460 |
+
|
461 |
+
//taking current page form data
|
462 |
+
$mapping_form_data=(isset($this->selected_template_form_data['mapping_form_data']) ? $this->selected_template_form_data['mapping_form_data'] : array());
|
463 |
+
|
464 |
+
|
465 |
+
/* form_data/template data of fields in mapping page */
|
466 |
+
$form_data_mapping_fields=isset($mapping_form_data['mapping_fields']) ? $mapping_form_data['mapping_fields'] : array();
|
467 |
+
|
468 |
+
/* default mapping page fields */
|
469 |
+
$mapping_fields=array();
|
470 |
+
$mapping_fields=apply_filters('wt_iew_exporter_alter_mapping_fields_basic', $mapping_fields, $this->to_export, $form_data_mapping_fields);
|
471 |
+
|
472 |
+
|
473 |
+
/* meta fields list */
|
474 |
+
$this->get_mapping_enabled_fields();
|
475 |
+
|
476 |
+
/* mapping enabled meta fields */
|
477 |
+
$form_data_mapping_enabled_fields=(isset($mapping_form_data['mapping_enabled_fields']) ? $mapping_form_data['mapping_enabled_fields'] : array());
|
478 |
+
|
479 |
+
ob_start();
|
480 |
+
$this->prepare_step_header_html();
|
481 |
+
include_once dirname(plugin_dir_path(__FILE__)).'/views/_export_mapping_page.php';
|
482 |
+
$this->prepare_step_footer_html();
|
483 |
+
return ob_get_clean();
|
484 |
+
}else
|
485 |
+
{
|
486 |
+
return '';
|
487 |
+
}
|
488 |
+
}
|
489 |
+
|
490 |
+
/**
|
491 |
+
* Step 5 (Ajax sub function)
|
492 |
+
* Built in steps, advanced page
|
493 |
+
*/
|
494 |
+
public function advanced_page()
|
495 |
+
{
|
496 |
+
$this->step='advanced';
|
497 |
+
$step_info=$this->steps[$this->step];
|
498 |
+
if($this->to_export!='')
|
499 |
+
{
|
500 |
+
|
501 |
+
$this->prepare_step_summary();
|
502 |
+
$this->prepare_footer_button_list();
|
503 |
+
|
504 |
+
//taking current page form data
|
505 |
+
$advanced_form_data=(isset($this->selected_template_form_data['advanced_form_data']) ? $this->selected_template_form_data['advanced_form_data'] : array());
|
506 |
+
|
507 |
+
$advanced_screen_fields=$this->export_obj->get_advanced_screen_fields($advanced_form_data);
|
508 |
+
|
509 |
+
ob_start();
|
510 |
+
$this->prepare_step_header_html();
|
511 |
+
include_once dirname(plugin_dir_path(__FILE__)).'/views/_export_advanced_page.php';
|
512 |
+
$this->prepare_step_footer_html();
|
513 |
+
return ob_get_clean();
|
514 |
+
|
515 |
+
}else
|
516 |
+
{
|
517 |
+
return '';
|
518 |
+
}
|
519 |
+
}
|
520 |
+
|
521 |
+
/**
|
522 |
+
* Get template form data
|
523 |
+
*/
|
524 |
+
protected function get_template_form_data($id)
|
525 |
+
{
|
526 |
+
$template_data=$this->get_mapping_template_by_id($id);
|
527 |
+
if($template_data)
|
528 |
+
{
|
529 |
+
$decoded_form_data=Wt_Import_Export_For_Woo_Basic_Common_Helper::process_formdata(maybe_unserialize($template_data['data']));
|
530 |
+
$this->selected_template_form_data=(!is_array($decoded_form_data) ? array() : $decoded_form_data);
|
531 |
+
}
|
532 |
+
}
|
533 |
+
|
534 |
+
/**
|
535 |
+
* Taking mapping template by Name
|
536 |
+
*/
|
537 |
+
protected function get_mapping_template_by_name($name)
|
538 |
+
{
|
539 |
+
global $wpdb;
|
540 |
+
$tb=$wpdb->prefix. Wt_Import_Export_For_Woo_Basic::$template_tb;
|
541 |
+
$qry=$wpdb->prepare("SELECT * FROM $tb WHERE template_type=%s AND item_type=%s AND name=%s",array('export', $this->to_export, $name));
|
542 |
+
return $wpdb->get_row($qry, ARRAY_A);
|
543 |
+
}
|
544 |
+
|
545 |
+
/**
|
546 |
+
* Taking mapping template by ID
|
547 |
+
*/
|
548 |
+
protected function get_mapping_template_by_id($id)
|
549 |
+
{
|
550 |
+
global $wpdb;
|
551 |
+
$tb=$wpdb->prefix.Wt_Import_Export_For_Woo_Basic::$template_tb;
|
552 |
+
$qry=$wpdb->prepare("SELECT * FROM $tb WHERE template_type=%s AND item_type=%s AND id=%d",array('export', $this->to_export, $id));
|
553 |
+
return $wpdb->get_row($qry, ARRAY_A);
|
554 |
+
}
|
555 |
+
|
556 |
+
/**
|
557 |
+
* Taking all mapping templates
|
558 |
+
*/
|
559 |
+
protected function get_mapping_templates()
|
560 |
+
{
|
561 |
+
if($this->to_export=='')
|
562 |
+
{
|
563 |
+
return;
|
564 |
+
}
|
565 |
+
global $wpdb;
|
566 |
+
$tb=$wpdb->prefix.Wt_Import_Export_For_Woo_Basic::$template_tb;
|
567 |
+
$val=$wpdb->get_results("SELECT * FROM $tb WHERE template_type='export' AND item_type='".$this->to_export."' ORDER BY id DESC", ARRAY_A);
|
568 |
+
|
569 |
+
//add a filter here for modules to alter the data
|
570 |
+
$this->mapping_templates=($val ? $val : array());
|
571 |
+
}
|
572 |
+
|
573 |
+
/**
|
574 |
+
* Get meta field list for mapping page
|
575 |
+
*
|
576 |
+
*/
|
577 |
+
protected function get_mapping_enabled_fields()
|
578 |
+
{
|
579 |
+
$mapping_enabled_fields=array(
|
580 |
+
// 'hidden_meta'=>array(__('Hidden meta'),0),
|
581 |
+
// 'meta'=>array(__('Meta'),1),
|
582 |
+
);
|
583 |
+
$this->mapping_enabled_fields=apply_filters('wt_iew_exporter_alter_mapping_enabled_fields_basic', $mapping_enabled_fields, $this->to_export, array());
|
584 |
+
}
|
585 |
+
|
586 |
+
protected function prepare_step_footer_html()
|
587 |
+
{
|
588 |
+
include dirname(plugin_dir_path(__FILE__)).'/views/_export_footer.php';
|
589 |
+
}
|
590 |
+
|
591 |
+
protected function prepare_step_summary()
|
592 |
+
{
|
593 |
+
$step_info= $this->get_step_info($this->step);
|
594 |
+
$this->step_title=$step_info['title'];
|
595 |
+
$this->step_keys=array_keys($this->steps);
|
596 |
+
$this->current_step_index=array_search($this->step, $this->step_keys);
|
597 |
+
$this->current_step_number=$this->current_step_index+1;
|
598 |
+
$this->last_page=(!isset($this->step_keys[$this->current_step_index+1]) ? true : false);
|
599 |
+
$this->total_steps=count($this->step_keys);
|
600 |
+
$this->step_summary=__(sprintf("Step %d of %d", $this->current_step_number, $this->total_steps));
|
601 |
+
}
|
602 |
+
|
603 |
+
protected function prepare_step_header_html()
|
604 |
+
{
|
605 |
+
include dirname(plugin_dir_path(__FILE__)).'/views/_export_header.php';
|
606 |
+
}
|
607 |
+
|
608 |
+
protected function prepare_footer_button_list()
|
609 |
+
{
|
610 |
+
$out=array();
|
611 |
+
$step_keys=$this->step_keys;
|
612 |
+
$current_index=$this->current_step_index;
|
613 |
+
$last_page=$this->last_page;
|
614 |
+
if($current_index!==false) /* step exists */
|
615 |
+
{
|
616 |
+
if($current_index>0) //add back button
|
617 |
+
{
|
618 |
+
$out['back']=array(
|
619 |
+
'type'=>'button',
|
620 |
+
'action_type'=>'step',
|
621 |
+
'key'=>$step_keys[$current_index-1],
|
622 |
+
'text'=>'<span class="dashicons dashicons-arrow-left-alt2" style="line-height:27px;"></span> '.__('Back'),
|
623 |
+
);
|
624 |
+
}
|
625 |
+
|
626 |
+
if(isset($step_keys[$current_index+1])) /* not last step */
|
627 |
+
{
|
628 |
+
$next_number=$current_index+2;
|
629 |
+
$next_key=$step_keys[$current_index+1];
|
630 |
+
$next_title=$this->steps[$next_key]['title'];
|
631 |
+
$out['next']=array(
|
632 |
+
'type'=>'button',
|
633 |
+
'action_type'=>'step',
|
634 |
+
'key'=>$next_key,
|
635 |
+
'text'=>__('Step').' '.$next_number.': '.$next_title.' <span class="dashicons dashicons-arrow-right-alt2" style="line-height:27px;"></span>',
|
636 |
+
);
|
637 |
+
|
638 |
+
if($this->export_method=='quick' || $this->export_method=='template') //Quick Or Template method
|
639 |
+
{
|
640 |
+
$out['or']=array(
|
641 |
+
'type'=>'text',
|
642 |
+
'text'=>__('Or'),
|
643 |
+
);
|
644 |
+
}
|
645 |
+
|
646 |
+
}else
|
647 |
+
{
|
648 |
+
$last_page=true;
|
649 |
+
}
|
650 |
+
|
651 |
+
if($this->export_method=='quick' || $this->export_method=='template' || $last_page) //template method, or last page, or quick export
|
652 |
+
{
|
653 |
+
if($last_page && $this->export_method!='quick') //last page and not quick export
|
654 |
+
{
|
655 |
+
if($this->export_method=='template')
|
656 |
+
{
|
657 |
+
$out['save']=array(
|
658 |
+
'key'=>'save',
|
659 |
+
'icon'=>'',
|
660 |
+
'type'=>'dropdown_button',
|
661 |
+
'text'=>__('Save template'),
|
662 |
+
'items'=>array(
|
663 |
+
'update'=>array(
|
664 |
+
'key'=>'update_template',
|
665 |
+
'text'=>__('Save'), //no prompt
|
666 |
+
),
|
667 |
+
'save'=>array(
|
668 |
+
'key'=>'save_template_as',
|
669 |
+
'text'=>__('Save As'), //prompt for name
|
670 |
+
)
|
671 |
+
)
|
672 |
+
);
|
673 |
+
}else
|
674 |
+
{
|
675 |
+
$out['save']=array(
|
676 |
+
'key'=>'save_template',
|
677 |
+
'icon'=>'',
|
678 |
+
'type'=>'button',
|
679 |
+
'text'=>__('Save template'), //prompt for name
|
680 |
+
);
|
681 |
+
}
|
682 |
+
}
|
683 |
+
|
684 |
+
if($last_page)
|
685 |
+
{
|
686 |
+
$out['export_image']=array(
|
687 |
+
'key'=>'export_image',
|
688 |
+
'class'=>'iew_export_image_btn',
|
689 |
+
'icon'=>'',
|
690 |
+
'type'=>'button',
|
691 |
+
'text'=>__('Export images'),
|
692 |
+
);
|
693 |
+
}
|
694 |
+
|
695 |
+
$out['export']=array(
|
696 |
+
'key'=>'export',
|
697 |
+
'class'=>'iew_export_btn',
|
698 |
+
'icon'=>'',
|
699 |
+
'type'=>'button',
|
700 |
+
'text'=>__('Export'),
|
701 |
+
);
|
702 |
+
}
|
703 |
+
}
|
704 |
+
$this->step_btns=apply_filters('wt_iew_exporter_alter_footer_btns_basic', $out, $this->step, $this->steps);
|
705 |
+
}
|
706 |
+
}
|
707 |
+
}
|
admin/modules/export/export.php
ADDED
@@ -0,0 +1,814 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Export section of the plugin
|
4 |
+
*
|
5 |
+
* @link
|
6 |
+
*
|
7 |
+
* @package Wt_Import_Export_For_Woo
|
8 |
+
*/
|
9 |
+
if (!defined('ABSPATH')) {
|
10 |
+
exit;
|
11 |
+
}
|
12 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Basic_Export')){
|
13 |
+
class Wt_Import_Export_For_Woo_Basic_Export
|
14 |
+
{
|
15 |
+
public $module_id='';
|
16 |
+
public static $module_id_static='';
|
17 |
+
public $module_base='export';
|
18 |
+
|
19 |
+
public static $export_dir=WP_CONTENT_DIR.'/webtoffee_export';
|
20 |
+
public static $export_dir_name='/webtoffee_export';
|
21 |
+
public $steps=array();
|
22 |
+
public $allowed_export_file_type=array();
|
23 |
+
|
24 |
+
private $to_export='';
|
25 |
+
private $to_export_id='';
|
26 |
+
private $rerun_id=0;
|
27 |
+
public $export_method='';
|
28 |
+
public $export_methods=array();
|
29 |
+
public $selected_template=0;
|
30 |
+
public $default_batch_count=0; /* configure this value in `advanced_setting_fields` method */
|
31 |
+
public $selected_template_data=array();
|
32 |
+
public $default_export_method=''; /* configure this value in `advanced_setting_fields` method */
|
33 |
+
public $form_data=array();
|
34 |
+
|
35 |
+
public function __construct()
|
36 |
+
{
|
37 |
+
$this->module_id=Wt_Import_Export_For_Woo_Basic::get_module_id($this->module_base);
|
38 |
+
self::$module_id_static=$this->module_id;
|
39 |
+
|
40 |
+
/* allowed file types */
|
41 |
+
$this->allowed_export_file_type=array(
|
42 |
+
'csv'=>__('CSV'),
|
43 |
+
'xml'=>__('XML')
|
44 |
+
);
|
45 |
+
|
46 |
+
/* default step list */
|
47 |
+
$this->steps=array
|
48 |
+
(
|
49 |
+
'post_type'=>array(
|
50 |
+
'title'=>__('Select a post type'),
|
51 |
+
'description'=>__('Export and download the respective post type into a CSV. This file can also be used to import data related to the specific post type back into your WooCommerce shop. As a first step you need to choose the post type to start the export.'),
|
52 |
+
),
|
53 |
+
'method_export'=>array(
|
54 |
+
'title'=>__('Select an export method'),
|
55 |
+
'description'=>__('Choose from the options below to continue with your export: quick export from DB, based on a pre-saved template or a new export with advanced options.'),
|
56 |
+
),
|
57 |
+
'filter'=>array(
|
58 |
+
'title'=>__('Filter data'),
|
59 |
+
'description'=>__('Filter data that needs to be exported as per the below criteria.'),
|
60 |
+
),
|
61 |
+
'mapping'=>array(
|
62 |
+
'title'=>__('Map and reorder export columns'),
|
63 |
+
'description'=>__('The default export column names can be edited from the screen below, if required. If you have chosen a pre-saved template you can see the preferred names and choices that were last saved. You may also drag the columns accordingly to reorder them within the output file.'),
|
64 |
+
),
|
65 |
+
'advanced'=>array(
|
66 |
+
'title'=>__('Advanced options/Batch export'),
|
67 |
+
'description'=>__('You can save the template file for future exports or proceed with the export.'),
|
68 |
+
),
|
69 |
+
);
|
70 |
+
|
71 |
+
|
72 |
+
$this->validation_rule=array(
|
73 |
+
'post_type'=>array(), /* no validation rule. So default sanitization text */
|
74 |
+
'method_export'=>array(
|
75 |
+
'mapping_enabled_fields' => array('type'=>'text_arr') //in case of quick export
|
76 |
+
)
|
77 |
+
);
|
78 |
+
|
79 |
+
$this->step_need_validation_filter=array('filter', 'advanced');
|
80 |
+
|
81 |
+
|
82 |
+
$this->export_methods=array(
|
83 |
+
'quick'=>array('title'=>__('Quick export'), 'description'=> __('Exports all the basic fields.')),
|
84 |
+
'template'=>array('title'=>__('Pre-saved template'), 'description'=> __('Exports data as per the specifications(filters,selective column,mapping etc) from the previously saved file.')),
|
85 |
+
'new'=>array('title'=>__('Advanced export'), 'description'=> __('Exports data after a detailed process of data filtering/column selection/advanced options that may be required for your export. You can also save this file for future use.')),
|
86 |
+
);
|
87 |
+
|
88 |
+
/* advanced plugin settings */
|
89 |
+
add_filter('wt_iew_advanced_setting_fields_basic', array($this, 'advanced_setting_fields'));
|
90 |
+
|
91 |
+
/* setting default values, this method must be below of advanced setting filter */
|
92 |
+
$this->get_defaults();
|
93 |
+
|
94 |
+
/* main ajax hook. The callback function will decide which is to execute. */
|
95 |
+
add_action('wp_ajax_iew_export_ajax_basic', array($this, 'ajax_main'), 11);
|
96 |
+
|
97 |
+
/* Admin menu for export */
|
98 |
+
add_filter('wt_iew_admin_menu_basic', array($this, 'add_admin_pages'), 10, 1);
|
99 |
+
|
100 |
+
/* Download export file via nonce URL */
|
101 |
+
add_action('admin_init', array($this, 'download_file'), 11);
|
102 |
+
}
|
103 |
+
|
104 |
+
public function get_defaults()
|
105 |
+
{
|
106 |
+
$this->default_export_method= Wt_Import_Export_For_Woo_Basic_Common_Helper::get_advanced_settings('default_export_method');
|
107 |
+
$this->default_batch_count=Wt_Import_Export_For_Woo_Basic_Common_Helper::get_advanced_settings('default_export_batch');
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Fields for advanced settings
|
112 |
+
*
|
113 |
+
*/
|
114 |
+
public function advanced_setting_fields($fields)
|
115 |
+
{
|
116 |
+
$export_methods=array_map(function($vl){ return $vl['title']; }, $this->export_methods);
|
117 |
+
$fields['default_export_method']=array(
|
118 |
+
'label'=>__("Default Export method"),
|
119 |
+
'type'=>'select',
|
120 |
+
'sele_vals'=>$export_methods,
|
121 |
+
'value' =>'quick',
|
122 |
+
'field_name'=>'default_export_method',
|
123 |
+
'field_group'=>'advanced_field',
|
124 |
+
'help_text'=>__('Select the default method of export.'),
|
125 |
+
);
|
126 |
+
$fields['default_export_batch']=array(
|
127 |
+
'label'=>__("Default Export batch count"),
|
128 |
+
'type'=>'number',
|
129 |
+
'value' =>100,
|
130 |
+
'field_name'=>'default_export_batch',
|
131 |
+
'help_text'=>__('Provide the default count for the records to be exported in a batch.'),
|
132 |
+
'validation_rule'=>array('type'=>'absint'),
|
133 |
+
);
|
134 |
+
return $fields;
|
135 |
+
}
|
136 |
+
|
137 |
+
/**
|
138 |
+
* Adding admin menus
|
139 |
+
*/
|
140 |
+
public function add_admin_pages($menus)
|
141 |
+
{
|
142 |
+
$menu_temp=array(
|
143 |
+
$this->module_base=>array(
|
144 |
+
'menu',
|
145 |
+
__('Export'),
|
146 |
+
__('WebToffee Import Export (Basic)'),
|
147 |
+
'manage_options',
|
148 |
+
$this->module_id,
|
149 |
+
array($this,'admin_settings_page'),
|
150 |
+
'dashicons-controls-repeat',
|
151 |
+
56
|
152 |
+
),
|
153 |
+
$this->module_base.'-sub'=>array(
|
154 |
+
'submenu',
|
155 |
+
$this->module_id,
|
156 |
+
__('Export'),
|
157 |
+
__('Export'),
|
158 |
+
"manage_options",
|
159 |
+
$this->module_id,
|
160 |
+
array($this, 'admin_settings_page')
|
161 |
+
),
|
162 |
+
);
|
163 |
+
unset($menus['general-settings']);
|
164 |
+
$menus=array_merge($menu_temp, $menus);
|
165 |
+
return $menus;
|
166 |
+
}
|
167 |
+
|
168 |
+
/**
|
169 |
+
* Export page
|
170 |
+
*/
|
171 |
+
public function admin_settings_page()
|
172 |
+
{
|
173 |
+
/**
|
174 |
+
* Check it is a rerun call
|
175 |
+
*/
|
176 |
+
$requested_rerun_id=(isset($_GET['wt_iew_rerun']) ? absint($_GET['wt_iew_rerun']) : 0);
|
177 |
+
$this->_process_rerun($requested_rerun_id);
|
178 |
+
|
179 |
+
$this->enqueue_assets();
|
180 |
+
include plugin_dir_path(__FILE__).'views/main.php';
|
181 |
+
}
|
182 |
+
|
183 |
+
/**
|
184 |
+
* Main ajax hook to handle all export related requests
|
185 |
+
*/
|
186 |
+
public function ajax_main()
|
187 |
+
{
|
188 |
+
|
189 |
+
include_once plugin_dir_path(__FILE__).'classes/class-export-ajax.php';
|
190 |
+
if(Wt_Iew_Sh::check_write_access(WT_IEW_PLUGIN_ID_BASIC))
|
191 |
+
{
|
192 |
+
/**
|
193 |
+
* Check it is a rerun call
|
194 |
+
*/
|
195 |
+
if(!$this->_process_rerun((isset($_POST['rerun_id']) ? absint($_POST['rerun_id']) : 0)))
|
196 |
+
{
|
197 |
+
$this->export_method=(isset($_POST['export_method']) ? Wt_Iew_Sh::sanitize_item($_POST['export_method'], 'text') : '');
|
198 |
+
$this->to_export=(isset($_POST['to_export']) ? Wt_Iew_Sh::sanitize_item($_POST['to_export'], 'text') : '');
|
199 |
+
$this->selected_template=(isset($_POST['selected_template']) ? Wt_Iew_Sh::sanitize_item($_POST['selected_template'], 'int') : 0);
|
200 |
+
}
|
201 |
+
|
202 |
+
$this->get_steps();
|
203 |
+
|
204 |
+
$ajax_obj=new Wt_Import_Export_For_Woo_Basic_Export_Ajax($this, $this->to_export, $this->steps, $this->export_method, $this->selected_template, $this->rerun_id);
|
205 |
+
|
206 |
+
$export_action=Wt_Iew_Sh::sanitize_item($_POST['export_action'], 'text');
|
207 |
+
$data_type=Wt_Iew_Sh::sanitize_item($_POST['data_type'], 'text');
|
208 |
+
|
209 |
+
$allowed_ajax_actions=array('get_steps', 'get_meta_mapping_fields', 'save_template', 'save_template_as', 'update_template', 'upload', 'export', 'export_image');
|
210 |
+
|
211 |
+
$out=array(
|
212 |
+
'status'=>0,
|
213 |
+
'msg'=>__('Error'),
|
214 |
+
);
|
215 |
+
|
216 |
+
if(method_exists($ajax_obj, $export_action) && in_array($export_action, $allowed_ajax_actions))
|
217 |
+
{
|
218 |
+
$out=$ajax_obj->{$export_action}($out);
|
219 |
+
}
|
220 |
+
|
221 |
+
if($data_type=='json')
|
222 |
+
{
|
223 |
+
echo json_encode($out);
|
224 |
+
}
|
225 |
+
}
|
226 |
+
exit();
|
227 |
+
}
|
228 |
+
|
229 |
+
public function get_filter_screen_fields($filter_form_data)
|
230 |
+
{
|
231 |
+
$filter_screen_fields=array(
|
232 |
+
'limit'=>array(
|
233 |
+
'label'=>__("Limit"),
|
234 |
+
'value'=>'',
|
235 |
+
'type' => 'number',
|
236 |
+
'field_name'=>'limit',
|
237 |
+
'placeholder'=>'Unlimited',
|
238 |
+
'help_text'=>__('The actual number of records you want to export. e.g. A limit of 500 with an offset 10 will export records from 11th to 510th position.'),
|
239 |
+
//'validation_rule'=>array('type'=>'int'),
|
240 |
+
),
|
241 |
+
'offset'=>array(
|
242 |
+
'label'=>__("Offset"),
|
243 |
+
'value'=>0,
|
244 |
+
'field_name'=>'offset',
|
245 |
+
'help_text'=>__('Specify the number of records that should be skipped from the beginning. e.g. An offset of 10 skips the first 10 records.'),
|
246 |
+
'validation_rule'=>array('type'=>'int'),
|
247 |
+
),
|
248 |
+
);
|
249 |
+
$filter_screen_fields=apply_filters('wt_iew_exporter_alter_filter_fields_basic', $filter_screen_fields, $this->to_export, $filter_form_data);
|
250 |
+
return $filter_screen_fields;
|
251 |
+
}
|
252 |
+
|
253 |
+
public function get_advanced_screen_fields($advanced_form_data)
|
254 |
+
{
|
255 |
+
$file_into_arr=array('local'=>__('Local'));
|
256 |
+
|
257 |
+
/* taking available remote adapters */
|
258 |
+
$remote_adapter_names=array();
|
259 |
+
$remote_adapter_names=apply_filters('wt_iew_exporter_remote_adapter_names_basic', $remote_adapter_names);
|
260 |
+
if($remote_adapter_names && is_array($remote_adapter_names))
|
261 |
+
{
|
262 |
+
foreach($remote_adapter_names as $remote_adapter_key => $remote_adapter_vl)
|
263 |
+
{
|
264 |
+
$file_into_arr[$remote_adapter_key]=$remote_adapter_vl;
|
265 |
+
}
|
266 |
+
}
|
267 |
+
|
268 |
+
|
269 |
+
$advanced_screen_fields=array(
|
270 |
+
|
271 |
+
'batch_count'=>array(
|
272 |
+
'label'=>__("Export in batches of"),
|
273 |
+
'type'=>'text',
|
274 |
+
'value'=>$this->default_batch_count,
|
275 |
+
'field_name'=>'batch_count',
|
276 |
+
'help_text'=>sprintf(__('The number of records that the server will process for every iteration within the configured timeout interval. If the export fails due to timeout you can lower this number accordingly and try again. Defaulted to %d records.'), 100),
|
277 |
+
'validation_rule'=>array('type'=>'absint'),
|
278 |
+
)
|
279 |
+
);
|
280 |
+
|
281 |
+
/* taking advanced fields from post type modules */
|
282 |
+
$advanced_screen_fields=apply_filters('wt_iew_exporter_alter_advanced_fields_basic', $advanced_screen_fields, $this->to_export, $advanced_form_data);
|
283 |
+
return $advanced_screen_fields;
|
284 |
+
}
|
285 |
+
|
286 |
+
/**
|
287 |
+
* Get steps
|
288 |
+
*
|
289 |
+
*/
|
290 |
+
public function get_steps()
|
291 |
+
{
|
292 |
+
if($this->export_method=='quick') /* if quick export then remove some steps */
|
293 |
+
{
|
294 |
+
$out=array(
|
295 |
+
'post_type'=>$this->steps['post_type'],
|
296 |
+
'method_export'=>$this->steps['method_export'],
|
297 |
+
'advanced'=>$this->steps['advanced'],
|
298 |
+
);
|
299 |
+
$this->steps=$out;
|
300 |
+
}
|
301 |
+
$this->steps=apply_filters('wt_iew_exporter_steps_basic', $this->steps, $this->to_export);
|
302 |
+
return $this->steps;
|
303 |
+
}
|
304 |
+
|
305 |
+
|
306 |
+
/**
|
307 |
+
* Validating and Processing rerun action
|
308 |
+
*/
|
309 |
+
protected function _process_rerun($rerun_id)
|
310 |
+
{
|
311 |
+
if($rerun_id>0)
|
312 |
+
{
|
313 |
+
/* check the history module is available */
|
314 |
+
$history_module_obj=Wt_Import_Export_For_Woo_Basic::load_modules('history');
|
315 |
+
if(!is_null($history_module_obj))
|
316 |
+
{
|
317 |
+
/* check the history entry is for export and also has form_data */
|
318 |
+
$history_data=$history_module_obj->get_history_entry_by_id($rerun_id);
|
319 |
+
if($history_data && $history_data['template_type']==$this->module_base)
|
320 |
+
{
|
321 |
+
$form_data=maybe_unserialize($history_data['data']);
|
322 |
+
if($form_data && is_array($form_data))
|
323 |
+
{
|
324 |
+
$this->to_export=(isset($form_data['post_type_form_data']) && isset($form_data['post_type_form_data']['item_type']) ? $form_data['post_type_form_data']['item_type'] : '');
|
325 |
+
if($this->to_export!="")
|
326 |
+
{
|
327 |
+
$this->export_method=(isset($form_data['method_export_form_data']) && isset($form_data['method_export_form_data']['method_export']) && $form_data['method_export_form_data']['method_export']!="" ? $form_data['method_export_form_data']['method_export'] : $this->default_export_method);
|
328 |
+
$this->rerun_id=$rerun_id;
|
329 |
+
$this->form_data=$form_data;
|
330 |
+
//process steps based on the export method in the history entry
|
331 |
+
$this->get_steps();
|
332 |
+
|
333 |
+
return true;
|
334 |
+
}
|
335 |
+
}
|
336 |
+
}
|
337 |
+
}
|
338 |
+
}
|
339 |
+
return false;
|
340 |
+
}
|
341 |
+
|
342 |
+
protected function enqueue_assets()
|
343 |
+
{
|
344 |
+
if(Wt_Import_Export_For_Woo_Basic_Common_Helper::wt_is_screen_allowed()){
|
345 |
+
wp_enqueue_script($this->module_id, plugin_dir_url(__FILE__).'assets/js/main.js', array('jquery', 'jquery-ui-sortable', 'jquery-ui-datepicker'), WT_O_IEW_VERSION);
|
346 |
+
wp_enqueue_style('jquery-ui-datepicker');
|
347 |
+
wp_enqueue_style(WT_IEW_PLUGIN_ID_BASIC.'-jquery-ui', WT_O_IEW_PLUGIN_URL.'admin/css/jquery-ui.css', array(), WT_O_IEW_VERSION, 'all');
|
348 |
+
$params=array(
|
349 |
+
'item_type'=>'',
|
350 |
+
'steps'=>$this->steps,
|
351 |
+
'rerun_id'=>$this->rerun_id,
|
352 |
+
'to_export'=>$this->to_export,
|
353 |
+
'export_method'=>$this->export_method,
|
354 |
+
'msgs'=>array(
|
355 |
+
'choosed_template'=>__('Choosed template: '),
|
356 |
+
'choose_export_method'=>__('Please select an export method.'),
|
357 |
+
'choose_template'=>__('Please select an export template.'),
|
358 |
+
'step'=>__('Step'),
|
359 |
+
'choose_ftp_profile'=>__('Please select an FTP profile.'),
|
360 |
+
),
|
361 |
+
);
|
362 |
+
wp_localize_script($this->module_id, 'wt_iew_export_basic_params', $params);
|
363 |
+
|
364 |
+
$this->add_select2_lib(); //adding select2 JS, It checks the availibility of woocommerce
|
365 |
+
}
|
366 |
+
}
|
367 |
+
|
368 |
+
/**
|
369 |
+
*
|
370 |
+
* Enqueue select2 library, if woocommerce available use that
|
371 |
+
*/
|
372 |
+
protected function add_select2_lib()
|
373 |
+
{
|
374 |
+
/* enqueue scripts */
|
375 |
+
if(!function_exists('is_plugin_active'))
|
376 |
+
{
|
377 |
+
include_once(ABSPATH.'wp-admin/includes/plugin.php');
|
378 |
+
}
|
379 |
+
if(is_plugin_active('woocommerce/woocommerce.php'))
|
380 |
+
{
|
381 |
+
wp_enqueue_script('wc-enhanced-select');
|
382 |
+
wp_enqueue_style('woocommerce_admin_styles', WC()->plugin_url().'/assets/css/admin.css');
|
383 |
+
}else
|
384 |
+
{
|
385 |
+
wp_enqueue_style(WT_IEW_PLUGIN_ID_BASIC.'-select2', WT_O_IEW_PLUGIN_URL. 'admin/css/select2.css', array(), WT_O_IEW_VERSION, 'all' );
|
386 |
+
wp_enqueue_script(WT_IEW_PLUGIN_ID_BASIC.'-select2', WT_O_IEW_PLUGIN_URL.'admin/js/select2.js', array('jquery'), WT_O_IEW_VERSION, false );
|
387 |
+
}
|
388 |
+
}
|
389 |
+
|
390 |
+
|
391 |
+
/**
|
392 |
+
* Upload data to the user choosed remote method (Eg: FTP)
|
393 |
+
* @param string $step the action to perform, here 'upload'
|
394 |
+
*
|
395 |
+
* @return array
|
396 |
+
*/
|
397 |
+
public function process_upload($step, $export_id, $to_export)
|
398 |
+
{
|
399 |
+
$out=array(
|
400 |
+
'response'=>false,
|
401 |
+
'export_id'=>0,
|
402 |
+
'history_id'=>0, //same as that of export id
|
403 |
+
'finished'=>0,
|
404 |
+
'file_url'=>'',
|
405 |
+
'msg'=>'',
|
406 |
+
);
|
407 |
+
|
408 |
+
if($export_id==0) //it may be an error
|
409 |
+
{
|
410 |
+
return $out;
|
411 |
+
}
|
412 |
+
|
413 |
+
//take history data by export_id
|
414 |
+
$export_data=Wt_Import_Export_For_Woo_Basic_History::get_history_entry_by_id($export_id);
|
415 |
+
if(is_null($export_data)) //no record found so it may be an error
|
416 |
+
{
|
417 |
+
return $out;
|
418 |
+
}
|
419 |
+
|
420 |
+
$form_data=maybe_unserialize($export_data['data']);
|
421 |
+
|
422 |
+
//taking file name
|
423 |
+
$file_name=(isset($export_data['file_name']) ? $export_data['file_name'] : '');
|
424 |
+
|
425 |
+
$file_path=$this->get_file_path($file_name);
|
426 |
+
if($file_path===false)
|
427 |
+
{
|
428 |
+
$update_data=array(
|
429 |
+
'status'=>Wt_Import_Export_For_Woo_Basic_History::$status_arr['failed'],
|
430 |
+
'status_text'=>'File not found.' //no need to add translation function
|
431 |
+
);
|
432 |
+
$update_data_type=array(
|
433 |
+
'%d',
|
434 |
+
'%s',
|
435 |
+
);
|
436 |
+
Wt_Import_Export_For_Woo_Basic_History::update_history_entry($export_id, $update_data, $update_data_type);
|
437 |
+
|
438 |
+
return $out;
|
439 |
+
}
|
440 |
+
|
441 |
+
/* updating output parameters */
|
442 |
+
$out['export_id']=$export_id;
|
443 |
+
$out['history_id']=$export_id;
|
444 |
+
$out['file_url']='';
|
445 |
+
|
446 |
+
//check where to copy the files
|
447 |
+
$file_into='local';
|
448 |
+
if(isset($form_data['advanced_form_data']))
|
449 |
+
{
|
450 |
+
$file_into=(isset($form_data['advanced_form_data']['wt_iew_file_into']) ? $form_data['advanced_form_data']['wt_iew_file_into'] : 'local');
|
451 |
+
}
|
452 |
+
|
453 |
+
if('local' != $file_into) /* file not save to local. Initiate the choosed remote profile */
|
454 |
+
{
|
455 |
+
$remote_adapter=Wt_Import_Export_For_Woo_Basic::get_remote_adapters('export', $file_into);
|
456 |
+
if(is_null($remote_adapter)) /* adapter object not found */
|
457 |
+
{
|
458 |
+
$msg=sprintf('Unable to initailize %s', $file_into);
|
459 |
+
Wt_Import_Export_For_Woo_Basic_History::record_failure($export_id, $msg);
|
460 |
+
$out['msg']=__($msg);
|
461 |
+
return $out;
|
462 |
+
}
|
463 |
+
|
464 |
+
/* upload the file */
|
465 |
+
$upload_out_format = array('response'=>true, 'msg'=>'');
|
466 |
+
|
467 |
+
$advanced_form_data=(isset($form_data['advanced_form_data']) ? $form_data['advanced_form_data'] : array());
|
468 |
+
|
469 |
+
$upload_data = $remote_adapter->upload($file_path, $file_name, $advanced_form_data, $upload_out_format);
|
470 |
+
$out['response'] = (isset($upload_data['response']) ? $upload_data['response'] : false);
|
471 |
+
$out['msg'] = (isset($upload_data['msg']) ? $upload_data['msg'] : __('Error'));
|
472 |
+
|
473 |
+
//unlink the local file
|
474 |
+
@unlink($file_path);
|
475 |
+
}else
|
476 |
+
{
|
477 |
+
$out['response']=true;
|
478 |
+
$out['file_url']=html_entity_decode($this->get_file_url($file_name));
|
479 |
+
}
|
480 |
+
|
481 |
+
$out['finished']=1; //if any error then also its finished, but with errors
|
482 |
+
if($out['response'] === true) //success
|
483 |
+
{
|
484 |
+
$out['msg']=__('Finished');
|
485 |
+
|
486 |
+
/* updating finished status */
|
487 |
+
$update_data=array(
|
488 |
+
'status'=>1 //success
|
489 |
+
);
|
490 |
+
$update_data_type=array(
|
491 |
+
'%d'
|
492 |
+
);
|
493 |
+
Wt_Import_Export_For_Woo_Basic_History::update_history_entry($export_id, $update_data, $update_data_type);
|
494 |
+
|
495 |
+
}else //failed
|
496 |
+
{
|
497 |
+
//no need to add translation function in message
|
498 |
+
Wt_Import_Export_For_Woo_Basic_History::record_failure($export_id, 'Failed while uploading');
|
499 |
+
}
|
500 |
+
return $out;
|
501 |
+
}
|
502 |
+
|
503 |
+
|
504 |
+
/**
|
505 |
+
* Do the export process
|
506 |
+
*/
|
507 |
+
public function process_action($form_data, $step, $to_process, $file_name='', $export_id=0, $offset=0)
|
508 |
+
{
|
509 |
+
$out=array(
|
510 |
+
'response'=>false,
|
511 |
+
'new_offset'=>0,
|
512 |
+
'export_id'=>0,
|
513 |
+
'history_id'=>0, //same as that of export id
|
514 |
+
'total_records'=>0,
|
515 |
+
'finished'=>0,
|
516 |
+
'file_url'=>'',
|
517 |
+
'msg'=>'',
|
518 |
+
);
|
519 |
+
|
520 |
+
/* prepare form_data, If this was not first batch */
|
521 |
+
if($export_id>0)
|
522 |
+
{
|
523 |
+
//take history data by export_id
|
524 |
+
$export_data=Wt_Import_Export_For_Woo_Basic_History::get_history_entry_by_id($export_id);
|
525 |
+
if(is_null($export_data)) //no record found so it may be an error
|
526 |
+
{
|
527 |
+
return $out;
|
528 |
+
}
|
529 |
+
|
530 |
+
//processing form data
|
531 |
+
$form_data=(isset($export_data['data']) ? maybe_unserialize($export_data['data']) : array());
|
532 |
+
}
|
533 |
+
$this->to_export=$to_process;
|
534 |
+
$default_batch_count=$this->_get_default_batch_count($form_data);
|
535 |
+
$batch_count=$default_batch_count;
|
536 |
+
$file_as='csv';
|
537 |
+
$csv_delimiter=',';
|
538 |
+
$total_records=0;
|
539 |
+
if(isset($form_data['advanced_form_data']))
|
540 |
+
{
|
541 |
+
$batch_count=(isset($form_data['advanced_form_data']['wt_iew_batch_count']) ? $form_data['advanced_form_data']['wt_iew_batch_count'] : $batch_count);
|
542 |
+
$file_as=(isset($form_data['advanced_form_data']['wt_iew_file_as']) ? $form_data['advanced_form_data']['wt_iew_file_as'] : 'csv');
|
543 |
+
$csv_delimiter=(isset($form_data['advanced_form_data']['wt_iew_delimiter']) ? $form_data['advanced_form_data']['wt_iew_delimiter'] : ',');
|
544 |
+
$csv_delimiter=($csv_delimiter=="" ? ',' : $csv_delimiter);
|
545 |
+
}
|
546 |
+
$file_as=(isset($this->allowed_export_file_type[$file_as]) ? $file_as : 'csv');
|
547 |
+
|
548 |
+
|
549 |
+
$generated_file_name=$this->to_export.'_export_'.date('Y-m-d-h-i-s').'.'.$file_as;
|
550 |
+
|
551 |
+
if($export_id==0) //first batch then create a history entry
|
552 |
+
{
|
553 |
+
$file_name=($file_name=="" ? $generated_file_name : sanitize_file_name($file_name.'.'.$file_as));
|
554 |
+
$export_id=Wt_Import_Export_For_Woo_Basic_History::create_history_entry($file_name, $form_data, $this->to_export, $step);
|
555 |
+
$offset=0;
|
556 |
+
}else
|
557 |
+
{
|
558 |
+
//taking file name from export data
|
559 |
+
$file_name=(isset($export_data['file_name']) ? $export_data['file_name'] : $generated_file_name);
|
560 |
+
$total_records=(isset($export_data['total']) ? $export_data['total'] : 0);
|
561 |
+
}
|
562 |
+
|
563 |
+
/* setting history_id in Log section */
|
564 |
+
Wt_Import_Export_For_Woo_Basic_Log::$history_id=$export_id;
|
565 |
+
|
566 |
+
|
567 |
+
$file_path=$this->get_file_path($file_name);
|
568 |
+
if($file_path===false)
|
569 |
+
{
|
570 |
+
$msg='Unable to create backup directory. Please grant write permission for `wp-content` folder.';
|
571 |
+
|
572 |
+
//no need to add translation function in message
|
573 |
+
Wt_Import_Export_For_Woo_Basic_History::record_failure($export_id, $msg);
|
574 |
+
|
575 |
+
$out['msg']=__($msg);
|
576 |
+
return $out;
|
577 |
+
}
|
578 |
+
|
579 |
+
/* giving full data */
|
580 |
+
$form_data=apply_filters('wt_iew_export_full_form_data_basic', $form_data, $to_process, $step, $this->selected_template_data);
|
581 |
+
|
582 |
+
/* hook to get data from corresponding module. Eg: product, order */
|
583 |
+
$export_data=array(
|
584 |
+
'total'=>100,
|
585 |
+
'head_data'=>array("abc"=>"hd1", "bcd"=>"hd2", "cde"=>"hd3", "def"=>"hd4"),
|
586 |
+
'body_data'=>array(
|
587 |
+
array("abc"=>"Abc1", "bcd"=>"Bcd1", "cde"=>"Cde1", "def"=>"Def1"),
|
588 |
+
array("abc"=>"Abc2", "bcd"=>"Bcd2", "cde"=>"Cde2", "def"=>"Def2")
|
589 |
+
),
|
590 |
+
);
|
591 |
+
|
592 |
+
/* in scheduled export. The export method will not available so we need to take it from form_data */
|
593 |
+
$form_data_export_method=(isset($form_data['method_export_form_data']) && isset($form_data['method_export_form_data']['method_export']) ? $form_data['method_export_form_data']['method_export'] : $this->default_export_method);
|
594 |
+
$this->export_method=($this->export_method=="" ? $form_data_export_method : $this->export_method);
|
595 |
+
|
596 |
+
$export_data=apply_filters('wt_iew_exporter_do_export_basic', $export_data, $to_process, $step, $form_data, $this->selected_template_data, $this->export_method, $offset);
|
597 |
+
if($offset==0)
|
598 |
+
{
|
599 |
+
$total_records=intval(isset($export_data['total']) ? $export_data['total'] : 0);
|
600 |
+
}
|
601 |
+
$this->_update_history_after_export($export_id, $offset, $total_records, $export_data);
|
602 |
+
|
603 |
+
/* checking action is finshed */
|
604 |
+
$is_last_offset=false;
|
605 |
+
$new_offset=$offset+$batch_count; //increase the offset
|
606 |
+
if($new_offset>=$total_records) //finished
|
607 |
+
{
|
608 |
+
$is_last_offset=true;
|
609 |
+
}
|
610 |
+
|
611 |
+
|
612 |
+
/* no data from corresponding module */
|
613 |
+
if(!$export_data) //error !!!
|
614 |
+
{
|
615 |
+
//return $out;
|
616 |
+
}else
|
617 |
+
{
|
618 |
+
|
619 |
+
include_once WT_O_IEW_PLUGIN_PATH.'admin/classes/class-csvwriter.php';
|
620 |
+
$writer=new Wt_Import_Export_For_Woo_Basic_Csvwriter($file_path, $offset, $csv_delimiter);
|
621 |
+
|
622 |
+
|
623 |
+
/**
|
624 |
+
* Alter export data before writing to file.
|
625 |
+
* @param array $export_data data to export
|
626 |
+
* @param int $offset current offset
|
627 |
+
* @param boolean $is_last_offset is current offset is last one
|
628 |
+
* @param string $file_as file type to write Eg: XML, CSV
|
629 |
+
* @param string $to_export Post type
|
630 |
+
* @param string $csv_delimiter CSV delimiter. In case of CSV export
|
631 |
+
* @return array $export_data Altered export data
|
632 |
+
*/
|
633 |
+
$export_data=apply_filters('wt_iew_alter_export_data_basic', $export_data, $offset, $is_last_offset, $file_as, $this->to_export, $csv_delimiter);
|
634 |
+
|
635 |
+
$writer->write_to_file($export_data, $offset, $is_last_offset, $this->to_export);
|
636 |
+
}
|
637 |
+
|
638 |
+
/* updating output parameters */
|
639 |
+
$out['total_records']=$total_records;
|
640 |
+
$out['export_id']=$export_id;
|
641 |
+
$out['history_id']=$export_id;
|
642 |
+
$out['file_url']='';
|
643 |
+
$out['response']=true;
|
644 |
+
|
645 |
+
/* updating action is finshed */
|
646 |
+
if($is_last_offset) //finished
|
647 |
+
{
|
648 |
+
//check where to copy the files
|
649 |
+
$file_into='local';
|
650 |
+
if(isset($form_data['advanced_form_data']))
|
651 |
+
{
|
652 |
+
$file_into=(isset($form_data['advanced_form_data']['wt_iew_file_into']) ? $form_data['advanced_form_data']['wt_iew_file_into'] : 'local');
|
653 |
+
}
|
654 |
+
if('local' != $file_into) /* file not save to local. Initiate the choosed remote profile */
|
655 |
+
{
|
656 |
+
$out['finished']=2; //file created, next upload it
|
657 |
+
|
658 |
+
$out['msg']=sprintf(__('Uploading to %s'), $file_into);
|
659 |
+
}else
|
660 |
+
{
|
661 |
+
$out['file_url']=html_entity_decode($this->get_file_url($file_name));
|
662 |
+
$out['finished']=1; //finished
|
663 |
+
|
664 |
+
$msg = __('Export file processing completed');
|
665 |
+
$msg.='<span class="wt_iew_popup_close" style="line-height:10px;width:auto" onclick="wt_iew_basic_export.hide_export_info_box();">X</span>';
|
666 |
+
|
667 |
+
$msg.='<span class="wt_iew_info_box_finished_text" style="font-size: 10px; display:block">';
|
668 |
+
if(Wt_Import_Export_For_Woo_Admin_Basic::module_exists('history'))
|
669 |
+
{
|
670 |
+
$history_module_id= Wt_Import_Export_For_Woo_Basic::get_module_id('history');
|
671 |
+
$history_page_url=admin_url('admin.php?page='.$history_module_id);
|
672 |
+
$msg.=__('You can manage exports from History section.');
|
673 |
+
// $msg.=sprintf(__('You can manage exports from %s History %s section.'), '<a href="'.$history_page_url.'" target="_blank">', '</a>');
|
674 |
+
}
|
675 |
+
|
676 |
+
$msg.='<a class="button button-secondary" style="margin-top:10px;" onclick="wt_iew_basic_export.hide_export_info_box();" target="_blank" href="'.$out['file_url'].'" >'.__('Download file').'</a></span>';
|
677 |
+
|
678 |
+
$out['msg']=$msg;
|
679 |
+
|
680 |
+
/* updating finished status */
|
681 |
+
$update_data=array(
|
682 |
+
'status'=>Wt_Import_Export_For_Woo_Basic_History::$status_arr['finished'],
|
683 |
+
'status_text'=>'Finished' //translation function not needed
|
684 |
+
);
|
685 |
+
$update_data_type=array(
|
686 |
+
'%d',
|
687 |
+
'%s',
|
688 |
+
);
|
689 |
+
Wt_Import_Export_For_Woo_Basic_History::update_history_entry($export_id,$update_data,$update_data_type);
|
690 |
+
}
|
691 |
+
|
692 |
+
}else
|
693 |
+
{
|
694 |
+
$out['new_offset']=$new_offset;
|
695 |
+
$out['msg']=sprintf(__('Exporting...(%d out of %d)'), $new_offset, $total_records);
|
696 |
+
}
|
697 |
+
return $out;
|
698 |
+
}
|
699 |
+
|
700 |
+
|
701 |
+
public static function get_file_path($file_name)
|
702 |
+
{
|
703 |
+
if(!is_dir(self::$export_dir))
|
704 |
+
{
|
705 |
+
if(!mkdir(self::$export_dir, 0700))
|
706 |
+
{
|
707 |
+
return false;
|
708 |
+
}else
|
709 |
+
{
|
710 |
+
$files_to_create=array('.htaccess' => 'deny from all', 'index.php'=>'<?php // Silence is golden');
|
711 |
+
foreach($files_to_create as $file=>$file_content)
|
712 |
+
{
|
713 |
+
if(!file_exists(self::$export_dir.'/'.$file))
|
714 |
+
{
|
715 |
+
$fh=@fopen(self::$export_dir.'/'.$file, "w");
|
716 |
+
if(is_resource($fh))
|
717 |
+
{
|
718 |
+
fwrite($fh, $file_content);
|
719 |
+
fclose($fh);
|
720 |
+
}
|
721 |
+
}
|
722 |
+
}
|
723 |
+
}
|
724 |
+
}
|
725 |
+
return self::$export_dir.'/'.$file_name;
|
726 |
+
}
|
727 |
+
|
728 |
+
/**
|
729 |
+
* Download file via a nonce URL
|
730 |
+
*/
|
731 |
+
public function download_file()
|
732 |
+
{
|
733 |
+
if(isset($_GET['wt_iew_export_download']))
|
734 |
+
{
|
735 |
+
if(Wt_Iew_Sh::check_write_access(WT_IEW_PLUGIN_ID_BASIC)) /* check nonce and role */
|
736 |
+
{
|
737 |
+
$file_name=(isset($_GET['file']) ? sanitize_file_name($_GET['file']) : '');
|
738 |
+
if($file_name!="")
|
739 |
+
{
|
740 |
+
$file_arr=explode(".", $file_name);
|
741 |
+
$file_ext=end($file_arr);
|
742 |
+
if(isset($this->allowed_export_file_type[$file_ext]) || $file_ext=='zip') /* Only allowed files. Zip file in image export */
|
743 |
+
{
|
744 |
+
$file_path=self::$export_dir.'/'.$file_name;
|
745 |
+
if(file_exists($file_path) && is_file($file_path)) /* check existence of file */
|
746 |
+
{
|
747 |
+
header('Pragma: public');
|
748 |
+
header('Expires: 0');
|
749 |
+
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
750 |
+
header('Cache-Control: private', false);
|
751 |
+
header('Content-Transfer-Encoding: binary');
|
752 |
+
header('Content-Disposition: attachment; filename="'.$file_name.'";');
|
753 |
+
header('Content-Description: File Transfer');
|
754 |
+
header('Content-Type: application/octet-stream');
|
755 |
+
//header('Content-Length: '.filesize($file_path));
|
756 |
+
|
757 |
+
$chunk_size=1024 * 1024;
|
758 |
+
$handle=@fopen($file_path, 'rb');
|
759 |
+
while(!feof($handle))
|
760 |
+
{
|
761 |
+
$buffer = fread($handle, $chunk_size);
|
762 |
+
echo $buffer;
|
763 |
+
ob_flush();
|
764 |
+
flush();
|
765 |
+
}
|
766 |
+
fclose($handle);
|
767 |
+
exit();
|
768 |
+
|
769 |
+
}
|
770 |
+
}
|
771 |
+
}
|
772 |
+
}
|
773 |
+
}
|
774 |
+
}
|
775 |
+
|
776 |
+
private function _update_history_after_export($export_id, $offset, $total_records, $export_data)
|
777 |
+
{
|
778 |
+
/* we need to update total record count on first batch */
|
779 |
+
if($offset==0)
|
780 |
+
{
|
781 |
+
$update_data=array(
|
782 |
+
'total'=>$total_records
|
783 |
+
);
|
784 |
+
}else
|
785 |
+
{
|
786 |
+
/* updating completed offset */
|
787 |
+
$update_data=array(
|
788 |
+
'offset'=>$offset
|
789 |
+
);
|
790 |
+
}
|
791 |
+
$update_data_type=array(
|
792 |
+
'%d'
|
793 |
+
);
|
794 |
+
Wt_Import_Export_For_Woo_Basic_History::update_history_entry($export_id, $update_data, $update_data_type);
|
795 |
+
}
|
796 |
+
|
797 |
+
private function _get_default_batch_count($form_data)
|
798 |
+
{
|
799 |
+
$default_batch_count=absint(apply_filters('wt_iew_exporter_alter_default_batch_count_basic', $this->default_batch_count, $this->to_export, $form_data));
|
800 |
+
$form_data=null;
|
801 |
+
unset($form_data);
|
802 |
+
return ($default_batch_count==0 ? $this->default_batch_count : $default_batch_count);
|
803 |
+
}
|
804 |
+
|
805 |
+
/**
|
806 |
+
* Generating downloadable URL for a file
|
807 |
+
*/
|
808 |
+
private function get_file_url($file_name)
|
809 |
+
{
|
810 |
+
return wp_nonce_url(admin_url('admin.php?wt_iew_export_download=true&file='.$file_name), WT_IEW_PLUGIN_ID_BASIC);
|
811 |
+
}
|
812 |
+
}
|
813 |
+
}
|
814 |
+
Wt_Import_Export_For_Woo_Basic::$loaded_modules['export']=new Wt_Import_Export_For_Woo_Basic_Export();
|
admin/modules/export/views/_export_advanced_page.php
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
?>
|
6 |
+
<div class="wt_iew_export_main">
|
7 |
+
<p><?php echo $step_info['description']; ?></p>
|
8 |
+
<form class="wt_iew_export_advanced_form">
|
9 |
+
<table class="form-table wt-iew-form-table wt-iew-export-filter-table">
|
10 |
+
<?php
|
11 |
+
Wt_Import_Export_For_Woo_Basic_Common_Helper::field_generator($advanced_screen_fields, $advanced_form_data);
|
12 |
+
?>
|
13 |
+
</table>
|
14 |
+
</form>
|
15 |
+
</div>
|
16 |
+
<?php
|
17 |
+
|
18 |
+
$file_int_field_tr_arr=array();
|
19 |
+
$file_int_field_tr_arr=apply_filters('wt_iew_exporter_file_into_fields_row_id_basic', $file_int_field_tr_arr);
|
20 |
+
?>
|
21 |
+
<script type="text/javascript">
|
22 |
+
var file_int_field_tr_arr=<?php echo json_encode($file_int_field_tr_arr); ?>;
|
23 |
+
/* remote file modules can hook */
|
24 |
+
function wt_iew_set_file_into_fields(file_into)
|
25 |
+
{
|
26 |
+
/* first hide all */
|
27 |
+
if(file_int_field_tr_arr.length>0)
|
28 |
+
{
|
29 |
+
jQuery(file_int_field_tr_arr.join(', ')).hide();
|
30 |
+
}
|
31 |
+
// wt_iew_toggle_schedule_btn(0); //hide scheduler btn if exists
|
32 |
+
<?php
|
33 |
+
do_action('wt_iew_exporter_file_into_js_fn');
|
34 |
+
?>
|
35 |
+
}
|
36 |
+
<?php /*
|
37 |
+
function wt_iew_toggle_schedule_btn(state) /* show/hide cron button
|
38 |
+
{
|
39 |
+
<?php
|
40 |
+
do_action('wt_iew_toggle_schedule_btn');
|
41 |
+
?>
|
42 |
+
} */ ?>
|
43 |
+
|
44 |
+
/* custom action: other than export, save, update. Eg: schedule */
|
45 |
+
function wt_iew_custom_action_basic(ajx_dta, action, id)
|
46 |
+
{
|
47 |
+
ajx_dta['item_type']=ajx_dta['to_export'];
|
48 |
+
<?php
|
49 |
+
do_action('wt_iew_custom_action_basic');
|
50 |
+
?>
|
51 |
+
}
|
52 |
+
</script>
|
admin/modules/export/views/_export_filter_page.php
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
?>
|
6 |
+
<div class="wt_iew_export_main">
|
7 |
+
<p><?php echo $step_info['description']; ?></p>
|
8 |
+
<form class="wt_iew_export_filter_form">
|
9 |
+
<table class="form-table wt-iew-form-table wt-iew-export-filter-table">
|
10 |
+
<?php
|
11 |
+
Wt_Import_Export_For_Woo_Basic_Common_Helper::field_generator($filter_screen_fields, $filter_form_data);
|
12 |
+
?>
|
13 |
+
</table>
|
14 |
+
</form>
|
15 |
+
</div>
|
admin/modules/export/views/_export_footer.php
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
?>
|
6 |
+
<div class="wt-iew-plugin-toolbar bottom">
|
7 |
+
<div style="float:left; padding-top:10px;" class="wt_iew_export_template_name"> </div>
|
8 |
+
<div style="float:right;">
|
9 |
+
<div style="float:right;">
|
10 |
+
<?php
|
11 |
+
$button_types = array_column(array_values($this->step_btns), 'type');
|
12 |
+
$last_button_key = array_search('button', array_reverse($button_types, true));
|
13 |
+
$count = 0;
|
14 |
+
$button_standard_class = 'media-button';
|
15 |
+
foreach($this->step_btns as $btnk=>$btnv)
|
16 |
+
{
|
17 |
+
$css_class=(isset($btnv['class']) ? $btnv['class'] : '');
|
18 |
+
$action_type=(isset($btnv['action_type']) ? $btnv['action_type'] : 'non-step');
|
19 |
+
if($count == $last_button_key){
|
20 |
+
$button_standard_class = 'button-primary';
|
21 |
+
}
|
22 |
+
if($btnv['type']=='button')
|
23 |
+
{
|
24 |
+
?>
|
25 |
+
<button class="button <?php echo $button_standard_class; ?> wt_iew_export_action_btn <?php echo $css_class; ?>" data-action-type="<?php echo $action_type; ?>" data-action="<?php echo $btnv['key'];?>" type="submit">
|
26 |
+
<?php echo $btnv['text'];?>
|
27 |
+
</button>
|
28 |
+
<?php
|
29 |
+
|
30 |
+
}
|
31 |
+
elseif($btnv['type']=='dropdown_button')
|
32 |
+
{
|
33 |
+
$btn_arr=(isset($btnv['items']) && is_array($btnv['items']) ? $btnv['items'] : array());
|
34 |
+
?>
|
35 |
+
<button type="button" class="button button-primary wt_iew_drp_menu <?php echo $css_class; ?>" data-target="wt_iew_<?php echo $btnk; ?>_drp">
|
36 |
+
<?php echo $btnv['text'];?> <span class="dashicons dashicons-arrow-down" style="line-height: 28px;"></span>
|
37 |
+
</button>
|
38 |
+
<ul class="wt_iew_dropdown <?php echo $css_class; ?>" data-id="wt_iew_<?php echo $btnk; ?>_drp">
|
39 |
+
<?php
|
40 |
+
foreach($btn_arr as $btnkk => $btnvv)
|
41 |
+
{
|
42 |
+
$field_attr=(isset($btnvv['field_attr']) ? $btnvv['field_attr'] : '');
|
43 |
+
$action_type=(isset($btnvv['action_type']) ? $btnvv['action_type'] : 'non-step');
|
44 |
+
?>
|
45 |
+
<li class="wt_iew_export_action_btn" data-action-type="<?php echo $action_type; ?>" data-action="<?php echo $btnvv['key'];?>" <?php echo $field_attr;?> ><?php echo $btnvv['text'];?></li>
|
46 |
+
<?php
|
47 |
+
}
|
48 |
+
?>
|
49 |
+
</ul>
|
50 |
+
<?php
|
51 |
+
}
|
52 |
+
elseif($btnv['type']=='hidden_button')
|
53 |
+
{
|
54 |
+
?>
|
55 |
+
<button style="display:none;" class="button button-primary wt_iew_export_action_btn <?php echo $css_class; ?>" data-action-type="<?php echo $action_type; ?>" data-action="<?php echo $btnv['key'];?>" type="submit">
|
56 |
+
<?php echo $btnv['text'];?>
|
57 |
+
</button>
|
58 |
+
<?php
|
59 |
+
|
60 |
+
}
|
61 |
+
elseif($btnv['type']=='text')
|
62 |
+
{
|
63 |
+
?>
|
64 |
+
<span style="line-height:40px; font-weight:bold;" class="<?php echo $css_class; ?>"><?php echo $btnv['text'];?></span>
|
65 |
+
<?php
|
66 |
+
}
|
67 |
+
$count++;
|
68 |
+
}
|
69 |
+
?>
|
70 |
+
</div>
|
71 |
+
</div>
|
72 |
+
<span class="spinner" style="margin-top:11px;"></span>
|
73 |
+
</div>
|
admin/modules/export/views/_export_header.php
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
?>
|
6 |
+
<div class="wt-iew-settings-header">
|
7 |
+
<h3>
|
8 |
+
<?php _e('Export'); ?><?php if($this->step!='post_type'){ ?> <span class="wt_iew_step_head_post_type_name"></span><?php } ?>: <?php echo $this->step_title; ?>
|
9 |
+
</h3>
|
10 |
+
<span class="wt_iew_step_info" title="<?php echo $this->step_summary; ?>">
|
11 |
+
<?php
|
12 |
+
echo $this->step_summary;
|
13 |
+
?>
|
14 |
+
</span>
|
15 |
+
</div>
|
admin/modules/export/views/_export_mapping_page.php
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
?>
|
6 |
+
<div class="wt_iew_export_main">
|
7 |
+
<p><?php echo $step_info['description']; ?></p>
|
8 |
+
<div class="meta_mapping_box">
|
9 |
+
<div class="meta_mapping_box_hd_nil wt_iew_noselect">
|
10 |
+
<?php _e('Default fields');?>
|
11 |
+
<span class="meta_mapping_box_selected_count_box"><span class="meta_mapping_box_selected_count_box_num">0</span> <?php _e(' columns(s) selected'); ?></span>
|
12 |
+
</div>
|
13 |
+
<div style="clear:both;"></div>
|
14 |
+
<div class="meta_mapping_box_con" data-sortable="0" data-loaded="1" data-field-validated="0" data-key="" style="display:inline-block;">
|
15 |
+
<table class="wt-iew-mapping-tb wt-iew-exporter-default-mapping-tb">
|
16 |
+
<thead>
|
17 |
+
<tr>
|
18 |
+
<th>
|
19 |
+
<input type="checkbox" name="" class="wt_iew_mapping_checkbox_main">
|
20 |
+
</th>
|
21 |
+
<th width="35%"><?php _e('Column');?></th>
|
22 |
+
<th><?php _e('Column name');?></th>
|
23 |
+
</tr>
|
24 |
+
</thead>
|
25 |
+
<tbody>
|
26 |
+
<?php
|
27 |
+
$draggable_tooltip=__("Drag to rearrange the columns");
|
28 |
+
$tr_count=0;
|
29 |
+
foreach($form_data_mapping_fields as $key=>$val)
|
30 |
+
{
|
31 |
+
if(isset($mapping_fields[$key]))
|
32 |
+
{
|
33 |
+
$label=$mapping_fields[$key];
|
34 |
+
include "_export_mapping_tr_html.php";
|
35 |
+
unset($mapping_fields[$key]); //remove the field from default list
|
36 |
+
$tr_count++;
|
37 |
+
}
|
38 |
+
}
|
39 |
+
if(count($mapping_fields)>0)
|
40 |
+
{
|
41 |
+
foreach($mapping_fields as $key=>$label)
|
42 |
+
{
|
43 |
+
$val=array($key, 1); //enable the field
|
44 |
+
include "_export_mapping_tr_html.php";
|
45 |
+
$tr_count++;
|
46 |
+
}
|
47 |
+
}
|
48 |
+
if($tr_count==0)
|
49 |
+
{
|
50 |
+
?>
|
51 |
+
<tr>
|
52 |
+
<td colspan="3" style="text-align:center;">
|
53 |
+
<?php _e('No fields found.'); ?>
|
54 |
+
</td>
|
55 |
+
</tr>
|
56 |
+
<?php
|
57 |
+
}
|
58 |
+
?>
|
59 |
+
</tbody>
|
60 |
+
</table>
|
61 |
+
</div>
|
62 |
+
</div>
|
63 |
+
<div style="clear:both;"></div>
|
64 |
+
<?php
|
65 |
+
if($this->mapping_enabled_fields)
|
66 |
+
{
|
67 |
+
foreach($this->mapping_enabled_fields as $mapping_enabled_field_key=>$mapping_enabled_field)
|
68 |
+
{
|
69 |
+
$mapping_enabled_field=(!is_array($mapping_enabled_field) ? array($mapping_enabled_field, 0) : $mapping_enabled_field);
|
70 |
+
|
71 |
+
if(count($form_data_mapping_enabled_fields)>0)
|
72 |
+
{
|
73 |
+
if(in_array($mapping_enabled_field_key, $form_data_mapping_enabled_fields))
|
74 |
+
{
|
75 |
+
$mapping_enabled_field[1]=1;
|
76 |
+
}else
|
77 |
+
{
|
78 |
+
$mapping_enabled_field[1]=0;
|
79 |
+
}
|
80 |
+
}
|
81 |
+
?>
|
82 |
+
<div class="meta_mapping_box">
|
83 |
+
<div class="meta_mapping_box_hd wt_iew_noselect">
|
84 |
+
<span class="dashicons dashicons-arrow-right"></span>
|
85 |
+
<?php echo $mapping_enabled_field[0];?>
|
86 |
+
<span class="meta_mapping_box_selected_count_box"><span class="meta_mapping_box_selected_count_box_num">0</span> <?php _e(' columns(s) selected'); ?></span>
|
87 |
+
</div>
|
88 |
+
<div style="clear:both;"></div>
|
89 |
+
<div class="meta_mapping_box_con" data-sortable="0" data-loaded="0" data-field-validated="0" data-key="<?php echo $mapping_enabled_field_key;?>"></div>
|
90 |
+
</div>
|
91 |
+
<div style="clear:both;"></div>
|
92 |
+
<?php
|
93 |
+
}
|
94 |
+
}
|
95 |
+
?>
|
96 |
+
</div>
|
admin/modules/export/views/_export_mapping_tr_html.php
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
$checked=is_array($val) ? $val[1] : 0;
|
6 |
+
$val=(is_array($val) ? $val[0] : $val);
|
7 |
+
?>
|
8 |
+
<tr id="columns_<?php echo $key;?>">
|
9 |
+
<td>
|
10 |
+
<div class="wt_iew_sort_handle" title="<?php echo $draggable_tooltip;?>">
|
11 |
+
<img src="<?php echo WT_O_IEW_PLUGIN_URL.'assets/images/drag_icon.png'; ?>"/>
|
12 |
+
</div>
|
13 |
+
<input type="checkbox" name="columns_key[]" class="columns_key wt_iew_mapping_checkbox_sub" value="<?php echo $key;?>" <?php echo ($checked==1 ? 'checked' : ''); ?>></td>
|
14 |
+
<td>
|
15 |
+
<label class="wt_iew_mapping_column_label"><?php echo $label;?></label>
|
16 |
+
</td>
|
17 |
+
<td>
|
18 |
+
<input type="text" name="columns_val[]" class="columns_val" value="<?php echo $val;?>">
|
19 |
+
</td>
|
20 |
+
</tr>
|
admin/modules/export/views/_export_meta_step_page.php
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
?>
|
6 |
+
<table class="wt-iew-mapping-tb wt-iew-exporter-meta-mapping-tb" data-field-type="<?php echo $meta_mapping_screen_field_key; ?>">
|
7 |
+
<thead>
|
8 |
+
<tr>
|
9 |
+
<th>
|
10 |
+
<?php
|
11 |
+
$is_checked=(isset($meta_mapping_screen_field_val['checked']) && $meta_mapping_screen_field_val['checked']==1 ? 1 : 0);
|
12 |
+
$checked_attr=($is_checked==1 ? ' checked="checked"' : '');
|
13 |
+
?>
|
14 |
+
<input type="checkbox" name="" class="wt_iew_mapping_checkbox_main" <?php echo $checked_attr; ?>>
|
15 |
+
</th>
|
16 |
+
<th width="35%"><?php _e('Column');?></th>
|
17 |
+
<th><?php _e('Column name');?></th>
|
18 |
+
</tr>
|
19 |
+
</thead>
|
20 |
+
<tbody>
|
21 |
+
<?php
|
22 |
+
$tr_count=0;
|
23 |
+
|
24 |
+
if(isset($meta_mapping_screen_field_val['fields']) && is_array($meta_mapping_screen_field_val['fields']) && count($meta_mapping_screen_field_val['fields'])>0)
|
25 |
+
{
|
26 |
+
foreach($meta_mapping_screen_field_val['fields'] as $key=>$val)
|
27 |
+
{
|
28 |
+
$val=is_array($val) ? $val : array($val, 0);
|
29 |
+
$label=$val[0];
|
30 |
+
|
31 |
+
if(isset($current_meta_step_form_data[$key])) /* forma data/template data available */
|
32 |
+
{
|
33 |
+
$val=(is_array($current_meta_step_form_data[$key]) ? $current_meta_step_form_data[$key] : array($current_meta_step_form_data[$key], 1));
|
34 |
+
}else
|
35 |
+
{
|
36 |
+
$val[1]=$is_checked; //parent is checked
|
37 |
+
}
|
38 |
+
|
39 |
+
include "_export_mapping_tr_html.php";
|
40 |
+
$tr_count++;
|
41 |
+
}
|
42 |
+
}
|
43 |
+
|
44 |
+
if($tr_count==0)
|
45 |
+
{
|
46 |
+
?>
|
47 |
+
<tr>
|
48 |
+
<td colspan="3" style="text-align:center;">
|
49 |
+
<?php _e('No fields found.'); ?>
|
50 |
+
</td>
|
51 |
+
</tr>
|
52 |
+
<?php
|
53 |
+
}
|
54 |
+
?>
|
55 |
+
</tbody>
|
56 |
+
</table>
|
admin/modules/export/views/_export_method_export_page.php
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
?>
|
6 |
+
<div class="wt_iew_export_main">
|
7 |
+
<p><?php //echo $step_info['description']; ?></p>
|
8 |
+
|
9 |
+
<div class="wt_iew_warn wt_iew_method_export_wrn" style="display:none;">
|
10 |
+
<?php _e('Please select an export method');?>
|
11 |
+
</div>
|
12 |
+
|
13 |
+
<div class="wt_iew_warn wt_iew_export_template_wrn" style="display:none;">
|
14 |
+
<?php _e('Please select an export template.');?>
|
15 |
+
</div>
|
16 |
+
|
17 |
+
<table class="form-table wt-iew-form-table">
|
18 |
+
<tr>
|
19 |
+
<th><label><?php _e('Select an export method');?></label></th>
|
20 |
+
<td colspan="2" style="width:75%;">
|
21 |
+
<div class="wt_iew_radio_block">
|
22 |
+
<?php
|
23 |
+
foreach($this->export_obj->export_methods as $key => $value)
|
24 |
+
{
|
25 |
+
?>
|
26 |
+
<p>
|
27 |
+
<input type="radio" value="<?php echo $key;?>" id="wt_iew_export_<?php echo $key;?>_export" name="wt_iew_export_method_export" <?php echo ($this->export_method==$key ? 'checked="checked"' : '');?>><b><label for="wt_iew_export_<?php echo $key;?>_export"><?php echo $value['title']; ?></label></b> <br />
|
28 |
+
<span><label for="wt_iew_export_<?php echo $key;?>_export"><?php echo $value['description']; ?></label></span>
|
29 |
+
</p>
|
30 |
+
<?php
|
31 |
+
}
|
32 |
+
?>
|
33 |
+
</div>
|
34 |
+
|
35 |
+
</td>
|
36 |
+
</tr>
|
37 |
+
|
38 |
+
<!-- <tr class="wt-iew-export-method-options wt-iew-export-method-options-quick" style="display:none;">
|
39 |
+
<th style="width:150px; text-align:left; vertical-align:top;"><label><?php _e('Include fields from the respective groups');?></label></th>
|
40 |
+
<td colspan="2" style="width:75%;">
|
41 |
+
<?php
|
42 |
+
foreach($this->mapping_enabled_fields as $mapping_enabled_field_key=>$mapping_enabled_field)
|
43 |
+
{
|
44 |
+
$mapping_enabled_field=(!is_array($mapping_enabled_field) ? array($mapping_enabled_field, 0) : $mapping_enabled_field);
|
45 |
+
|
46 |
+
if($this->rerun_id>0) /* check this is a rerun request */
|
47 |
+
{
|
48 |
+
if(in_array($mapping_enabled_field_key, $form_data_mapping_enabled))
|
49 |
+
{
|
50 |
+
$mapping_enabled_field[1]=1; //mark it as checked
|
51 |
+
}else
|
52 |
+
{
|
53 |
+
$mapping_enabled_field[1]=0; //mark it as unchecked
|
54 |
+
}
|
55 |
+
}
|
56 |
+
?>
|
57 |
+
<div class="wt_iew_checkbox" style="padding-left:0px;">
|
58 |
+
<input type="checkbox" id="wt_iew_<?php echo $mapping_enabled_field_key;?>" name="wt_iew_include_these_fields[]" value="<?php echo $mapping_enabled_field_key;?>" <?php echo ($mapping_enabled_field[1]==1 ? 'checked="checked"' : '');?> />
|
59 |
+
<label for="wt_iew_<?php echo $mapping_enabled_field_key;?>"><?php echo $mapping_enabled_field[0];?></label>
|
60 |
+
</div>
|
61 |
+
<?php
|
62 |
+
}
|
63 |
+
?>
|
64 |
+
<span class="wt-iew_form_help"><?php _e('Enabling any of these ensures that all the fields from the respective groups are included in your export.');?></span>
|
65 |
+
</td>
|
66 |
+
</tr>-->
|
67 |
+
|
68 |
+
|
69 |
+
<tr class="wt-iew-export-method-options wt-iew-export-method-options-template" style="display:none;">
|
70 |
+
<th><label><?php _e('Export template');?></label></th>
|
71 |
+
<td>
|
72 |
+
<select class="wt-iew-export-template-sele">
|
73 |
+
<option value="0">-- <?php _e('Select a template'); ?> --</option>
|
74 |
+
<?php
|
75 |
+
foreach($this->mapping_templates as $mapping_template)
|
76 |
+
{
|
77 |
+
?>
|
78 |
+
<option value="<?php echo $mapping_template['id'];?>" <?php echo ($form_data_export_template==$mapping_template['id'] ? ' selected="selected"' : ''); ?>>
|
79 |
+
<?php echo $mapping_template['name'];?>
|
80 |
+
</option>
|
81 |
+
<?php
|
82 |
+
}
|
83 |
+
?>
|
84 |
+
</select>
|
85 |
+
</td>
|
86 |
+
<td>
|
87 |
+
</td>
|
88 |
+
</tr>
|
89 |
+
</table>
|
90 |
+
</div>
|
admin/modules/export/views/_export_post_type_page.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
?>
|
6 |
+
<div class="wt_iew_export_main">
|
7 |
+
<p><?php echo $step_info['description']; ?></p>
|
8 |
+
<div class="wt_iew_warn wt_iew_post_type_wrn" style="display:none;">
|
9 |
+
<?php _e('Please select a post type');?>
|
10 |
+
</div>
|
11 |
+
<table class="form-table wt-iew-form-table">
|
12 |
+
<tr>
|
13 |
+
<th><label><?php _e('What do you want to export ?'); ?></label></th>
|
14 |
+
<td>
|
15 |
+
<select name="wt_iew_export_post_type">
|
16 |
+
<option value="">-- <?php _e('Select post type'); ?> --</option>
|
17 |
+
<?php
|
18 |
+
foreach($post_types as $key=>$value)
|
19 |
+
{
|
20 |
+
?>
|
21 |
+
<option value="<?php echo $key;?>" <?php echo ($item_type==$key ? 'selected' : '');?>><?php echo $value;?></option>
|
22 |
+
<?php
|
23 |
+
}
|
24 |
+
?>
|
25 |
+
</select>
|
26 |
+
</td>
|
27 |
+
<td></td>
|
28 |
+
</tr>
|
29 |
+
</table>
|
30 |
+
</div>
|
admin/modules/export/views/main.php
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Main view file of export section
|
4 |
+
*
|
5 |
+
* @link
|
6 |
+
*
|
7 |
+
* @package Wt_Import_Export_For_Woo
|
8 |
+
*/
|
9 |
+
if (!defined('ABSPATH')) {
|
10 |
+
exit;
|
11 |
+
}
|
12 |
+
?>
|
13 |
+
<?php
|
14 |
+
do_action('wt_iew_exporter_before_head');
|
15 |
+
?>
|
16 |
+
<style type="text/css">
|
17 |
+
.wt_iew_export_step{ display:none; }
|
18 |
+
.wt_iew_export_step_loader{ width:100%; height:400px; text-align:center; line-height:400px; font-size:14px; }
|
19 |
+
.wt_iew_export_step_main{ float:left; box-sizing:border-box; padding:15px; padding-bottom:0px; width:95%; margin:30px 2.5%; background:#fff; box-shadow:0px 2px 2px #ccc; border:solid 1px #efefef; }
|
20 |
+
.wt_iew_export_main{ padding:20px 0px; }
|
21 |
+
.wt_iew_file_ext_info_td{ vertical-align:top !important; }
|
22 |
+
.wt_iew_file_ext_info{ display:inline-block; margin-top:3px; }
|
23 |
+
</style>
|
24 |
+
<?php
|
25 |
+
Wt_Iew_IE_Basic_Helper::debug_panel($this->module_base);
|
26 |
+
?>
|
27 |
+
<?php include WT_O_IEW_PLUGIN_PATH."/admin/views/_save_template_popup.php"; ?>
|
28 |
+
<h2 class="wt_iew_page_hd"><?php _e('Export'); ?><span class="wt_iew_post_type_name"></span></h2>
|
29 |
+
|
30 |
+
<?php
|
31 |
+
if($requested_rerun_id>0 && $this->rerun_id==0)
|
32 |
+
{
|
33 |
+
?>
|
34 |
+
<div class="wt_iew_warn wt_iew_rerun_warn">
|
35 |
+
<?php _e('Unable to handle Re-Run request.');?>
|
36 |
+
</div>
|
37 |
+
<?php
|
38 |
+
}
|
39 |
+
?>
|
40 |
+
|
41 |
+
<div class="wt_iew_loader_info_box"></div>
|
42 |
+
<div class="wt_iew_overlayed_loader"></div>
|
43 |
+
<div class="wt_iew_export_step_main">
|
44 |
+
<?php
|
45 |
+
foreach($this->steps as $stepk=>$stepv)
|
46 |
+
{
|
47 |
+
?>
|
48 |
+
<div class="wt_iew_export_step wt_iew_export_step_<?php echo $stepk;?>" data-loaded="0"></div>
|
49 |
+
<?php
|
50 |
+
}
|
51 |
+
?>
|
52 |
+
</div>
|
53 |
+
<?php /*
|
54 |
+
<script type="text/javascript">
|
55 |
+
/* external modules can hook
|
56 |
+
function wt_iew_exporter_validate(action, action_type, is_previous_step)
|
57 |
+
{
|
58 |
+
var is_continue=true;
|
59 |
+
<?php
|
60 |
+
do_action('wt_iew_exporter_validate');
|
61 |
+
?>
|
62 |
+
return is_continue;
|
63 |
+
}
|
64 |
+
</script> */ ?>
|
admin/modules/history/assets/js/main.js
ADDED
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var wt_iew_basic_history=(function( $ ) {
|
2 |
+
//'use strict';
|
3 |
+
var wt_iew_basic_history=
|
4 |
+
{
|
5 |
+
log_offset:0,
|
6 |
+
Set:function()
|
7 |
+
{
|
8 |
+
this.reg_delete();
|
9 |
+
this.reg_view_log();
|
10 |
+
this.reg_bulk_action();
|
11 |
+
},
|
12 |
+
reg_view_log:function()
|
13 |
+
{
|
14 |
+
jQuery('.wt_iew_view_log_btn').click(function(){
|
15 |
+
wt_iew_basic_history.show_log_popup();
|
16 |
+
var history_id=$(this).attr('data-history-id');
|
17 |
+
if(history_id>0)
|
18 |
+
{
|
19 |
+
wt_iew_basic_history.log_offset=0;
|
20 |
+
wt_iew_basic_history.load_page(history_id);
|
21 |
+
}else
|
22 |
+
{
|
23 |
+
var log_file=$(this).attr('data-log-file');
|
24 |
+
if(log_file!="")
|
25 |
+
{
|
26 |
+
wt_iew_basic_history.view_raw_log(log_file);
|
27 |
+
}
|
28 |
+
}
|
29 |
+
});
|
30 |
+
},
|
31 |
+
view_raw_log:function(log_file)
|
32 |
+
{
|
33 |
+
$('.wt_iew_log_container').html('<div class="wt_iew_log_loader">'+wt_iew_basic_params.msgs.loading+'</div>');
|
34 |
+
$.ajax({
|
35 |
+
url:wt_iew_basic_params.ajax_url,
|
36 |
+
data:{'action':'iew_history_ajax_basic', _wpnonce:wt_iew_basic_params.nonces.main, 'history_action':'view_log', 'log_file':log_file, 'data_type':'json'},
|
37 |
+
type:'post',
|
38 |
+
dataType:"json",
|
39 |
+
success:function(data)
|
40 |
+
{
|
41 |
+
if(data.status==1)
|
42 |
+
{
|
43 |
+
$('.wt_iew_log_container').html(data.html);
|
44 |
+
}else
|
45 |
+
{
|
46 |
+
$('.wt_iew_log_loader').html(wt_iew_basic_params.msgs.error);
|
47 |
+
wt_iew_notify_msg.error(wt_iew_basic_params.msgs.error);
|
48 |
+
}
|
49 |
+
},
|
50 |
+
error:function()
|
51 |
+
{
|
52 |
+
$('.wt_iew_log_loader').html(wt_iew_basic_params.msgs.error);
|
53 |
+
wt_iew_notify_msg.error(wt_iew_basic_params.msgs.error);
|
54 |
+
}
|
55 |
+
});
|
56 |
+
},
|
57 |
+
show_log_popup:function()
|
58 |
+
{
|
59 |
+
var pop_elm=$('.wt_iew_view_log');
|
60 |
+
var ww=$(window).width();
|
61 |
+
pop_w=(ww<1300 ? ww : 1300)-200;
|
62 |
+
pop_w=(pop_w<200 ? 200 : pop_w);
|
63 |
+
pop_elm.width(pop_w);
|
64 |
+
|
65 |
+
wh=$(window).height();
|
66 |
+
pop_h=(wh>=400 ? (wh-200) : wh);
|
67 |
+
$('.wt_iew_log_container').css({'max-height':pop_h+'px','overflow':'auto'});
|
68 |
+
wt_iew_popup.showPopup(pop_elm);
|
69 |
+
},
|
70 |
+
load_page:function(history_id)
|
71 |
+
{
|
72 |
+
var offset=wt_iew_basic_history.log_offset;
|
73 |
+
if(offset==0)
|
74 |
+
{
|
75 |
+
$('.wt_iew_log_container').html('<div class="wt_iew_log_loader">'+wt_iew_basic_params.msgs.loading+'</div>');
|
76 |
+
}else
|
77 |
+
{
|
78 |
+
$('.wt_iew_history_loadmore_btn').hide();
|
79 |
+
$('.wt_iew_history_loadmore_loading').show();
|
80 |
+
}
|
81 |
+
$.ajax({
|
82 |
+
url:wt_iew_basic_params.ajax_url,
|
83 |
+
data:{'action':'iew_history_ajax_basic', _wpnonce:wt_iew_basic_params.nonces.main, 'history_action':'view_log', 'offset': offset, 'history_id':history_id, 'data_type':'json'},
|
84 |
+
type:'post',
|
85 |
+
dataType:"json",
|
86 |
+
success:function(data)
|
87 |
+
{
|
88 |
+
$('.wt_iew_history_loadmore_btn').show();
|
89 |
+
$('.wt_iew_history_loadmore_loading').hide();
|
90 |
+
if(data.status==1)
|
91 |
+
{
|
92 |
+
wt_iew_basic_history.log_offset=data.offset;
|
93 |
+
if(offset==0)
|
94 |
+
{
|
95 |
+
$('.wt_iew_log_container').html(data.html);
|
96 |
+
}else
|
97 |
+
{
|
98 |
+
$('.log_view_tb_tbody').append(data.html);
|
99 |
+
}
|
100 |
+
if(data.finished)
|
101 |
+
{
|
102 |
+
$('.wt_iew_history_loadmore_btn').hide();
|
103 |
+
}else
|
104 |
+
{
|
105 |
+
if(offset==0)
|
106 |
+
{
|
107 |
+
$('.wt_iew_history_loadmore_btn').unbind('click').click(function(){
|
108 |
+
wt_iew_basic_history.load_page(history_id);
|
109 |
+
});
|
110 |
+
}
|
111 |
+
}
|
112 |
+
}else
|
113 |
+
{
|
114 |
+
$('.wt_iew_log_loader').html(wt_iew_basic_params.msgs.error);
|
115 |
+
wt_iew_notify_msg.error(wt_iew_basic_params.msgs.error);
|
116 |
+
}
|
117 |
+
},
|
118 |
+
error:function()
|
119 |
+
{
|
120 |
+
$('.wt_iew_log_loader').html(wt_iew_basic_params.msgs.error);
|
121 |
+
$('.wt_iew_history_loadmore_btn').show();
|
122 |
+
$('.wt_iew_history_loadmore_loading').hide();
|
123 |
+
wt_iew_notify_msg.error(wt_iew_basic_params.msgs.error);
|
124 |
+
}
|
125 |
+
});
|
126 |
+
},
|
127 |
+
reg_delete:function()
|
128 |
+
{
|
129 |
+
jQuery('.wt_iew_delete_history, .wt_iew_delete_log').click(function(){
|
130 |
+
if(confirm(wt_iew_history_basic_params.msgs.sure))
|
131 |
+
{
|
132 |
+
window.location.href=jQuery(this).attr('data-href');
|
133 |
+
}
|
134 |
+
});
|
135 |
+
},
|
136 |
+
reg_bulk_action:function()
|
137 |
+
{
|
138 |
+
var checkbox_main=$('.wt_iew_history_checkbox_main');
|
139 |
+
var checkbox_sub=$('.wt_iew_history_checkbox_sub');
|
140 |
+
var tb=$('.history_list_tb');
|
141 |
+
if(tb.find('.wt_iew_history_checkbox_sub:checked').length==tb.find('.wt_iew_history_checkbox_sub').length)
|
142 |
+
{
|
143 |
+
checkbox_main.prop('checked',true);
|
144 |
+
}else
|
145 |
+
{
|
146 |
+
checkbox_main.prop('checked',false);
|
147 |
+
}
|
148 |
+
|
149 |
+
checkbox_main.unbind('click').click(function()
|
150 |
+
{
|
151 |
+
if($(this).is(':checked'))
|
152 |
+
{
|
153 |
+
checkbox_sub.prop('checked',true);
|
154 |
+
}else
|
155 |
+
{
|
156 |
+
checkbox_sub.prop('checked',false);
|
157 |
+
}
|
158 |
+
});
|
159 |
+
checkbox_sub.unbind('click').click(function()
|
160 |
+
{
|
161 |
+
if($(this).is(':checked') && $('.wt_iew_history_checkbox_sub:checked').length==checkbox_sub.length)
|
162 |
+
{
|
163 |
+
checkbox_main.prop('checked',true);
|
164 |
+
}else
|
165 |
+
{
|
166 |
+
checkbox_main.prop('checked',false);
|
167 |
+
}
|
168 |
+
});
|
169 |
+
|
170 |
+
$('.wt_iew_bulk_action_btn').click(function(){
|
171 |
+
if($('.wt_iew_history_checkbox_sub:checked').length>0 && $('.wt_iew_bulk_action option:selected').val()!="")
|
172 |
+
{
|
173 |
+
var cr_action=$('.wt_iew_bulk_action option:selected').val();
|
174 |
+
if(cr_action=='delete')
|
175 |
+
{
|
176 |
+
if(confirm(wt_iew_history_basic_params.msgs.sure))
|
177 |
+
{
|
178 |
+
var id_arr=new Array();
|
179 |
+
$('.wt_iew_history_checkbox_sub:checked').each(function(){
|
180 |
+
id_arr.push($(this).val());
|
181 |
+
});
|
182 |
+
var delete_url=wt_iew_history_basic_params.delete_url.replace('_history_id_', id_arr.join(','));
|
183 |
+
window.location.href=delete_url;
|
184 |
+
}
|
185 |
+
}
|
186 |
+
}
|
187 |
+
});
|
188 |
+
}
|
189 |
+
}
|
190 |
+
return wt_iew_basic_history;
|
191 |
+
|
192 |
+
})( jQuery );
|
193 |
+
|
194 |
+
jQuery(function() {
|
195 |
+
wt_iew_basic_history.Set();
|
196 |
+
});
|
admin/modules/history/history.php
ADDED
@@ -0,0 +1,857 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* History of import/Export
|
4 |
+
*
|
5 |
+
* @link
|
6 |
+
*
|
7 |
+
* @package Wt_Import_Export_For_Woo
|
8 |
+
*/
|
9 |
+
if (!defined('ABSPATH')) {
|
10 |
+
exit;
|
11 |
+
}
|
12 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Basic_History')){
|
13 |
+
class Wt_Import_Export_For_Woo_Basic_History
|
14 |
+
{
|
15 |
+
public $module_id='';
|
16 |
+
public static $module_id_static='';
|
17 |
+
public $module_base='history';
|
18 |
+
public static $status_arr=array();
|
19 |
+
public static $status_label_arr=array();
|
20 |
+
public static $action_label_arr=array();
|
21 |
+
public $max_records=50;
|
22 |
+
|
23 |
+
public function __construct()
|
24 |
+
{
|
25 |
+
$this->module_id=Wt_Import_Export_For_Woo_Basic::get_module_id($this->module_base);
|
26 |
+
self::$module_id_static=$this->module_id;
|
27 |
+
|
28 |
+
self::$status_arr=array(
|
29 |
+
'pending'=>0, //running...
|
30 |
+
'finished'=>1, //completed
|
31 |
+
'failed'=>2, //failed
|
32 |
+
);
|
33 |
+
|
34 |
+
self::$status_label_arr=array(
|
35 |
+
0=>__('Running/Incomplete'),
|
36 |
+
1=>__('Finished'),
|
37 |
+
2=>__('Failed'),
|
38 |
+
);
|
39 |
+
|
40 |
+
self::$action_label_arr=array(
|
41 |
+
'export'=>__('Export'),
|
42 |
+
'import'=>__('Import'),
|
43 |
+
'export_image'=>__('Image Export'),
|
44 |
+
);
|
45 |
+
|
46 |
+
/* Admin menu for hostory listing */
|
47 |
+
add_filter('wt_iew_admin_menu_basic', array($this, 'add_admin_pages'), 10, 1);
|
48 |
+
|
49 |
+
/* advanced plugin settings */
|
50 |
+
add_filter('wt_iew_advanced_setting_fields_basic', array($this, 'advanced_setting_fields'), 11);
|
51 |
+
|
52 |
+
/* main ajax hook. The callback function will decide which action is to execute. */
|
53 |
+
add_action('wp_ajax_iew_history_ajax_basic', array($this, 'ajax_main'), 11);
|
54 |
+
|
55 |
+
/* Hook to perform actions after advanced settings was updated */
|
56 |
+
add_action('wt_iew_after_advanced_setting_update_basic', array($this, 'after_advanced_setting_update'), 11);
|
57 |
+
|
58 |
+
/* Download log file via nonce URL */
|
59 |
+
add_action('admin_init', array($this, 'download_file'), 11);
|
60 |
+
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Adding admin menus
|
65 |
+
*/
|
66 |
+
public function add_admin_pages($menus)
|
67 |
+
{
|
68 |
+
$menus[$this->module_base]=array(
|
69 |
+
'submenu',
|
70 |
+
WT_IEW_PLUGIN_ID_BASIC,
|
71 |
+
__('History'),
|
72 |
+
__('History'),
|
73 |
+
'manage_options',
|
74 |
+
$this->module_id,
|
75 |
+
array($this, 'admin_settings_page')
|
76 |
+
);
|
77 |
+
$menus[$this->module_base.'_log']=array(
|
78 |
+
'submenu',
|
79 |
+
WT_IEW_PLUGIN_ID_BASIC,
|
80 |
+
__('Logs'),
|
81 |
+
__('Logs'),
|
82 |
+
'manage_options',
|
83 |
+
$this->module_id.'_log',
|
84 |
+
array($this, 'admin_log_page')
|
85 |
+
);
|
86 |
+
return $menus;
|
87 |
+
}
|
88 |
+
|
89 |
+
public function ajax_main()
|
90 |
+
{
|
91 |
+
if(Wt_Iew_Sh::check_write_access(WT_IEW_PLUGIN_ID_BASIC))
|
92 |
+
{
|
93 |
+
$allowed_ajax_actions=array('view_log');
|
94 |
+
|
95 |
+
$out=array(
|
96 |
+
'status'=>0,
|
97 |
+
'msg'=>__('Error'),
|
98 |
+
);
|
99 |
+
|
100 |
+
$history_action=Wt_Iew_Sh::sanitize_item($_POST['history_action'], 'text');
|
101 |
+
$data_type=Wt_Iew_Sh::sanitize_item($_POST['data_type'], 'text');
|
102 |
+
|
103 |
+
if(method_exists($this, $history_action) && in_array($history_action, $allowed_ajax_actions))
|
104 |
+
{
|
105 |
+
$out=$this->{$history_action}($out);
|
106 |
+
}
|
107 |
+
|
108 |
+
if($data_type=='json')
|
109 |
+
{
|
110 |
+
echo json_encode($out);
|
111 |
+
}
|
112 |
+
}
|
113 |
+
exit();
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* Ajax sub function to display logs
|
118 |
+
*
|
119 |
+
*/
|
120 |
+
private function view_log($out)
|
121 |
+
{
|
122 |
+
$history_id=(isset($_POST['history_id']) ? absint($_POST['history_id']) : 0);
|
123 |
+
$out['html']='';
|
124 |
+
|
125 |
+
if($history_id>0)
|
126 |
+
{
|
127 |
+
$offset=(isset($_POST['offset']) ? absint($_POST['offset']) : 0);
|
128 |
+
$out['offset']=$offset;
|
129 |
+
$out['history_id']=$history_id;
|
130 |
+
|
131 |
+
$history_item=$this->get_history_entry_by_id($history_id);
|
132 |
+
if($history_item) //history item exists
|
133 |
+
{
|
134 |
+
$action_type=$history_item['template_type'];
|
135 |
+
if($action_type=='import' && Wt_Import_Export_For_Woo_Admin_Basic::module_exists($action_type))
|
136 |
+
{
|
137 |
+
$action_module_obj=Wt_Import_Export_For_Woo_Basic::load_modules($action_type);
|
138 |
+
$log_file_name=$action_module_obj->get_log_file_name($history_item['id']);
|
139 |
+
$log_file_path=$action_module_obj->get_file_path($log_file_name);
|
140 |
+
if(file_exists($log_file_path))
|
141 |
+
{
|
142 |
+
include_once WT_O_IEW_PLUGIN_PATH.'admin/classes/class-logreader.php';
|
143 |
+
$reader=new Wt_Import_Export_For_Woo_Basic_Logreader();
|
144 |
+
$response=$reader->get_data_as_batch($log_file_path, $offset);
|
145 |
+
if($response['response'])
|
146 |
+
{
|
147 |
+
$log_list=$response['data_arr'];
|
148 |
+
$out['offset']=$response['offset'];
|
149 |
+
$out['status']=1;
|
150 |
+
$out['finished']=$response['finished'];
|
151 |
+
|
152 |
+
$is_finished=$response['finished'];
|
153 |
+
$new_offset=$response['offset'];
|
154 |
+
|
155 |
+
$show_item_details=false;
|
156 |
+
$item_type_module_obj=Wt_Import_Export_For_Woo_Basic::load_modules($history_item['item_type']);
|
157 |
+
if(!is_null($item_type_module_obj) && method_exists($item_type_module_obj, 'get_item_by_id'))
|
158 |
+
{
|
159 |
+
$show_item_details=true;
|
160 |
+
}
|
161 |
+
ob_start();
|
162 |
+
include plugin_dir_path(__FILE__).'views/_log_table.php';
|
163 |
+
$out['html']=ob_get_clean();
|
164 |
+
}
|
165 |
+
}
|
166 |
+
}
|
167 |
+
}
|
168 |
+
}else /* raw log viewing */
|
169 |
+
{
|
170 |
+
$log_file_name=(isset($_POST['log_file']) ? sanitize_text_field($_POST['log_file']) : '');
|
171 |
+
if($log_file_name!="")
|
172 |
+
{
|
173 |
+
$ext_arr=explode(".", $log_file_name);
|
174 |
+
$ext=end($ext_arr);
|
175 |
+
if($ext=='log')
|
176 |
+
{
|
177 |
+
$log_file_path=Wt_Import_Export_For_Woo_Basic_Log::get_file_path($log_file_name);
|
178 |
+
if(file_exists($log_file_path))
|
179 |
+
{
|
180 |
+
include_once WT_O_IEW_PLUGIN_PATH.'admin/classes/class-logreader.php';
|
181 |
+
$reader=new Wt_Import_Export_For_Woo_Basic_Logreader();
|
182 |
+
$response=$reader->get_full_data($log_file_path);
|
183 |
+
|
184 |
+
$out['status']=1;
|
185 |
+
$out['html']='<div class="wt_iew_raw_log">'.nl2br(esc_html__($response['data_str'])).'</div>';
|
186 |
+
}
|
187 |
+
}
|
188 |
+
}
|
189 |
+
|
190 |
+
}
|
191 |
+
return $out;
|
192 |
+
}
|
193 |
+
|
194 |
+
/**
|
195 |
+
* Fields for advanced settings
|
196 |
+
*
|
197 |
+
*/
|
198 |
+
public function advanced_setting_fields($fields)
|
199 |
+
{
|
200 |
+
$fields['advanced_field_head'] =array(
|
201 |
+
'type'=>'field_group_head', //field type
|
202 |
+
'head'=>__('Advanced options'),
|
203 |
+
'group_id'=>'advanced_field', //field group id
|
204 |
+
'show_on_default'=>0,
|
205 |
+
);
|
206 |
+
$fields['enable_history_auto_delete']=array(
|
207 |
+
'label'=>__("Auto delete history"),
|
208 |
+
'type'=>'radio',
|
209 |
+
'radio_fields'=>array(
|
210 |
+
1=>__('Yes'),
|
211 |
+
0=>__('No')
|
212 |
+
),
|
213 |
+
'value' =>1,
|
214 |
+
'field_name'=>'enable_history_auto_delete',
|
215 |
+
'field_group'=>'advanced_field',
|
216 |
+
'help_text'=>__('Enable auto delete for records within the history section.'),
|
217 |
+
'validation_rule'=>array('type'=>'absint'),
|
218 |
+
'form_toggler'=>array(
|
219 |
+
'type'=>'parent',
|
220 |
+
'target'=>'wt_iew_enable_history_auto_delete',
|
221 |
+
),
|
222 |
+
);
|
223 |
+
|
224 |
+
$fields['auto_delete_history_count']=array(
|
225 |
+
'label'=>__("Maximum entries"),
|
226 |
+
'type'=>'number',
|
227 |
+
'value' =>100,
|
228 |
+
'attr' =>array(
|
229 |
+
'style'=>'width:30%;',
|
230 |
+
),
|
231 |
+
'field_name'=>'auto_delete_history_count',
|
232 |
+
'field_group'=>'advanced_field',
|
233 |
+
'help_text'=>__('Indicates the maximum records to retain in history. Limit the number of records with status ‘Finished’. E.g On giving an input of 50, the system will retain(not delete) the latest 50 records with status ‘Finished’. Any other record with a different status will not be retained.'),
|
234 |
+
'validation_rule'=>array('type'=>'absint'),
|
235 |
+
'form_toggler'=>array(
|
236 |
+
'type'=>'child',
|
237 |
+
'id'=>'wt_iew_enable_history_auto_delete',
|
238 |
+
'val'=>1,
|
239 |
+
),
|
240 |
+
);
|
241 |
+
|
242 |
+
return $fields;
|
243 |
+
}
|
244 |
+
|
245 |
+
public function admin_log_page($args)
|
246 |
+
{
|
247 |
+
/* delete action */
|
248 |
+
if(isset($_GET['wt_iew_delete_log']))
|
249 |
+
{
|
250 |
+
if(Wt_Iew_Sh::check_write_access(WT_IEW_PLUGIN_ID_BASIC))
|
251 |
+
{
|
252 |
+
$log_file_name=(isset($_GET['wt_iew_log_file']) ? sanitize_text_field($_GET['wt_iew_log_file']) : '');
|
253 |
+
if($log_file_name!="")
|
254 |
+
{
|
255 |
+
$ext_arr=explode(".", $log_file_name);
|
256 |
+
$ext=end($ext_arr);
|
257 |
+
if($ext=='log')
|
258 |
+
{
|
259 |
+
$log_file_path=Wt_Import_Export_For_Woo_Basic_Log::get_file_path($log_file_name);
|
260 |
+
if(file_exists($log_file_path) && is_file($log_file_path))
|
261 |
+
{
|
262 |
+
@unlink($log_file_path);
|
263 |
+
}
|
264 |
+
}
|
265 |
+
}
|
266 |
+
}
|
267 |
+
}
|
268 |
+
|
269 |
+
$delete_url_params['wt_iew_delete_log']=1;
|
270 |
+
$delete_url_params['wt_iew_log_file']='_log_file_';
|
271 |
+
$delete_url_params['page']=$this->module_id.'_log';
|
272 |
+
$delete_url=wp_nonce_url(admin_url('admin.php?'.http_build_query($delete_url_params)), WT_IEW_PLUGIN_ID_BASIC);
|
273 |
+
|
274 |
+
$download_url=wp_nonce_url(admin_url('admin.php?wt_iew_log_download=1&file=_log_file_'), WT_IEW_PLUGIN_ID_BASIC);
|
275 |
+
|
276 |
+
//enqueue script
|
277 |
+
if(isset($_GET['page']) && $_GET['page']==$this->module_id.'_log')
|
278 |
+
{
|
279 |
+
$this->enqueue_scripts($delete_url);
|
280 |
+
}
|
281 |
+
|
282 |
+
include plugin_dir_path(__FILE__).'views/settings.php';
|
283 |
+
}
|
284 |
+
|
285 |
+
/**
|
286 |
+
* History list page
|
287 |
+
*/
|
288 |
+
public function admin_settings_page($args)
|
289 |
+
{
|
290 |
+
global $wpdb;
|
291 |
+
|
292 |
+
/* delete action */
|
293 |
+
if(isset($_GET['wt_iew_delete_history']))
|
294 |
+
{
|
295 |
+
if(Wt_Iew_Sh::check_write_access(WT_IEW_PLUGIN_ID_BASIC))
|
296 |
+
{
|
297 |
+
$history_id_arr=isset($_GET['wt_iew_history_id']) ? explode(",", $_GET['wt_iew_history_id']) : array();
|
298 |
+
$history_id_arr=Wt_Iew_Sh::sanitize_item($history_id_arr, 'absint_arr');
|
299 |
+
if(count($history_id_arr)>0)
|
300 |
+
{
|
301 |
+
self::delete_history_by_id($history_id_arr);
|
302 |
+
}
|
303 |
+
}
|
304 |
+
}
|
305 |
+
|
306 |
+
/**
|
307 |
+
* Lising page section
|
308 |
+
*/
|
309 |
+
$tb=$wpdb->prefix.Wt_Import_Export_For_Woo_Basic::$history_tb;
|
310 |
+
|
311 |
+
$post_type_arr=self::get_disticnt_items('item_type');
|
312 |
+
$action_type_arr=self::get_disticnt_items('template_type');
|
313 |
+
$status_arr=self::get_disticnt_items('status');
|
314 |
+
|
315 |
+
$importer_post_types=apply_filters('wt_iew_importer_post_types_basic', array());
|
316 |
+
$exporter_post_types=apply_filters('wt_iew_exporter_post_types_basic', array());
|
317 |
+
$post_type_label_arr=array_merge($importer_post_types, $exporter_post_types);
|
318 |
+
|
319 |
+
|
320 |
+
/**
|
321 |
+
* Get history entries by Schedule ID
|
322 |
+
*/
|
323 |
+
$cron_id=(isset($_GET['wt_iew_cron_id']) ? absint($_GET['wt_iew_cron_id']) : 0);
|
324 |
+
$history_arr=array();
|
325 |
+
$list_by_cron=false;
|
326 |
+
if($cron_id>0)
|
327 |
+
{
|
328 |
+
$cron_module_obj=Wt_Import_Export_For_Woo_Basic::load_modules('cron');
|
329 |
+
if(!is_null($cron_module_obj))
|
330 |
+
{
|
331 |
+
$cron_data=$cron_module_obj->get_cron_by_id($cron_id);
|
332 |
+
if($cron_data)
|
333 |
+
{
|
334 |
+
$history_id_arr=($cron_data['history_id_list']!="" ? maybe_unserialize($cron_data['history_id_list']) : array());
|
335 |
+
$history_id_arr=(is_array($history_id_arr) ? $history_id_arr : array());
|
336 |
+
$list_by_cron=true;
|
337 |
+
}else
|
338 |
+
{
|
339 |
+
$cron_id=0; //invalid cron id
|
340 |
+
}
|
341 |
+
}else
|
342 |
+
{
|
343 |
+
$cron_id=0; //cron module not enabled
|
344 |
+
}
|
345 |
+
}
|
346 |
+
|
347 |
+
|
348 |
+
/**
|
349 |
+
* Filter by form fields
|
350 |
+
*/
|
351 |
+
$filter_by=array(
|
352 |
+
'item_type'=>array(
|
353 |
+
'label'=>__('Post type'),
|
354 |
+
'values'=>$post_type_arr,
|
355 |
+
'val_labels'=>$post_type_label_arr,
|
356 |
+
'val_type'=>'%s',
|
357 |
+
'selected_val'=>'',
|
358 |
+
),
|
359 |
+
'template_type'=>array(
|
360 |
+
'label'=>__('Action type'),
|
361 |
+
'values'=>$action_type_arr,
|
362 |
+
'val_labels'=>self::$action_label_arr,
|
363 |
+
'val_type'=>'%s',
|
364 |
+
'selected_val'=>'',
|
365 |
+
),
|
366 |
+
'status'=>array(
|
367 |
+
'label'=>__('Status'),
|
368 |
+
'values'=>$status_arr,
|
369 |
+
'val_labels'=>self::$status_label_arr,
|
370 |
+
'validation_rule'=>array('type'=>'absint'),
|
371 |
+
'val_type'=>'%d',
|
372 |
+
'selected_val'=>'',
|
373 |
+
),
|
374 |
+
);
|
375 |
+
|
376 |
+
if($list_by_cron) // no need of these filters in `cron by` listing
|
377 |
+
{
|
378 |
+
unset($filter_by['item_type']);
|
379 |
+
unset($filter_by['template_type']);
|
380 |
+
}
|
381 |
+
|
382 |
+
|
383 |
+
/**
|
384 |
+
* Order by field vals
|
385 |
+
*/
|
386 |
+
$order_by=array(
|
387 |
+
'date_desc'=>array('label'=>__('Date descending'), 'sql'=>'created_at DESC'),
|
388 |
+
'date_asc'=>array('label'=>__('Date ascending'), 'sql'=>'created_at ASC'),
|
389 |
+
);
|
390 |
+
|
391 |
+
/* just applying a text validation */
|
392 |
+
$conf_arr=isset($_GET['wt_iew_history']) ? Wt_Iew_Sh::sanitize_item($_GET['wt_iew_history'], 'text_arr') : array();
|
393 |
+
$url_params_allowed=array(); //this array will only include the allowed $_GET params. This will use in pagination section
|
394 |
+
|
395 |
+
/**
|
396 |
+
* Filter by block
|
397 |
+
*/
|
398 |
+
$where_qry_val_arr=array(); //sql query WHERE clause val array
|
399 |
+
$where_qry_format_arr=array(); //sql query WHERE clause val format array
|
400 |
+
if(isset($conf_arr['filter_by'])) /* filter by GET var exists */
|
401 |
+
{
|
402 |
+
$url_params_allowed['filter_by']=array();/* for pagination purpose */
|
403 |
+
|
404 |
+
$filter_by_conf=(is_array($conf_arr['filter_by']) ? $conf_arr['filter_by'] : array());
|
405 |
+
$filter_by_validation_rule=Wt_Import_Export_For_Woo_Basic_Common_Helper::extract_validation_rules($filter_by);
|
406 |
+
foreach ($filter_by as $filter_key => $filter_val)
|
407 |
+
{
|
408 |
+
if(isset($filter_by_conf[$filter_key]) && trim($filter_by_conf[$filter_key])!="") //current filter applied
|
409 |
+
{
|
410 |
+
$where_qry_format_arr[]=$filter_key.'='.$filter_val['val_type'];
|
411 |
+
$filter_by[$filter_key]['selected_val']=Wt_Iew_Sh::sanitize_data($filter_by_conf[$filter_key], $filter_key, $filter_by_validation_rule);
|
412 |
+
$where_qry_val_arr[]=$filter_by[$filter_key]['selected_val'];
|
413 |
+
|
414 |
+
$url_params_allowed['filter_by'][$filter_key]=$filter_by[$filter_key]['selected_val']; /* for pagination purpose */
|
415 |
+
}
|
416 |
+
}
|
417 |
+
}
|
418 |
+
|
419 |
+
/**
|
420 |
+
* Order by block
|
421 |
+
*/
|
422 |
+
$default_order_by=array_keys($order_by)[0];
|
423 |
+
$order_by_val=$default_order_by;
|
424 |
+
$order_qry_val_arr=array(); //sql query ORDER clause val array
|
425 |
+
if(isset($conf_arr['order_by'])) /* order by GET var exists */
|
426 |
+
{
|
427 |
+
$order_by_val=(is_array($conf_arr['order_by']) ? $default_order_by : $conf_arr['order_by']);
|
428 |
+
}
|
429 |
+
if(isset($order_by[$order_by_val]))
|
430 |
+
{
|
431 |
+
$order_qry_val_arr[]=$order_by[$order_by_val]['sql'];
|
432 |
+
$url_params_allowed['order_by']=$order_by_val; /* for pagination purpose */
|
433 |
+
}
|
434 |
+
|
435 |
+
/**
|
436 |
+
* Pagination block
|
437 |
+
*/
|
438 |
+
$max_data=(isset($conf_arr['max_data']) ? absint($conf_arr['max_data']) : $this->max_records);
|
439 |
+
$this->max_records=($max_data>0 ? $max_data : $this->max_records);
|
440 |
+
|
441 |
+
$offset=(isset($_GET['offset']) ? absint($_GET['offset']) : 0);
|
442 |
+
$url_params_allowed['max_data']=$this->max_records;
|
443 |
+
$pagination_url_params=array('wt_iew_history'=>$url_params_allowed, 'page'=>$this->module_id);
|
444 |
+
$offset_qry_str=" LIMIT $offset, ".$this->max_records;
|
445 |
+
$no_records=false;
|
446 |
+
|
447 |
+
if($list_by_cron) /* list by cron */
|
448 |
+
{
|
449 |
+
$pagination_url_params['wt_iew_cron_id']=$cron_id; /* adding cron id to URL params */
|
450 |
+
|
451 |
+
$total_history_ids=count($history_id_arr);
|
452 |
+
if($total_history_ids>0)
|
453 |
+
{
|
454 |
+
$where_qry_format_arr[]='id IN('.implode(",", array_fill(0, $total_history_ids, "%d")).")";
|
455 |
+
$where_qry_val_arr=array_merge($where_qry_val_arr, $history_id_arr);
|
456 |
+
|
457 |
+
}else //reset all where, order by queries
|
458 |
+
{
|
459 |
+
$where_qry_format_arr=array();
|
460 |
+
$where_qry_val_arr=array();
|
461 |
+
//$order_qry_val_arr=array();
|
462 |
+
$no_records=true;
|
463 |
+
}
|
464 |
+
}
|
465 |
+
|
466 |
+
$where_qry=(count($where_qry_format_arr)>0 ? ' WHERE '.implode(" AND ", $where_qry_format_arr) : '');
|
467 |
+
$orderby_qry=(count($order_qry_val_arr)>0 ? ' ORDER BY '.implode(", ", $order_qry_val_arr) : '');
|
468 |
+
|
469 |
+
/* prepare SQL */
|
470 |
+
$num_sql="SELECT COUNT(id) AS total_records FROM $tb $where_qry";
|
471 |
+
$list_sql="SELECT * FROM $tb $where_qry $orderby_qry ".$offset_qry_str;
|
472 |
+
|
473 |
+
if(count($where_qry_format_arr)>0)
|
474 |
+
{
|
475 |
+
$num_sql=$wpdb->prepare($num_sql, $where_qry_val_arr);
|
476 |
+
$list_sql=$wpdb->prepare($list_sql, $where_qry_val_arr);
|
477 |
+
}
|
478 |
+
|
479 |
+
if($no_records) /* in list_by cron, history IDs are not available */
|
480 |
+
{
|
481 |
+
$total_records=0;
|
482 |
+
$history_list=array();
|
483 |
+
}else
|
484 |
+
{
|
485 |
+
$total_records=$wpdb->get_row($num_sql, ARRAY_A);
|
486 |
+
$total_records=($total_records && isset($total_records['total_records']) ? $total_records['total_records'] : 0);
|
487 |
+
|
488 |
+
$history_list=$wpdb->get_results($list_sql, ARRAY_A);
|
489 |
+
$history_list=($history_list ? $history_list : array());
|
490 |
+
}
|
491 |
+
|
492 |
+
$delete_url_params=$pagination_url_params;
|
493 |
+
$delete_url_params['wt_iew_delete_history']=1;
|
494 |
+
$delete_url_params['wt_iew_history_id']='_history_id_';
|
495 |
+
$delete_url_params['offset']=$offset;
|
496 |
+
$delete_url=wp_nonce_url(admin_url('admin.php?'.http_build_query($delete_url_params)), WT_IEW_PLUGIN_ID_BASIC);
|
497 |
+
|
498 |
+
//enqueue script
|
499 |
+
if(isset($_GET['page']) && $_GET['page']==$this->module_id)
|
500 |
+
{
|
501 |
+
$this->enqueue_scripts($delete_url);
|
502 |
+
}
|
503 |
+
|
504 |
+
|
505 |
+
include plugin_dir_path(__FILE__).'views/settings.php';
|
506 |
+
}
|
507 |
+
|
508 |
+
private function enqueue_scripts($delete_url)
|
509 |
+
{
|
510 |
+
if(Wt_Import_Export_For_Woo_Basic_Common_Helper::wt_is_screen_allowed()){
|
511 |
+
wp_enqueue_script($this->module_id, plugin_dir_url(__FILE__).'assets/js/main.js', array('jquery'), WT_O_IEW_VERSION, false);
|
512 |
+
|
513 |
+
$params=array(
|
514 |
+
'delete_url'=>$delete_url,
|
515 |
+
'msgs'=>array(
|
516 |
+
'sure'=>__('Are you sure?'),
|
517 |
+
)
|
518 |
+
);
|
519 |
+
wp_localize_script($this->module_id, 'wt_iew_history_basic_params', $params);
|
520 |
+
}
|
521 |
+
}
|
522 |
+
|
523 |
+
public static function record_failure($history_id, $msg)
|
524 |
+
{
|
525 |
+
$update_data=array(
|
526 |
+
'status'=>self::$status_arr['failed'],
|
527 |
+
'status_text'=>$msg //no need to add translation function
|
528 |
+
);
|
529 |
+
$update_data_type=array(
|
530 |
+
'%d',
|
531 |
+
'%s',
|
532 |
+
);
|
533 |
+
self::update_history_entry($history_id, $update_data, $update_data_type);
|
534 |
+
}
|
535 |
+
|
536 |
+
/**
|
537 |
+
* Delete history entry from DB and also associated files (Export files only)
|
538 |
+
* @param array|int $id history entry IDs
|
539 |
+
*/
|
540 |
+
public static function delete_history_by_id($id)
|
541 |
+
{
|
542 |
+
global $wpdb;
|
543 |
+
$tb=$wpdb->prefix.Wt_Import_Export_For_Woo_Basic::$history_tb;
|
544 |
+
if(is_array($id))
|
545 |
+
{
|
546 |
+
$where=" IN(".implode(",", array_fill(0, count($id), '%d')).")";
|
547 |
+
$where_data=$id;
|
548 |
+
}else
|
549 |
+
{
|
550 |
+
$where="=%d";
|
551 |
+
$where_data=array($id);
|
552 |
+
}
|
553 |
+
|
554 |
+
//first remove files associated with it. give argument as array then no need to check the result array type
|
555 |
+
$allowed_ext_arr=array('csv', 'xml'); //please update this array if new file types introduced
|
556 |
+
$list=self::get_history_entry_by_id($where_data);
|
557 |
+
if($list)
|
558 |
+
{
|
559 |
+
foreach($list as $listv)
|
560 |
+
{
|
561 |
+
if($listv['template_type']=='export') //history is for export action
|
562 |
+
{
|
563 |
+
if(Wt_Import_Export_For_Woo_Admin_Basic::module_exists('export'))
|
564 |
+
{
|
565 |
+
$ext_arr=explode('.', $listv['file_name']);
|
566 |
+
$ext=end($ext_arr);
|
567 |
+
if(in_array($ext, $allowed_ext_arr)) /* delete only allowed extensions */
|
568 |
+
{
|
569 |
+
$file_path=Wt_Import_Export_For_Woo_Basic_Export::get_file_path($listv['file_name']);
|
570 |
+
if($file_path && file_exists($file_path))
|
571 |
+
{
|
572 |
+
@unlink($file_path);
|
573 |
+
}
|
574 |
+
}
|
575 |
+
}
|
576 |
+
}elseif($listv['template_type']=='import')
|
577 |
+
{
|
578 |
+
$action_module_obj=Wt_Import_Export_For_Woo_Basic::load_modules('import');
|
579 |
+
|
580 |
+
$log_file_name=$action_module_obj->get_log_file_name($listv['id']);
|
581 |
+
$log_file_path=$action_module_obj->get_file_path($log_file_name);
|
582 |
+
if(file_exists($log_file_path))
|
583 |
+
{
|
584 |
+
@unlink($log_file_path);
|
585 |
+
}
|
586 |
+
}
|
587 |
+
}
|
588 |
+
}
|
589 |
+
|
590 |
+
|
591 |
+
$wpdb->query(
|
592 |
+
$wpdb->prepare("DELETE FROM $tb WHERE id".$where, $where_data)
|
593 |
+
);
|
594 |
+
}
|
595 |
+
|
596 |
+
public static function update_history_entry($history_id, $update_data, $update_data_type)
|
597 |
+
{
|
598 |
+
global $wpdb;
|
599 |
+
//updating the data
|
600 |
+
$tb=$wpdb->prefix.Wt_Import_Export_For_Woo_Basic::$history_tb;
|
601 |
+
$update_where=array(
|
602 |
+
'id'=>$history_id
|
603 |
+
);
|
604 |
+
$update_where_type=array(
|
605 |
+
'%d'
|
606 |
+
);
|
607 |
+
if($wpdb->update($tb, $update_data, $update_where, $update_data_type, $update_where_type)!==false)
|
608 |
+
{
|
609 |
+
return true;
|
610 |
+
}
|
611 |
+
return false;
|
612 |
+
}
|
613 |
+
|
614 |
+
/**
|
615 |
+
* Mathod perform actions after advanced settings was updated
|
616 |
+
*
|
617 |
+
*/
|
618 |
+
public function after_advanced_setting_update($advanced_settings)
|
619 |
+
{
|
620 |
+
/* Check auto deletion enabled */
|
621 |
+
if(isset($advanced_settings['wt_iew_enable_history_auto_delete']) && $advanced_settings['wt_iew_enable_history_auto_delete']==1)
|
622 |
+
{
|
623 |
+
$record_count=(isset($advanced_settings['wt_iew_auto_delete_history_count']) ? absint($advanced_settings['wt_iew_auto_delete_history_count']) : 0);
|
624 |
+
if($record_count>0)
|
625 |
+
{
|
626 |
+
self::auto_delete_history_entry($record_count);
|
627 |
+
}
|
628 |
+
}
|
629 |
+
}
|
630 |
+
|
631 |
+
/**
|
632 |
+
* Check and delete history entry. If auto deletion enabled
|
633 |
+
*
|
634 |
+
*/
|
635 |
+
public static function auto_delete_history_entry($record_count=0)
|
636 |
+
{
|
637 |
+
if($record_count==0) /* this condition is for, some requests will come from create section or some from advanced settings section */
|
638 |
+
{
|
639 |
+
if(Wt_Import_Export_For_Woo_Basic_Common_Helper::get_advanced_settings('enable_history_auto_delete')==1)
|
640 |
+
{
|
641 |
+
$record_count=absint(Wt_Import_Export_For_Woo_Basic_Common_Helper::get_advanced_settings('auto_delete_history_count'));
|
642 |
+
}
|
643 |
+
}
|
644 |
+
if($record_count>=1)
|
645 |
+
{
|
646 |
+
global $wpdb;
|
647 |
+
$tb=$wpdb->prefix.Wt_Import_Export_For_Woo_Basic::$history_tb;
|
648 |
+
|
649 |
+
$data=$wpdb->get_results("SELECT * FROM $tb WHERE status=".self::$status_arr['finished']." AND id<(SELECT id FROM $tb ORDER BY id DESC LIMIT ".($record_count-1).",1)", ARRAY_A);
|
650 |
+
|
651 |
+
if($data && is_array($data))
|
652 |
+
{
|
653 |
+
$id_arr=array_column($data, 'id');
|
654 |
+
self::delete_history_by_id($id_arr);
|
655 |
+
}
|
656 |
+
}
|
657 |
+
}
|
658 |
+
|
659 |
+
/**
|
660 |
+
* create a history entry before starting export/import
|
661 |
+
* @param $file_name String export/import file name
|
662 |
+
* @param $form_data Array export/import formdata
|
663 |
+
* @param $action String export or import
|
664 |
+
* @return $history_id Int DB id if success otherwise zero
|
665 |
+
*/
|
666 |
+
public static function create_history_entry($file_name, $form_data, $to_process, $action)
|
667 |
+
{
|
668 |
+
global $wpdb;
|
669 |
+
|
670 |
+
$tb=$wpdb->prefix.Wt_Import_Export_For_Woo_Basic::$history_tb;
|
671 |
+
$insert_data=array(
|
672 |
+
'template_type'=>$action,
|
673 |
+
'item_type'=>$to_process, //item type Eg: product
|
674 |
+
'file_name'=>$file_name, //export/import file name
|
675 |
+
'created_at'=>time(), //craeted time
|
676 |
+
'data'=>maybe_serialize($form_data), //formadata
|
677 |
+
'status'=>self::$status_arr['pending'], //pending
|
678 |
+
'status_text'=>'Pending', //pending, No need to add translate function. we can add this on printing page
|
679 |
+
'offset'=>0, //current offset, its always 0 on start
|
680 |
+
'total'=>0, //total records, not available now
|
681 |
+
);
|
682 |
+
$insert_data_type=array(
|
683 |
+
'%s','%s','%s','%d','%s','%d','%d','%d'
|
684 |
+
);
|
685 |
+
|
686 |
+
$insert_response=$wpdb->insert($tb, $insert_data, $insert_data_type);
|
687 |
+
|
688 |
+
/* check for auto delete */
|
689 |
+
self::auto_delete_history_entry();
|
690 |
+
|
691 |
+
if($insert_response) //success
|
692 |
+
{
|
693 |
+
return $wpdb->insert_id;
|
694 |
+
}
|
695 |
+
return 0;
|
696 |
+
}
|
697 |
+
|
698 |
+
/**
|
699 |
+
* Get distinct column values from history table
|
700 |
+
* @param string $column table column name
|
701 |
+
* @return array array of distinct column values
|
702 |
+
*/
|
703 |
+
private static function get_disticnt_items($column)
|
704 |
+
{
|
705 |
+
global $wpdb;
|
706 |
+
$tb=$wpdb->prefix.Wt_Import_Export_For_Woo_Basic::$history_tb;
|
707 |
+
$data=$wpdb->get_results("SELECT DISTINCT $column FROM $tb ORDER BY $column ASC", ARRAY_A);
|
708 |
+
$data=is_array($data) ? $data : array();
|
709 |
+
return array_column($data, $column);
|
710 |
+
}
|
711 |
+
|
712 |
+
/**
|
713 |
+
* Taking history entry by ID
|
714 |
+
*/
|
715 |
+
public static function get_history_entry_by_id($id)
|
716 |
+
{
|
717 |
+
global $wpdb;
|
718 |
+
$tb=$wpdb->prefix.Wt_Import_Export_For_Woo_Basic::$history_tb;
|
719 |
+
if(is_array($id))
|
720 |
+
{
|
721 |
+
$where=" IN(".implode(",", array_fill(0, count($id), '%d')).")";
|
722 |
+
$where_data=$id;
|
723 |
+
}else
|
724 |
+
{
|
725 |
+
$where="=%d";
|
726 |
+
$where_data=array($id);
|
727 |
+
}
|
728 |
+
$qry=$wpdb->prepare("SELECT * FROM $tb WHERE id".$where, $where_data);
|
729 |
+
|
730 |
+
if(!is_array($id))
|
731 |
+
{
|
732 |
+
return $wpdb->get_row($qry, ARRAY_A);
|
733 |
+
}else
|
734 |
+
{
|
735 |
+
return $wpdb->get_results($qry, ARRAY_A);
|
736 |
+
}
|
737 |
+
}
|
738 |
+
|
739 |
+
|
740 |
+
/**
|
741 |
+
* Download log file via a nonce URL
|
742 |
+
*/
|
743 |
+
public function download_file()
|
744 |
+
{
|
745 |
+
if(isset($_GET['wt_iew_log_download']))
|
746 |
+
{
|
747 |
+
if(Wt_Iew_Sh::check_write_access(WT_IEW_PLUGIN_ID_BASIC)) /* check nonce and role */
|
748 |
+
{
|
749 |
+
$file_name=(isset($_GET['file']) ? sanitize_text_field($_GET['file']) : '');
|
750 |
+
if($file_name!="")
|
751 |
+
{
|
752 |
+
$file_arr=explode(".", $file_name);
|
753 |
+
$file_ext=end($file_arr);
|
754 |
+
if($file_ext=='log') /* Only allowed files. */
|
755 |
+
{
|
756 |
+
$file_path=Wt_Import_Export_For_Woo_Basic_Log::get_file_path($file_name);
|
757 |
+
if(file_exists($file_path) && is_file($file_path))
|
758 |
+
{
|
759 |
+
header('Pragma: public');
|
760 |
+
header('Expires: 0');
|
761 |
+
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
762 |
+
header('Cache-Control: private', false);
|
763 |
+
header('Content-Transfer-Encoding: binary');
|
764 |
+
header('Content-Disposition: attachment; filename="'.$file_name.'";');
|
765 |
+
header('Content-Description: File Transfer');
|
766 |
+
header('Content-Type: application/octet-stream');
|
767 |
+
//header('Content-Length: '.filesize($file_path));
|
768 |
+
|
769 |
+
$chunk_size=1024 * 1024;
|
770 |
+
$handle=@fopen($file_path, 'rb');
|
771 |
+
while(!feof($handle))
|
772 |
+
{
|
773 |
+
$buffer = fread($handle, $chunk_size);
|
774 |
+
echo $buffer;
|
775 |
+
ob_flush();
|
776 |
+
flush();
|
777 |
+
}
|
778 |
+
fclose($handle);
|
779 |
+
exit();
|
780 |
+
|
781 |
+
}
|
782 |
+
}
|
783 |
+
}
|
784 |
+
}
|
785 |
+
}
|
786 |
+
}
|
787 |
+
|
788 |
+
|
789 |
+
/**
|
790 |
+
*
|
791 |
+
* Generate pagination HTML
|
792 |
+
*/
|
793 |
+
public static function gen_pagination_html($total, $limit, $offset, $url, $url_params=array(), $mxnav=6)
|
794 |
+
{
|
795 |
+
if($total<=0){
|
796 |
+
return '';
|
797 |
+
}
|
798 |
+
/* taking current page */
|
799 |
+
$crpage=($offset+$limit)/$limit;
|
800 |
+
|
801 |
+
$limit=$limit<=0 ? 1 : $limit;
|
802 |
+
$ttpg=ceil($total/$limit);
|
803 |
+
if($ttpg<$crpage){
|
804 |
+
//return '';
|
805 |
+
}
|
806 |
+
|
807 |
+
//calculations
|
808 |
+
$mxnav=$ttpg<$mxnav ? $ttpg : $mxnav;
|
809 |
+
|
810 |
+
$mxnav_mid=floor($mxnav/2);
|
811 |
+
$pgstart=$mxnav_mid>=$crpage ? 1 : $crpage-$mxnav_mid;
|
812 |
+
$mxnav_mid+=$mxnav_mid>=$crpage ? ($mxnav_mid-$crpage) : 0; //adjusting other half with first half balance
|
813 |
+
$pgend=$crpage+$mxnav_mid;
|
814 |
+
if($pgend>$ttpg)
|
815 |
+
{
|
816 |
+
$pgend=$ttpg;
|
817 |
+
}
|
818 |
+
|
819 |
+
$html='<span class="wt_iew_pagination_total_info">'.$total.__(' record(s)').'</span>';
|
820 |
+
$url_params_string=http_build_query($url_params);
|
821 |
+
$url_params_string=$url_params_string!="" ? '&'.$url_params_string : '';
|
822 |
+
$url=(strpos($url, '?')!==false ? $url.'&' : $url.'?');
|
823 |
+
$href_attr=' href="'.$url.'offset={offset}'.$url_params_string.'"';
|
824 |
+
|
825 |
+
$prev_onclick='';
|
826 |
+
if($crpage>1)
|
827 |
+
{
|
828 |
+
$offset=(($crpage-2)*$limit);
|
829 |
+
$prev_onclick=str_replace('{offset}', $offset, $href_attr);
|
830 |
+
}
|
831 |
+
|
832 |
+
$html.='<a class="'.($crpage>1 ? 'wt_iew_page' : 'wt_iew_pagedisabled').'"'.$prev_onclick.'>‹</a>';
|
833 |
+
for($i=$pgstart; $i<=$pgend; $i++)
|
834 |
+
{
|
835 |
+
$page_offset='';
|
836 |
+
$onclick='';
|
837 |
+
$offset=($i*$limit)-$limit;
|
838 |
+
if($i!=$crpage)
|
839 |
+
{
|
840 |
+
$onclick=str_replace('{offset}', $offset, $href_attr);
|
841 |
+
}
|
842 |
+
$html.='<a class="'.($i==$crpage ? 'wt_iew_pageactive' : 'wt_iew_page').'" '.$onclick.'>'.$i.'</a>';
|
843 |
+
}
|
844 |
+
|
845 |
+
$next_onclick='';
|
846 |
+
if($crpage<$ttpg)
|
847 |
+
{
|
848 |
+
$offset=($crpage*$limit);
|
849 |
+
$next_onclick=str_replace('{offset}', $offset, $href_attr);
|
850 |
+
}
|
851 |
+
|
852 |
+
$html.='<a class="'.($crpage<$ttpg ? 'wt_iew_page' : 'wt_iew_pagedisabled').'"'.$next_onclick.'>›</a>';
|
853 |
+
return '<div class="wt_iew_pagination"><span>'.$html.'</div>';
|
854 |
+
}
|
855 |
+
}
|
856 |
+
}
|
857 |
+
Wt_Import_Export_For_Woo_Basic::$loaded_modules['history']=new Wt_Import_Export_For_Woo_Basic_History();
|
admin/modules/history/views/_history_list.php
ADDED
@@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'WPINC' ) ) {
|
3 |
+
die;
|
4 |
+
}
|
5 |
+
?>
|
6 |
+
<div class="wt_iew_history_page">
|
7 |
+
<h2 class="wp-heading-inline"><?php _e('Import/Export history');?></h2>
|
8 |
+
|
9 |
+
<div style="margin-bottom:25px;">
|
10 |
+
<?php _e('Lists the runs and the status corresponding to every import/export with options to re-run, view detailed log or delete entry.');?>
|
11 |
+
</div>
|
12 |
+
|
13 |
+
|
14 |
+
<div class="wt_iew_history_settings">
|
15 |
+
<form action="admin.php">
|
16 |
+
<input type="hidden" name="page" value="<?php echo $this->module_id;?>">
|
17 |
+
<?php
|
18 |
+
if(array_filter(array_column($filter_by, 'values')))
|
19 |
+
{
|
20 |
+
?>
|
21 |
+
<div class="wt_iew_history_settings_hd"><?php _e('Filter'); ?></div>
|
22 |
+
<div class="wt_iew_history_settings_form_group_box">
|
23 |
+
<?php
|
24 |
+
foreach ($filter_by as $filter_by_key => $filter_by_value)
|
25 |
+
{
|
26 |
+
if(count($filter_by_value['values'])>0)
|
27 |
+
{
|
28 |
+
?>
|
29 |
+
<div class="wt_iew_history_settings_form_group">
|
30 |
+
<label><?php echo $filter_by_value['label']; ?></label>
|
31 |
+
<select name="wt_iew_history[filter_by][<?php echo $filter_by_key;?>]" class="wt_iew_select">
|
32 |
+
<option value=""><?php _e('All'); ?></option>
|
33 |
+
<?php
|
34 |
+
$val_labels=$filter_by_value['val_labels'];
|
35 |
+
foreach($filter_by_value['values'] as $val)
|
36 |
+
{
|
37 |
+
?>
|
38 |
+
<option value="<?php echo $val;?>" <?php echo ($filter_by_value['selected_val']==$val ? 'selected="selected"' : '');?>><?php echo (isset($val_labels[$val]) ? $val_labels[$val] : $val);?></option>
|
39 |
+
<?php
|
40 |
+
}
|
41 |
+
?>
|
42 |
+
</select>
|
43 |
+
</div>
|
44 |
+
<?php
|
45 |
+
}
|
46 |
+
}
|
47 |
+
?>
|
48 |
+
</div>
|
49 |
+
<?php
|
50 |
+
}
|
51 |
+
?>
|
52 |
+
|
53 |
+
<div class="wt_iew_history_settings_form_group_box">
|
54 |
+
<div class="wt_iew_history_settings_form_group">
|
55 |
+
<label><?php _e('Sort by'); ?></label>
|
56 |
+
<select name="wt_iew_history[order_by]" class="wt_iew_select">
|
57 |
+
<?php
|
58 |
+
foreach ($order_by as $key => $value)
|
59 |
+
{
|
60 |
+
?>
|
61 |
+
<option value="<?php echo $key;?>" <?php echo ($order_by_val==$key ? 'selected="selected"' : '');?>><?php echo $value['label'];?></option>
|
62 |
+
<?php
|
63 |
+
}
|
64 |
+
?>
|
65 |
+
</select>
|
66 |
+
</div>
|
67 |
+
<div class="wt_iew_history_settings_form_group">
|
68 |
+
<label><?php _e('Max record/page'); ?></label>
|
69 |
+
<input type="text" name="wt_iew_history[max_data]" value="<?php echo $this->max_records;?>" class="wt_iew_text" style="width:50px;">
|
70 |
+
</div>
|
71 |
+
</div>
|
72 |
+
<div class="wt_iew_history_settings_form_group_box">
|
73 |
+
<input type="hidden" name="offset" value="0">
|
74 |
+
<?php
|
75 |
+
if($list_by_cron) /* list by cron */
|
76 |
+
{
|
77 |
+
?>
|
78 |
+
<input type="hidden" name="wt_iew_cron_id" value="<?php echo $cron_id;?>">
|
79 |
+
<?php
|
80 |
+
}
|
81 |
+
?>
|
82 |
+
<button class="button button-primary" type="submit" style="float:left;"><?php _e('Apply'); ?></button>
|
83 |
+
</div>
|
84 |
+
</form>
|
85 |
+
</div>
|
86 |
+
|
87 |
+
<div class="wt_iew_bulk_action_box">
|
88 |
+
<select class="wt_iew_bulk_action wt_iew_select">
|
89 |
+
<option value=""><?php _e('Bulk Actions'); ?></option>
|
90 |
+
<option value="delete"><?php _e('Delete'); ?></option>
|
91 |
+
</select>
|
92 |
+
<button class="button button-primary wt_iew_bulk_action_btn" type="button" style="float:left;"><?php _e('Apply'); ?></button>
|
93 |
+
</div>
|
94 |
+
<?php
|
95 |
+
echo self::gen_pagination_html($total_records, $this->max_records, $offset, 'admin.php', $pagination_url_params);
|
96 |
+
?>
|
97 |
+
<?php
|
98 |
+
if(isset($history_list) && is_array($history_list) && count($history_list)>0)
|
99 |
+
{
|
100 |
+
?>
|
101 |
+
<table class="wp-list-table widefat fixed striped history_list_tb">
|
102 |
+
<thead>
|
103 |
+
<tr>
|
104 |
+
<th width="100">
|
105 |
+
<input type="checkbox" name="" class="wt_iew_history_checkbox_main">
|
106 |
+
<?php _e("No."); ?>
|
107 |
+
</th>
|
108 |
+
<th><?php _e("Id"); ?></th>
|
109 |
+
<th><?php _e("Action type"); ?></th>
|
110 |
+
<th><?php _e("Post type"); ?></th>
|
111 |
+
<th><?php _e("Started at"); ?></th>
|
112 |
+
<th>
|
113 |
+
<?php _e("Status"); ?>
|
114 |
+
<span class="dashicons dashicons-editor-help wt-iew-tips"
|
115 |
+
data-wt-iew-tip="
|
116 |
+
<span class='wt_iew_tooltip_span'><?php echo sprintf(__('%sSuccess%s - Process completed successfully'), '<b>', '</b>');?></span><br />
|
117 |
+
<span class='wt_iew_tooltip_span'><?php echo sprintf(__('%sFailed%s - Failed process triggered due to connection/permission or similar issues(unable to establish FTP/DB connection, write permission issues etc.)'), '<b>', '</b>');?> </span><br />
|
118 |
+
<span class='wt_iew_tooltip_span'><?php echo sprintf(__('%sRunning/Incomplete%s - Process that are running currently or that may have been terminated unknowingly(e.g, closing a browser tab while in progress etc)'), '<b>', '</b>');?> </span>">
|
119 |
+
</span>
|
120 |
+
</th>
|
121 |
+
<th>
|
122 |
+
<?php _e("Actions"); ?>
|
123 |
+
<span class="dashicons dashicons-editor-help wt-iew-tips"
|
124 |
+
data-wt-iew-tip=" <span class='wt_iew_tooltip_span'><?php _e('Re-run will take the user to the respective screen depending on the corresponding action type and the user can initiate the process accordingly.');?></span>"></span>
|
125 |
+
</th>
|
126 |
+
</tr>
|
127 |
+
</thead>
|
128 |
+
<tbody>
|
129 |
+
<?php
|
130 |
+
$i=$offset;
|
131 |
+
foreach($history_list as $key =>$history_item)
|
132 |
+
{
|
133 |
+
$i++;
|
134 |
+
?>
|
135 |
+
<tr>
|
136 |
+
<th>
|
137 |
+
<input type="checkbox" value="<?php echo $history_item['id'];?>" name="history_id[]" class="wt_iew_history_checkbox_sub">
|
138 |
+
<?php echo $i;?>
|
139 |
+
</td>
|
140 |
+
<td><?php echo $history_item['id']; ?></td>
|
141 |
+
<td><?php echo ucfirst($history_item['template_type']); ?></td>
|
142 |
+
<td><?php echo ucfirst($history_item['item_type']); ?></td>
|
143 |
+
<td><?php echo date_i18n('Y-m-d h:i:s A', $history_item['created_at']); ?></td>
|
144 |
+
<td>
|
145 |
+
<?php
|
146 |
+
echo (isset(self::$status_label_arr[$history_item['status']]) ? self::$status_label_arr[$history_item['status']] : __('Unknown'));
|
147 |
+
?>
|
148 |
+
</td>
|
149 |
+
<td>
|
150 |
+
<a class="wt_iew_delete_history" data-href="<?php echo str_replace('_history_id_', $history_item['id'], $delete_url);?>"><?php _e('Delete'); ?></a>
|
151 |
+
<?php
|
152 |
+
$form_data=maybe_unserialize($history_item['data']);
|
153 |
+
$action_type=$history_item['template_type'];
|
154 |
+
if($form_data && is_array($form_data))
|
155 |
+
{
|
156 |
+
$to_process=(isset($form_data['post_type_form_data']) && isset($form_data['post_type_form_data']['item_type']) ? $form_data['post_type_form_data']['item_type'] : '');
|
157 |
+
if($to_process!="")
|
158 |
+
{
|
159 |
+
if(Wt_Import_Export_For_Woo_Admin_Basic::module_exists($action_type))
|
160 |
+
{
|
161 |
+
$action_module_id=Wt_Import_Export_For_Woo_Basic::get_module_id($action_type);
|
162 |
+
$url=admin_url('admin.php?page='.$action_module_id.'&wt_iew_rerun='.$history_item['id']);
|
163 |
+
?>
|
164 |
+
| <a href="<?php echo $url;?>" target="_blank"><?php _e("Re-Run");?></a>
|
165 |
+
<?php
|
166 |
+
}
|
167 |
+
}
|
168 |
+
}
|
169 |
+
if($action_type=='import' && Wt_Import_Export_For_Woo_Admin_Basic::module_exists($action_type))
|
170 |
+
{
|
171 |
+
$action_module_obj=Wt_Import_Export_For_Woo_Basic::load_modules($action_type);
|
172 |
+
$log_file_name=$action_module_obj->get_log_file_name($history_item['id']);
|
173 |
+
$log_file_path=$action_module_obj->get_file_path($log_file_name);
|
174 |
+
if(file_exists($log_file_path))
|
175 |
+
{
|
176 |
+
?>
|
177 |
+
| <a class="wt_iew_view_log_btn" data-history-id="<?php echo $history_item['id'];?>"><?php _e("View log");?></a>
|
178 |
+
<?php
|
179 |
+
}
|
180 |
+
}
|
181 |
+
?>
|
182 |
+
</td>
|
183 |
+
</tr>
|
184 |
+
<?php
|
185 |
+
}
|
186 |
+
?>
|
187 |
+
</tbody>
|
188 |
+
</table>
|
189 |
+
<?php
|
190 |
+
echo self::gen_pagination_html($total_records, $this->max_records, $offset, 'admin.php', $pagination_url_params);
|
191 |
+
}else
|
192 |
+
{
|
193 |
+
?>
|
194 |
+
<h4 class="wt_iew_history_no_records"><?php _e("No records found."); ?></h4>
|
195 |
+
<?php
|
196 |
+
}
|
197 |
+
?>
|
198 |
+
</div>
|
admin/modules/history/views/_log_list.php
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'WPINC' ) ) {
|
3 |
+
die;
|
4 |
+
}
|
5 |
+
/* delete after redirect */
|
6 |
+
if(isset($_GET['wt_iew_delete_log']))
|
7 |
+
{
|
8 |
+
?>
|
9 |
+
<script type="text/javascript">
|
10 |
+
window.location.href='<?php echo admin_url('admin.php?page='.$this->module_id.'_log'); ?>';
|
11 |
+
</script>
|
12 |
+
<?php
|
13 |
+
}
|
14 |
+
?>
|
15 |
+
<div class="wt_iew_history_page">
|
16 |
+
<h2 class="wp-heading-inline"><?php _e('Logs');?></h2>
|
17 |
+
<p>
|
18 |
+
<?php _e('Lists developer logs mostly required for debugging purposes. Options to view detailed logs are available along with delete and download(that can be shared with the support team in case of issues).');?>
|
19 |
+
</p>
|
20 |
+
|
21 |
+
<?php
|
22 |
+
$log_path=Wt_Import_Export_For_Woo_Basic_Log::$log_dir;
|
23 |
+
$log_files = glob($log_path.'/*'.'.log');
|
24 |
+
if(is_array($log_files) && count($log_files)>0)
|
25 |
+
{
|
26 |
+
foreach ($log_files as $key => $value) {
|
27 |
+
$date_time = str_replace('.log','',substr($value, strrpos($value, '_') + 1));
|
28 |
+
$d = DateTime::createFromFormat('Y-m-d H i s A', $date_time);
|
29 |
+
if ($d == false) {
|
30 |
+
$index = $date_time;
|
31 |
+
} else {
|
32 |
+
$index = $d->getTimestamp();
|
33 |
+
}
|
34 |
+
$indexed_log_files[$index] = $value;
|
35 |
+
}
|
36 |
+
krsort($indexed_log_files);
|
37 |
+
$log_files = $indexed_log_files;
|
38 |
+
|
39 |
+
?>
|
40 |
+
<table class="wp-list-table widefat fixed striped history_list_tb log_list_tb">
|
41 |
+
<thead>
|
42 |
+
<tr>
|
43 |
+
<th class="log_file_name_col"><?php _e("File"); ?></th>
|
44 |
+
<th><?php _e("Actions"); ?></th>
|
45 |
+
</tr>
|
46 |
+
</thead>
|
47 |
+
<tbody>
|
48 |
+
<?php
|
49 |
+
foreach($log_files as $log_file)
|
50 |
+
{
|
51 |
+
$file_name=basename($log_file);
|
52 |
+
?>
|
53 |
+
<tr>
|
54 |
+
<td class="log_file_name_col"><a class="wt_iew_view_log_btn" data-log-file="<?php echo $file_name;?>"><?php echo $file_name; ?></a></td>
|
55 |
+
<td>
|
56 |
+
<a class="wt_iew_delete_log" data-href="<?php echo str_replace('_log_file_', $file_name, $delete_url);?>"><?php _e('Delete'); ?></a>
|
57 |
+
| <a class="wt_iew_view_log_btn" data-log-file="<?php echo $file_name;?>"><?php _e("View");?></a>
|
58 |
+
| <a class="wt_iew_download_log_btn" href="<?php echo str_replace('_log_file_', $file_name, $download_url);?>"><?php _e("Download");?></a>
|
59 |
+
</td>
|
60 |
+
</tr>
|
61 |
+
<?php
|
62 |
+
}
|
63 |
+
?>
|
64 |
+
</tbody>
|
65 |
+
</table>
|
66 |
+
<?php
|
67 |
+
}else
|
68 |
+
{
|
69 |
+
?>
|
70 |
+
<h4 class="wt_iew_history_no_records"><?php _e("No logs found."); ?></h4>
|
71 |
+
<?php
|
72 |
+
}
|
73 |
+
?>
|
74 |
+
</div>
|
admin/modules/history/views/_log_table.php
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Log table view file
|
4 |
+
*
|
5 |
+
* @link
|
6 |
+
*
|
7 |
+
* @package Wt_Import_Export_For_Woo
|
8 |
+
*/
|
9 |
+
if (!defined('ABSPATH')) {
|
10 |
+
exit;
|
11 |
+
}
|
12 |
+
if(isset($log_list) && is_array($log_list) && count($log_list)>0)
|
13 |
+
{
|
14 |
+
if($offset==0)
|
15 |
+
{
|
16 |
+
?>
|
17 |
+
<table class="wp-list-table widefat fixed striped log_view_tb" style="margin-bottom:25px;">
|
18 |
+
<thead>
|
19 |
+
<tr>
|
20 |
+
<th style="width:100px;"><?php _e("Row No."); ?></th>
|
21 |
+
<th><?php _e("Status"); ?></th>
|
22 |
+
<th><?php _e("Message"); ?></th>
|
23 |
+
<th><?php _e("Item"); ?></th>
|
24 |
+
</tr>
|
25 |
+
</thead>
|
26 |
+
<tbody class="log_view_tb_tbody">
|
27 |
+
<?php
|
28 |
+
}
|
29 |
+
foreach($log_list as $key =>$log_item)
|
30 |
+
{
|
31 |
+
?>
|
32 |
+
<tr>
|
33 |
+
<td><?php echo absint($log_item['row']); ?></td>
|
34 |
+
<td><?php echo ($log_item['status'] ? __('Success') : __('Failed/Skipped') ); ?></td>
|
35 |
+
<td><?php esc_html_e($log_item['message']); ?></td>
|
36 |
+
<td>
|
37 |
+
<?php
|
38 |
+
if($show_item_details)
|
39 |
+
{
|
40 |
+
$item_data=$item_type_module_obj->get_item_by_id($log_item['post_id']);
|
41 |
+
if($item_data && isset($item_data['title']))
|
42 |
+
{
|
43 |
+
if(isset($item_data['edit_url']))
|
44 |
+
{
|
45 |
+
echo '<a href="'.$item_data['edit_url'].'" target="_blank">'.$item_data['title'].'</a>';
|
46 |
+
}else
|
47 |
+
{
|
48 |
+
echo $item_data['title'];
|
49 |
+
}
|
50 |
+
}else
|
51 |
+
{
|
52 |
+
echo $log_item['post_id'];
|
53 |
+
}
|
54 |
+
}else
|
55 |
+
{
|
56 |
+
echo $log_item['post_id'];
|
57 |
+
}
|
58 |
+
?>
|
59 |
+
</td>
|
60 |
+
</tr>
|
61 |
+
<?php
|
62 |
+
}
|
63 |
+
if($offset==0)
|
64 |
+
{
|
65 |
+
?>
|
66 |
+
</tbody>
|
67 |
+
</table>
|
68 |
+
<h4 style="margin-top:0px;">
|
69 |
+
<a class="wt_iew_history_loadmore_btn button button-primary"> <?php _e("Load more."); ?></a>
|
70 |
+
<span class="wt_iew_history_loadmore_loading" style="display:none;"><?php _e("Loading...."); ?></span>
|
71 |
+
</h4>
|
72 |
+
<?php
|
73 |
+
}
|
74 |
+
}else
|
75 |
+
{
|
76 |
+
?>
|
77 |
+
<h4 style="margin-bottom:55px;"><?php _e("No records found."); ?> </h4>
|
78 |
+
<?php
|
79 |
+
}
|
80 |
+
?>
|
admin/modules/history/views/settings.php
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'WPINC' ) ) {
|
3 |
+
die;
|
4 |
+
}
|
5 |
+
?>
|
6 |
+
<style type="text/css">
|
7 |
+
.wt_iew_history_page{ padding:15px; }
|
8 |
+
.history_list_tb td, .history_list_tb th{ text-align:center; }
|
9 |
+
.history_list_tb tr th:first-child{ text-align:left; }
|
10 |
+
.wt_iew_delete_history, .wt_iew_delete_log{ cursor:pointer; }
|
11 |
+
.wt_iew_history_settings{ float:left; width:100%; padding:15px; background:#fff; border:solid 1px #ccd0d4; box-sizing:border-box; margin-bottom:15px; }
|
12 |
+
.wt_iew_history_settings_hd{ float:left; width:100%; font-weight:bold; font-size:13px; }
|
13 |
+
.wt_iew_history_settings_form_group_box{ float:left; width:100%; box-sizing:border-box; padding:10px; padding-bottom:0px; height:auto; font-size:12px; }
|
14 |
+
.wt_iew_history_settings_form_group{ float:left; width:auto; margin-right:3%; min-width:200px;}
|
15 |
+
.wt_iew_history_settings_form_group label{ font-size:12px; font-weight:bold; }
|
16 |
+
.wt_iew_history_settings_form_group select, .wt_iew_history_settings_form_group input[type="text"]{ height:20px; }
|
17 |
+
.wt_iew_history_no_records{float:left; width:100%; margin-bottom:55px; margin-top:20px; text-align:center; background:#fff; padding:15px 0px; border:solid 1px #ccd0d4;}
|
18 |
+
.wt_iew_bulk_action_box{ float:left; width:auto; margin:10px 0px; }
|
19 |
+
select.wt_iew_bulk_action{ float:left; width:auto; height:20px; margin-right:10px; }
|
20 |
+
.wt_iew_view_log_btn{ cursor:pointer; }
|
21 |
+
.wt_iew_view_log{ }
|
22 |
+
.wt_iew_log_loader{ width:100%; height:200px; text-align:center; line-height:150px; font-size:14px; font-style:italic; }
|
23 |
+
.wt_iew_log_container{ padding:25px; }
|
24 |
+
.wt_iew_raw_log{ text-align:left; font-size:14px; }
|
25 |
+
.log_view_tb th, .log_view_tb td{ text-align:center; }
|
26 |
+
.log_list_tb .log_file_name_col{ text-align:left; }
|
27 |
+
</style>
|
28 |
+
<div class="wt_iew_view_log wt_iew_popup">
|
29 |
+
<div class="wt_iew_popup_hd">
|
30 |
+
<span style="line-height:40px;" class="dashicons dashicons-media-text"></span>
|
31 |
+
<span class="wt_iew_popup_hd_label"><?php _e('View log');?></span>
|
32 |
+
<div class="wt_iew_popup_close">X</div>
|
33 |
+
</div>
|
34 |
+
<div class="wt_iew_log_container">
|
35 |
+
|
36 |
+
</div>
|
37 |
+
</div>
|
38 |
+
<?php
|
39 |
+
if(isset($_GET['page']) && $_GET['page']==$this->module_id.'_log')
|
40 |
+
{
|
41 |
+
include plugin_dir_path(__FILE__)."/_log_list.php";
|
42 |
+
}else
|
43 |
+
{
|
44 |
+
include plugin_dir_path(__FILE__)."/_history_list.php";
|
45 |
+
}
|
46 |
+
?>
|
admin/modules/import/assets/js/main.js
ADDED
@@ -0,0 +1,1453 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var wt_iew_basic_import=(function( $ ) {
|
2 |
+
//'use strict';
|
3 |
+
var wt_iew_basic_import=
|
4 |
+
{
|
5 |
+
ajax_data:{},
|
6 |
+
selected_template:0,
|
7 |
+
selected_template_name:'',
|
8 |
+
to_import:'',
|
9 |
+
to_import_title:'',
|
10 |
+
import_method:'',
|
11 |
+
current_step:'',
|
12 |
+
loaded_status_arr:{'loaded':1, 'loading':2, 'not_loaded':0},
|
13 |
+
page_overlay:false,
|
14 |
+
step_keys:[],
|
15 |
+
form_data:{},
|
16 |
+
is_valid_file:false,
|
17 |
+
temp_import_file:'',
|
18 |
+
file_from:'',
|
19 |
+
blocked_action:'', /* the current action will be blocked if file validation is not done. After the successful validation the blocked action will be executed */
|
20 |
+
local_import_file:'',
|
21 |
+
url_import_file:'',
|
22 |
+
on_rerun:false,
|
23 |
+
rerun_id:0,
|
24 |
+
import_delimiter:',',
|
25 |
+
Set:function()
|
26 |
+
{
|
27 |
+
this.step_keys=Object.keys(wt_iew_import_basic_params.steps);
|
28 |
+
if(this.on_rerun)
|
29 |
+
{
|
30 |
+
this.rerun();
|
31 |
+
}else
|
32 |
+
{
|
33 |
+
var first_step=this.step_keys[0];
|
34 |
+
this.load_steps([first_step], first_step);
|
35 |
+
this.show_step_page(first_step, false); /* just to show a loading */
|
36 |
+
}
|
37 |
+
},
|
38 |
+
rerun:function()
|
39 |
+
{
|
40 |
+
var last_step=this.step_keys[this.step_keys.length-1];
|
41 |
+
this.load_steps(this.step_keys, last_step);
|
42 |
+
this.show_step_page(last_step, false); /* just to show a loading */
|
43 |
+
},
|
44 |
+
filter_loaded_steps:function(steps)
|
45 |
+
{
|
46 |
+
var filtered_steps=new Array();
|
47 |
+
$.each(steps, function(step_ind, step){
|
48 |
+
if(wt_iew_basic_import.get_page_dom_object(step).attr('data-loaded')!=wt_iew_basic_import.loaded_status_arr['loaded'])
|
49 |
+
{
|
50 |
+
filtered_steps.push(step);
|
51 |
+
}
|
52 |
+
});
|
53 |
+
return filtered_steps;
|
54 |
+
},
|
55 |
+
load_steps:function(steps, step_to_show)
|
56 |
+
{
|
57 |
+
steps=this.filter_loaded_steps(steps);
|
58 |
+
if(steps.length==0){ return; }
|
59 |
+
this.prepare_ajax_data('get_steps', 'json');
|
60 |
+
this.ajax_data.steps=steps;
|
61 |
+
if(this.on_rerun)
|
62 |
+
{
|
63 |
+
this.ajax_data.rerun_id=this.rerun_id;
|
64 |
+
}
|
65 |
+
this.set_step_loading_status(steps, 'loading');
|
66 |
+
this.set_ajax_page_loader(steps, 'loading');
|
67 |
+
$.ajax({
|
68 |
+
type: 'POST',
|
69 |
+
url:wt_iew_basic_params.ajax_url,
|
70 |
+
data:this.ajax_data,
|
71 |
+
dataType:'json',
|
72 |
+
success:function(data)
|
73 |
+
{
|
74 |
+
if(data!=null && data.status==1)
|
75 |
+
{
|
76 |
+
wt_iew_basic_import.set_step_page(data);
|
77 |
+
wt_iew_basic_import.set_step_loading_status(steps, 'loaded');
|
78 |
+
if(step_to_show)
|
79 |
+
{
|
80 |
+
wt_iew_basic_import.show_step_page(step_to_show, true);
|
81 |
+
}
|
82 |
+
if(wt_iew_basic_import.on_rerun)
|
83 |
+
{
|
84 |
+
wt_iew_basic_import.load_meta_mapping_fields();
|
85 |
+
wt_iew_basic_import.set_validate_file_info(); /* this will prevent revalidation of files */
|
86 |
+
wt_iew_basic_import.on_rerun=false;
|
87 |
+
wt_iew_basic_import.rerun_id=0;
|
88 |
+
}
|
89 |
+
}else
|
90 |
+
{
|
91 |
+
wt_iew_basic_import.set_step_loading_status(steps, 'not_loaded');
|
92 |
+
wt_iew_basic_import.set_ajax_page_loader(steps, 'error');
|
93 |
+
}
|
94 |
+
wt_iew_basic_import.remove_ajax_page_loader();
|
95 |
+
},
|
96 |
+
error:function()
|
97 |
+
{
|
98 |
+
wt_iew_basic_import.set_step_loading_status(steps, 'not_loaded');
|
99 |
+
wt_iew_basic_import.remove_ajax_page_loader();
|
100 |
+
wt_iew_basic_import.set_ajax_page_loader(steps, 'error');
|
101 |
+
}
|
102 |
+
});
|
103 |
+
},
|
104 |
+
load_meta_mapping_fields:function()
|
105 |
+
{
|
106 |
+
this.prepare_ajax_data('get_meta_mapping_fields', 'json');
|
107 |
+
this.ajax_data['file_head_meta']=JSON.stringify(wt_iew_file_head_remaining_meta);
|
108 |
+
$('.meta_mapping_box_con[data-loaded="0"]').html('<div class="wt_iew_import_step_loader">'+wt_iew_basic_params.msgs.loading+'</div>');
|
109 |
+
$.ajax({
|
110 |
+
type: 'POST',
|
111 |
+
url:wt_iew_basic_params.ajax_url,
|
112 |
+
data:this.ajax_data,
|
113 |
+
dataType:'json',
|
114 |
+
success:function(data)
|
115 |
+
{
|
116 |
+
if(data.status==1)
|
117 |
+
{
|
118 |
+
$.each(data.meta_html, function(meta_id, meta_content){
|
119 |
+
$('.meta_mapping_box_con[data-key="'+meta_id+'"]').html(meta_content).attr('data-loaded', 1);
|
120 |
+
});
|
121 |
+
wt_iew_basic_import.enable_sortable();
|
122 |
+
wt_iew_basic_import.reg_mapping_field_bulk_action();
|
123 |
+
wt_iew_popover.Set();
|
124 |
+
}else
|
125 |
+
{
|
126 |
+
$('.meta_mapping_box_con[data-loaded="0"]').html('<div class="wt_iew_import_step_loader">'+wt_iew_basic_params.msgs.error+'</div>');
|
127 |
+
}
|
128 |
+
},
|
129 |
+
error:function()
|
130 |
+
{
|
131 |
+
$('.meta_mapping_box_con[data-loaded="0"]').html('<div class="wt_iew_import_step_loader">'+wt_iew_basic_params.msgs.loading+'</div>');
|
132 |
+
}
|
133 |
+
});
|
134 |
+
},
|
135 |
+
console_formdata:function()
|
136 |
+
{
|
137 |
+
console.log(this.form_data);
|
138 |
+
},
|
139 |
+
refresh_step:function(no_overlay)
|
140 |
+
{
|
141 |
+
/* if popover is opened */
|
142 |
+
wt_iew_popover.closePop();
|
143 |
+
|
144 |
+
if(!no_overlay){
|
145 |
+
this.page_overlay=true;
|
146 |
+
}
|
147 |
+
this.reset_step_loaded_state([this.current_step]);
|
148 |
+
this.load_steps([this.current_step], this.current_step);
|
149 |
+
},
|
150 |
+
get_need_to_reload_steps:function()
|
151 |
+
{
|
152 |
+
var rest_steps=this.step_keys.slice(0);
|
153 |
+
/* remove first and second steps */
|
154 |
+
rest_steps.shift();
|
155 |
+
rest_steps.shift();
|
156 |
+
return rest_steps;
|
157 |
+
},
|
158 |
+
load_pending_steps:function(no_overlay, show_step)
|
159 |
+
{
|
160 |
+
if(!no_overlay){
|
161 |
+
this.page_overlay=true;
|
162 |
+
}
|
163 |
+
if(!show_step)
|
164 |
+
{
|
165 |
+
show_step=this.current_step;
|
166 |
+
}
|
167 |
+
this.load_steps(this.get_need_to_reload_steps(), show_step);
|
168 |
+
},
|
169 |
+
get_page_dom_object:function(step)
|
170 |
+
{
|
171 |
+
return $('.wt_iew_import_step_'+step);
|
172 |
+
},
|
173 |
+
remove_ajax_page_loader:function()
|
174 |
+
{
|
175 |
+
this.hide_import_info_box();
|
176 |
+
$('.wt_iew_overlayed_loader').hide();
|
177 |
+
$('.spinner').css({'visibility':'hidden'});
|
178 |
+
this.page_overlay=false;
|
179 |
+
},
|
180 |
+
set_ajax_page_loader:function(steps, msg_type)
|
181 |
+
{
|
182 |
+
if(this.page_overlay)
|
183 |
+
{
|
184 |
+
var h=parseInt($('.wt_iew_import_step_main').outerHeight());
|
185 |
+
var w=parseInt($('.wt_iew_import_step_main').outerWidth());
|
186 |
+
$('.wt_iew_overlayed_loader').show().css({'height':h,'width':w,'margin-top':'30px','margin-left':'30px'});
|
187 |
+
$('.spinner').css({'visibility':'visible'});
|
188 |
+
}else
|
189 |
+
{
|
190 |
+
var msg='';
|
191 |
+
if(msg_type=='loading')
|
192 |
+
{
|
193 |
+
msg=wt_iew_basic_params.msgs.loading;
|
194 |
+
}else if(msg_type=='error')
|
195 |
+
{
|
196 |
+
msg=wt_iew_basic_params.msgs.error;
|
197 |
+
}
|
198 |
+
$.each(steps, function(step_ind, step){
|
199 |
+
wt_iew_basic_import.get_page_dom_object(step).html('<div class="wt_iew_import_step_loader">'+msg+'</div>');
|
200 |
+
});
|
201 |
+
}
|
202 |
+
},
|
203 |
+
hide_import_info_box:function()
|
204 |
+
{
|
205 |
+
$('.wt_iew_loader_info_box').hide();
|
206 |
+
},
|
207 |
+
set_import_progress_info:function(msg)
|
208 |
+
{
|
209 |
+
$('.wt_iew_loader_info_box').show().html(msg);
|
210 |
+
},
|
211 |
+
nonstep_actions:function(action)
|
212 |
+
{
|
213 |
+
this.prepare_ajax_data(action, 'json');
|
214 |
+
if(action=='save_template' || action=='save_template_as' || action=='update_template')
|
215 |
+
{
|
216 |
+
$('.wt_iew_template_name_wrn').hide();
|
217 |
+
var pop_elm=$('.wt_iew_template_name');
|
218 |
+
var popup_label=pop_elm.attr('data-save-label');
|
219 |
+
if(action=='save_template_as')
|
220 |
+
{
|
221 |
+
var popup_label=pop_elm.attr('data-saveas-label');
|
222 |
+
}
|
223 |
+
pop_elm.find('.wt_iew_popup_hd_label, .wt_iew_template_create_btn').text(popup_label);
|
224 |
+
wt_iew_popup.showPopup(pop_elm);
|
225 |
+
$('[name="wt_iew_template_name_field"]').val(this.selected_template_name).focus();
|
226 |
+
|
227 |
+
$('.wt_iew_template_create_btn').unbind('click').click(function(){
|
228 |
+
var name=$.trim($('.wt_iew_template_name_field').val());
|
229 |
+
if(name=='')
|
230 |
+
{
|
231 |
+
$('.wt_iew_template_name_wrn').show();
|
232 |
+
$('.wt_iew_template_name_field').focus();
|
233 |
+
}else
|
234 |
+
{
|
235 |
+
$('.wt_iew_template_name_wrn').hide();
|
236 |
+
wt_iew_popup.hidePopup();
|
237 |
+
|
238 |
+
wt_iew_basic_import.prepare_form_data();
|
239 |
+
wt_iew_basic_import.ajax_data['template_name']=name;
|
240 |
+
wt_iew_basic_import.ajax_data['form_data']=wt_iew_basic_import.form_data;
|
241 |
+
wt_iew_basic_import.do_nonstep_action(action);
|
242 |
+
}
|
243 |
+
});
|
244 |
+
}else if(action=='validate_file' || action=='download')
|
245 |
+
{
|
246 |
+
this.prepare_form_data();
|
247 |
+
this.ajax_data['form_data']=this.form_data;
|
248 |
+
this.do_nonstep_action(action);
|
249 |
+
}else
|
250 |
+
{
|
251 |
+
/* custom action section for other modules */
|
252 |
+
this.prepare_form_data();
|
253 |
+
this.ajax_data['form_data']=this.form_data;
|
254 |
+
wt_iew_custom_action_basic(this.ajax_data, action, this.selected_template);
|
255 |
+
}
|
256 |
+
},
|
257 |
+
do_nonstep_action:function(action)
|
258 |
+
{
|
259 |
+
this.page_overlay=true;
|
260 |
+
this.set_ajax_page_loader();
|
261 |
+
|
262 |
+
if(action=='download')
|
263 |
+
{
|
264 |
+
wt_iew_basic_import.set_import_progress_info(wt_iew_import_basic_params.msgs.processing_file);
|
265 |
+
}
|
266 |
+
$.ajax({
|
267 |
+
type: 'POST',
|
268 |
+
url:wt_iew_basic_params.ajax_url,
|
269 |
+
data:this.ajax_data,
|
270 |
+
dataType:'json',
|
271 |
+
success:function(data)
|
272 |
+
{
|
273 |
+
wt_iew_basic_import.remove_ajax_page_loader();
|
274 |
+
if(wt_iew_basic_import.is_object(data) && data.hasOwnProperty('status'))
|
275 |
+
{
|
276 |
+
if(data.status==1)
|
277 |
+
{
|
278 |
+
if(action=='save_template' || action=='save_template_as' || action=='update_template')
|
279 |
+
{
|
280 |
+
wt_iew_basic_import.selected_template=data.id;
|
281 |
+
wt_iew_basic_import.selected_template_name=data.name;
|
282 |
+
wt_iew_notify_msg.success(data.msg);
|
283 |
+
//wt_iew_notify_msg.success(wt_iew_basic_params.msgs.success);
|
284 |
+
|
285 |
+
}else if(action=='import')
|
286 |
+
{
|
287 |
+
if(data.finished==1)
|
288 |
+
{
|
289 |
+
wt_iew_basic_import.temp_import_file='';
|
290 |
+
wt_iew_notify_msg.success(wt_iew_basic_params.msgs.success);
|
291 |
+
wt_iew_basic_import.set_import_progress_info(data.msg);
|
292 |
+
}
|
293 |
+
else
|
294 |
+
{
|
295 |
+
wt_iew_basic_import.set_import_progress_info(data.msg);
|
296 |
+
wt_iew_basic_import.ajax_data['offset']=data.new_offset;
|
297 |
+
wt_iew_basic_import.ajax_data['import_id']=data.import_id;
|
298 |
+
wt_iew_basic_import.ajax_data['total_records']=data.total_records;
|
299 |
+
wt_iew_basic_import.ajax_data['offset_count']=data.offset_count;
|
300 |
+
|
301 |
+
wt_iew_basic_import.ajax_data['total_success']=data.total_success;
|
302 |
+
wt_iew_basic_import.ajax_data['total_failed']=data.total_failed;
|
303 |
+
wt_iew_basic_import.do_nonstep_action(action);
|
304 |
+
}
|
305 |
+
}else if(action=='download')
|
306 |
+
{
|
307 |
+
wt_iew_basic_import.set_import_progress_info(data.msg);
|
308 |
+
wt_iew_basic_import.ajax_data['import_id']=data.import_id;
|
309 |
+
wt_iew_basic_import.ajax_data['total_records']=data.total_records;
|
310 |
+
if(data.finished==3)/* finished file processing */
|
311 |
+
{
|
312 |
+
wt_iew_basic_import.ajax_data['offset']=0;
|
313 |
+
wt_iew_basic_import.ajax_data['offset_count']=0;
|
314 |
+
wt_iew_basic_import.ajax_data['import_action']='import';
|
315 |
+
wt_iew_basic_import.ajax_data['temp_import_file']=data.temp_import_file;
|
316 |
+
wt_iew_basic_import.temp_import_file=data.temp_import_file;
|
317 |
+
wt_iew_basic_import.do_nonstep_action('import');
|
318 |
+
}else
|
319 |
+
{
|
320 |
+
wt_iew_basic_import.ajax_data['offset']=data.new_offset;
|
321 |
+
wt_iew_basic_import.ajax_data['import_action']='download';
|
322 |
+
wt_iew_basic_import.do_nonstep_action('download');
|
323 |
+
}
|
324 |
+
}
|
325 |
+
else if(action=='validate_file')
|
326 |
+
{
|
327 |
+
wt_iew_basic_import.is_valid_file=true;
|
328 |
+
|
329 |
+
/* set meta step status to not loaded */
|
330 |
+
wt_iew_basic_import.reset_meta_step_loaded_state();
|
331 |
+
|
332 |
+
wt_iew_basic_import.temp_import_file=data.file_name;
|
333 |
+
wt_iew_basic_import.set_validate_file_info();
|
334 |
+
if(wt_iew_basic_import.blocked_action!='') /* pending action exists */
|
335 |
+
{
|
336 |
+
if(wt_iew_basic_import.is_step(wt_iew_basic_import.blocked_action))
|
337 |
+
{
|
338 |
+
/* load all pending steps, and show the next step (Blocked action) */
|
339 |
+
wt_iew_basic_import.load_pending_steps(false, wt_iew_basic_import.blocked_action);
|
340 |
+
|
341 |
+
}else /* may be import(download) */
|
342 |
+
{
|
343 |
+
wt_iew_basic_import.nonstep_actions(wt_iew_basic_import.blocked_action);
|
344 |
+
}
|
345 |
+
|
346 |
+
/* clear the blocked action */
|
347 |
+
wt_iew_basic_import.blocked_action='';
|
348 |
+
}
|
349 |
+
}else
|
350 |
+
{
|
351 |
+
|
352 |
+
}
|
353 |
+
}else
|
354 |
+
{
|
355 |
+
if(data.msg!="")
|
356 |
+
{
|
357 |
+
wt_iew_notify_msg.error(data.msg);
|
358 |
+
}else
|
359 |
+
{
|
360 |
+
wt_iew_notify_msg.error(wt_iew_basic_params.msgs.error);
|
361 |
+
}
|
362 |
+
}
|
363 |
+
}else
|
364 |
+
{
|
365 |
+
wt_iew_basic_import.temp_import_file='';
|
366 |
+
wt_iew_notify_msg.error(wt_iew_basic_params.msgs.error);
|
367 |
+
}
|
368 |
+
},
|
369 |
+
error:function()
|
370 |
+
{
|
371 |
+
wt_iew_basic_import.temp_import_file='';
|
372 |
+
wt_iew_basic_import.remove_ajax_page_loader();
|
373 |
+
wt_iew_notify_msg.error(wt_iew_basic_params.msgs.error);
|
374 |
+
}
|
375 |
+
});
|
376 |
+
},
|
377 |
+
reg_button_actions:function()
|
378 |
+
{
|
379 |
+
$('.wt_iew_import_action_btn').unbind('click').click(function(e){
|
380 |
+
e.preventDefault();
|
381 |
+
|
382 |
+
wt_iew_basic_import.remove_ajax_page_loader(); /* remove any loader that are open */
|
383 |
+
|
384 |
+
var action=$(this).attr('data-action');
|
385 |
+
var action_type=$(this).attr('data-action-type');
|
386 |
+
var is_previous_step=wt_iew_basic_import.is_previous_step(action);
|
387 |
+
if(!wt_iew_importer_validate_basic(action, action_type, is_previous_step))
|
388 |
+
{
|
389 |
+
return false;
|
390 |
+
}
|
391 |
+
|
392 |
+
/* validation section */
|
393 |
+
if(!wt_iew_basic_import.form_validation(action))
|
394 |
+
{
|
395 |
+
return false;
|
396 |
+
}
|
397 |
+
|
398 |
+
/* if popover is opened */
|
399 |
+
wt_iew_popover.closePop();
|
400 |
+
|
401 |
+
/* this method will check current step is import method step and file is validated */
|
402 |
+
if(!wt_iew_basic_import.validate_file(action, action_type))
|
403 |
+
{
|
404 |
+
return false;
|
405 |
+
}
|
406 |
+
|
407 |
+
if(action_type=='step')
|
408 |
+
{
|
409 |
+
wt_iew_basic_import.change_step(action);
|
410 |
+
}else
|
411 |
+
{
|
412 |
+
wt_iew_basic_import.nonstep_actions(action);
|
413 |
+
}
|
414 |
+
});
|
415 |
+
},
|
416 |
+
get_file_from:function()
|
417 |
+
{
|
418 |
+
if(jQuery('select[name="wt_iew_file_from"]').length>0) /* select box */
|
419 |
+
{
|
420 |
+
var file_from=jQuery('[name="wt_iew_file_from"]').val();
|
421 |
+
}else
|
422 |
+
{
|
423 |
+
var file_from=jQuery('[name="wt_iew_file_from"]:checked').val();
|
424 |
+
}
|
425 |
+
return file_from;
|
426 |
+
},
|
427 |
+
set_validate_file_info:function()
|
428 |
+
{
|
429 |
+
var file_from=this.get_file_from();
|
430 |
+
|
431 |
+
if(file_from=='local')
|
432 |
+
{
|
433 |
+
this.local_import_file=$('[name="wt_iew_local_file"]').val();
|
434 |
+
|
435 |
+
}else if(file_from=='url')
|
436 |
+
{
|
437 |
+
this.url_import_file=$('[name="wt_iew_url_file"]').val();
|
438 |
+
|
439 |
+
}else
|
440 |
+
{
|
441 |
+
wt_iew_set_validate_file_info(file_from);
|
442 |
+
}
|
443 |
+
},
|
444 |
+
validate_file:function(action, action_type)
|
445 |
+
{
|
446 |
+
if(this.current_step=='method_import')
|
447 |
+
{
|
448 |
+
/* check any revalidation needed for input file */
|
449 |
+
var file_from=this.get_file_from();
|
450 |
+
if(file_from=='local')
|
451 |
+
{
|
452 |
+
if(this.local_import_file!=$('[name="wt_iew_local_file"]').val())
|
453 |
+
{
|
454 |
+
this.is_valid_file=false;
|
455 |
+
}else
|
456 |
+
{
|
457 |
+
this.is_valid_file=true;
|
458 |
+
}
|
459 |
+
}else if(file_from=='url')
|
460 |
+
{
|
461 |
+
if(this.url_import_file!=$('[name="wt_iew_url_file"]').val())
|
462 |
+
{
|
463 |
+
this.is_valid_file=false;
|
464 |
+
}else
|
465 |
+
{
|
466 |
+
this.is_valid_file=true;
|
467 |
+
}
|
468 |
+
}else
|
469 |
+
{
|
470 |
+
/* revalidation check of other remote adapters will done on form validation hook */
|
471 |
+
}
|
472 |
+
}
|
473 |
+
|
474 |
+
if(this.current_step=='method_import' && !this.is_valid_file) /* method import page, then check file validation is done. */
|
475 |
+
{
|
476 |
+
if(action_type=='step' && this.is_previous_step(action)) /* step action and previous step */
|
477 |
+
{
|
478 |
+
return true;
|
479 |
+
}
|
480 |
+
|
481 |
+
/* store the current action to a variable. After successful validation of the file the stopped action will resumed */
|
482 |
+
this.blocked_action=action;
|
483 |
+
|
484 |
+
this.set_import_progress_info(wt_iew_import_basic_params.msgs.validating_file);
|
485 |
+
this.nonstep_actions('validate_file'); /* download/upload the file and validate it. */
|
486 |
+
return false;
|
487 |
+
}else
|
488 |
+
{
|
489 |
+
return true;
|
490 |
+
}
|
491 |
+
},
|
492 |
+
form_validation:function(step_to_go)
|
493 |
+
{
|
494 |
+
if(this.current_step=='post_type')
|
495 |
+
{
|
496 |
+
if(this.to_import=='')
|
497 |
+
{
|
498 |
+
$('.wt_iew_post_type_wrn').show();
|
499 |
+
return false;
|
500 |
+
}
|
501 |
+
}else if(this.current_step=='method_import') /* method import page */
|
502 |
+
{
|
503 |
+
if(this.import_method=='template' && this.selected_template==0 && !this.is_previous_step(step_to_go))
|
504 |
+
{
|
505 |
+
wt_iew_notify_msg.error(wt_iew_import_basic_params.msgs.select_an_import_template);
|
506 |
+
return false;
|
507 |
+
}
|
508 |
+
if((this.import_method=='new' || this.import_method=='quick') && !this.is_previous_step(step_to_go))
|
509 |
+
{
|
510 |
+
if(this.file_from=='')
|
511 |
+
{
|
512 |
+
wt_iew_notify_msg.error(wt_iew_import_basic_params.msgs.choose_import_from);
|
513 |
+
return false;
|
514 |
+
}else
|
515 |
+
{
|
516 |
+
if(this.file_from=='local' && $.trim($('[name="wt_iew_local_file"]').val())=='')
|
517 |
+
{
|
518 |
+
wt_iew_notify_msg.error(wt_iew_import_basic_params.msgs.choose_a_file);
|
519 |
+
return false;
|
520 |
+
}
|
521 |
+
else if(this.file_from=='url' && $.trim($('[name="wt_iew_url_file"]').val())=='')
|
522 |
+
{
|
523 |
+
wt_iew_notify_msg.error(wt_iew_import_basic_params.msgs.choose_a_file);
|
524 |
+
return false;
|
525 |
+
}
|
526 |
+
}
|
527 |
+
}
|
528 |
+
}else if(this.current_step=='advanced')
|
529 |
+
{
|
530 |
+
|
531 |
+
}
|
532 |
+
return true;
|
533 |
+
},
|
534 |
+
change_step:function(step_to_go)
|
535 |
+
{
|
536 |
+
/* setting fromdata */
|
537 |
+
this.prepare_form_data();
|
538 |
+
|
539 |
+
/* step changing section */
|
540 |
+
this.show_step_page(step_to_go, true);
|
541 |
+
},
|
542 |
+
reset_form_data:function()
|
543 |
+
{
|
544 |
+
this.form_data={};
|
545 |
+
this.selected_template=0;
|
546 |
+
this.selected_template_name='';
|
547 |
+
this.import_method='';
|
548 |
+
this.is_valid_file=false;
|
549 |
+
this.local_import_file='';
|
550 |
+
this.url_import_file='';
|
551 |
+
wt_iew_importer_reset_form_data_basic();
|
552 |
+
|
553 |
+
/* reset loaded state */
|
554 |
+
this.reset_step_loaded_state(this.get_need_to_reload_steps());
|
555 |
+
},
|
556 |
+
reset_step_loaded_state:function(steps)
|
557 |
+
{
|
558 |
+
this.set_step_loading_status(steps, 'not_loaded');
|
559 |
+
},
|
560 |
+
reset_meta_step_loaded_state:function()
|
561 |
+
{
|
562 |
+
var rest_steps=this.get_need_to_reload_steps();
|
563 |
+
var meta_step=rest_steps.shift();
|
564 |
+
this.reset_step_loaded_state([meta_step]);
|
565 |
+
},
|
566 |
+
prepare_form_data:function()
|
567 |
+
{
|
568 |
+
if(this.current_step=='post_type')
|
569 |
+
{
|
570 |
+
this.form_data['post_type_form_data']=JSON.stringify({'item_type':wt_iew_basic_import.to_import});
|
571 |
+
}
|
572 |
+
else if(this.current_step=='mapping')
|
573 |
+
{
|
574 |
+
|
575 |
+
/**
|
576 |
+
* Default mapping fields
|
577 |
+
*/
|
578 |
+
var mapping_form_data={};
|
579 |
+
var mapping_fields={};
|
580 |
+
var mapping_selected_fields={}; /* this value is only for backend processing */
|
581 |
+
|
582 |
+
$('.wt-iew-importer-default-mapping-tb tbody tr').each(function(){
|
583 |
+
|
584 |
+
var columns_key=$(this).find('.columns_key').val();
|
585 |
+
var columns_val=$(this).find('.columns_val').val();
|
586 |
+
|
587 |
+
var enabled=($(this).find('.columns_key').is(':checked') ? 1 : 0);
|
588 |
+
var type=$(this).find('.columns_val').attr('data-type');
|
589 |
+
mapping_fields[columns_key]=[columns_val, enabled, type];
|
590 |
+
if(enabled==1)
|
591 |
+
{
|
592 |
+
mapping_selected_fields[columns_key]=columns_val;
|
593 |
+
}
|
594 |
+
|
595 |
+
});
|
596 |
+
|
597 |
+
mapping_form_data={'mapping_fields':mapping_fields, 'mapping_selected_fields':mapping_selected_fields};
|
598 |
+
this.form_data['mapping_form_data']=JSON.stringify(mapping_form_data);
|
599 |
+
|
600 |
+
|
601 |
+
|
602 |
+
/**
|
603 |
+
* meta mapping fields
|
604 |
+
*/
|
605 |
+
var meta_step_form_data={};
|
606 |
+
var mapping_fields={};
|
607 |
+
var mapping_selected_fields={}; /* this value is only for backend processing */
|
608 |
+
|
609 |
+
$('.wt-iew-importer-meta-mapping-tb').each(function(){
|
610 |
+
var mapping_key=$(this).attr('data-field-type');
|
611 |
+
mapping_fields[mapping_key]={};
|
612 |
+
mapping_selected_fields[mapping_key]={};
|
613 |
+
|
614 |
+
$(this).find('tbody tr').each(function(){
|
615 |
+
if($(this).find('.columns_key').length>0 && $(this).find('.columns_val').length>0)
|
616 |
+
{
|
617 |
+
var columns_key=$(this).find('.columns_key').val();
|
618 |
+
var columns_val=$(this).find('.columns_val').val();
|
619 |
+
|
620 |
+
var enabled=($(this).find('.columns_key').is(':checked') ? 1 : 0);
|
621 |
+
var type=$(this).find('.columns_val').attr('data-type');
|
622 |
+
mapping_fields[mapping_key][columns_key]=[columns_val, enabled, type];
|
623 |
+
if(enabled==1)
|
624 |
+
{
|
625 |
+
mapping_selected_fields[mapping_key][columns_key]=columns_val;
|
626 |
+
}
|
627 |
+
}
|
628 |
+
});
|
629 |
+
});
|
630 |
+
|
631 |
+
meta_step_form_data={'mapping_fields':mapping_fields, 'mapping_selected_fields':mapping_selected_fields};
|
632 |
+
this.form_data['meta_step_form_data']=JSON.stringify(meta_step_form_data);
|
633 |
+
|
634 |
+
}
|
635 |
+
else
|
636 |
+
{
|
637 |
+
var current_form_data={};
|
638 |
+
if(this.current_step=='method_import')
|
639 |
+
{
|
640 |
+
current_form_data={'method_import' : wt_iew_basic_import.import_method, 'selected_template':this.selected_template};
|
641 |
+
}
|
642 |
+
if($('.wt_iew_import_'+this.current_step+'_form').length>0) /* may be user hit the back button */
|
643 |
+
{
|
644 |
+
var form_data=$('.wt_iew_import_'+this.current_step+'_form').serializeArray();
|
645 |
+
$.each(form_data, function(){
|
646 |
+
|
647 |
+
if(current_form_data[this.name])
|
648 |
+
{
|
649 |
+
if(!current_form_data[this.name].push)
|
650 |
+
{
|
651 |
+
current_form_data[this.name] = [current_form_data[this.name]];
|
652 |
+
}
|
653 |
+
current_form_data[this.name].push(this.value || '');
|
654 |
+
}else
|
655 |
+
{
|
656 |
+
current_form_data[this.name] = this.value || '';
|
657 |
+
}
|
658 |
+
|
659 |
+
});
|
660 |
+
|
661 |
+
this.form_data[this.current_step+'_form_data']=JSON.stringify(current_form_data);
|
662 |
+
}
|
663 |
+
}
|
664 |
+
|
665 |
+
/* we are resetting formdata on second step. If user not going to first step then post type formdata will be empty. */
|
666 |
+
if(this.current_step!='post_type')
|
667 |
+
{
|
668 |
+
this.form_data['post_type_form_data']=JSON.stringify({'item_type':wt_iew_basic_import.to_import});
|
669 |
+
}
|
670 |
+
|
671 |
+
},
|
672 |
+
is_multi_select:function(name)
|
673 |
+
{
|
674 |
+
var elm=$('[name="'+name+'"]');
|
675 |
+
if(elm.prop("tagName").toLowerCase()=='select' && this.has_attr(elm,'multiple'))
|
676 |
+
{
|
677 |
+
return true;
|
678 |
+
}else
|
679 |
+
{
|
680 |
+
return false;
|
681 |
+
}
|
682 |
+
},
|
683 |
+
has_attr:function(elm,attr_name)
|
684 |
+
{
|
685 |
+
var attr = elm.attr(attr_name);
|
686 |
+
if(typeof attr!==typeof undefined && attr!==false)
|
687 |
+
{
|
688 |
+
return true;
|
689 |
+
}else
|
690 |
+
{
|
691 |
+
return false;
|
692 |
+
}
|
693 |
+
},
|
694 |
+
is_step:function(step_key)
|
695 |
+
{
|
696 |
+
return wt_iew_import_basic_params.steps.hasOwnProperty(step_key) ? true : false;
|
697 |
+
},
|
698 |
+
is_previous_step:function(step_key)
|
699 |
+
{
|
700 |
+
if(this.is_step(step_key))
|
701 |
+
{
|
702 |
+
if(this.step_keys.indexOf(step_key)<this.step_keys.indexOf(this.current_step))
|
703 |
+
{
|
704 |
+
return true;
|
705 |
+
}
|
706 |
+
}
|
707 |
+
return false;
|
708 |
+
},
|
709 |
+
is_step_loaded:function(step)
|
710 |
+
{
|
711 |
+
if(this.get_page_dom_object(step).length==0){ return true; } /* block infinite loop, if element is not available */
|
712 |
+
return (this.get_page_dom_object(step).attr('data-loaded')==this.loaded_status_arr['loaded']);
|
713 |
+
},
|
714 |
+
set_step_loading_status:function(steps, status)
|
715 |
+
{
|
716 |
+
$.each(steps, function(step_ind, step){
|
717 |
+
wt_iew_basic_import.get_page_dom_object(step).attr('data-loaded', wt_iew_basic_import.loaded_status_arr[status]);
|
718 |
+
});
|
719 |
+
},
|
720 |
+
show_step_page:function(step, force_check_loaded)
|
721 |
+
{
|
722 |
+
$('.wt_iew_import_step').hide();
|
723 |
+
this.get_page_dom_object(step).show();
|
724 |
+
this.current_step=step;
|
725 |
+
if(force_check_loaded)
|
726 |
+
{
|
727 |
+
if(this.is_step_loaded(step))
|
728 |
+
{
|
729 |
+
this.current_step_actions();
|
730 |
+
}else
|
731 |
+
{
|
732 |
+
this.refresh_step(true);
|
733 |
+
}
|
734 |
+
}else
|
735 |
+
{
|
736 |
+
this.current_step_actions();
|
737 |
+
}
|
738 |
+
wt_iew_form_toggler.runToggler();
|
739 |
+
},
|
740 |
+
current_step_actions:function() /* current page actions after page is visible */
|
741 |
+
{
|
742 |
+
if(this.current_step=='method_import')
|
743 |
+
{
|
744 |
+
wt_iew_file_attacher.Set();
|
745 |
+
wt_iew_form_toggler.runToggler();
|
746 |
+
}
|
747 |
+
else if(this.current_step=='advanced')
|
748 |
+
{
|
749 |
+
wt_iew_form_toggler.runToggler();
|
750 |
+
wt_field_group.Set();
|
751 |
+
}
|
752 |
+
else if(this.current_step=='mapping')
|
753 |
+
{
|
754 |
+
wt_iew_popover.Set();
|
755 |
+
|
756 |
+
if($('.meta_mapping_box_con').length>0)
|
757 |
+
{
|
758 |
+
if($('.meta_mapping_box_con[data-loaded="0"]').length>0)
|
759 |
+
{
|
760 |
+
this.load_meta_mapping_fields();
|
761 |
+
}
|
762 |
+
}
|
763 |
+
}
|
764 |
+
},
|
765 |
+
show_post_type_name:function()
|
766 |
+
{
|
767 |
+
if(this.to_import!="" && this.to_import_title=='')
|
768 |
+
{
|
769 |
+
$('[name="wt_iew_import_post_type"]').val(this.to_import);
|
770 |
+
this.to_import_title=$('[name="wt_iew_import_post_type"] option:selected').text();
|
771 |
+
}
|
772 |
+
$('.wt_iew_step_head_post_type_name').html(this.to_import_title);
|
773 |
+
if(this.to_import_title.includes('User'))
|
774 |
+
$('#user-required-field-message').show();
|
775 |
+
},
|
776 |
+
page_actions:function(step)
|
777 |
+
{
|
778 |
+
if(step=='post_type') /* post type page */
|
779 |
+
{
|
780 |
+
$('[name="wt_iew_import_post_type"]').unbind('change').change(function(){
|
781 |
+
wt_iew_basic_import.to_import=$(this).val();
|
782 |
+
wt_iew_basic_import.to_import_title='';
|
783 |
+
wt_iew_basic_import.reset_form_data();
|
784 |
+
$('.wt_iew_post_type_name').html('');
|
785 |
+
if(wt_iew_basic_import.to_import=='')
|
786 |
+
{
|
787 |
+
$('.wt_iew_post_type_wrn').show();
|
788 |
+
}else
|
789 |
+
{
|
790 |
+
$('.wt_iew_post_type_wrn').hide();
|
791 |
+
var post_type_name=$('[name="wt_iew_import_post_type"] option:selected').text();
|
792 |
+
/* $('.wt_iew_post_type_name').html(': '+post_type_name); */
|
793 |
+
wt_iew_basic_import.to_import_title=post_type_name;
|
794 |
+
|
795 |
+
/* load second step */
|
796 |
+
wt_iew_basic_import.set_step_loading_status([wt_iew_basic_import.step_keys[1]], 'not_loaded'); /* resetting status for force refresh */
|
797 |
+
wt_iew_basic_import.load_steps([wt_iew_basic_import.step_keys[1]]);
|
798 |
+
}
|
799 |
+
});
|
800 |
+
}
|
801 |
+
else if(step=='method_import') /* method import page */
|
802 |
+
{
|
803 |
+
this.import_method=$('[name="wt_iew_import_method_import"]:checked').val();
|
804 |
+
this.toggle_import_method_options();
|
805 |
+
|
806 |
+
$('[name="wt_iew_import_method_import"]').unbind('click').click(function(){
|
807 |
+
var vl=$(this).val();
|
808 |
+
if(wt_iew_basic_import.import_method==vl)
|
809 |
+
{
|
810 |
+
return false;
|
811 |
+
}
|
812 |
+
wt_iew_basic_import.reset_form_data();
|
813 |
+
wt_iew_basic_import.import_method=vl;
|
814 |
+
wt_iew_basic_import.refresh_step();
|
815 |
+
});
|
816 |
+
|
817 |
+
$('.wt-iew-import-template-sele').unbind('change').change(function(){
|
818 |
+
wt_iew_basic_import.selected_template=$(this).val();
|
819 |
+
wt_iew_basic_import.is_valid_file=false;
|
820 |
+
if(wt_iew_basic_import.selected_template==0)
|
821 |
+
{
|
822 |
+
wt_iew_notify_msg.error(wt_iew_import_basic_params.msgs.select_an_import_template);
|
823 |
+
}else
|
824 |
+
{
|
825 |
+
/* reset step loaded sataus */
|
826 |
+
wt_iew_basic_import.reset_step_loaded_state(wt_iew_basic_import.get_need_to_reload_steps());
|
827 |
+
|
828 |
+
wt_iew_basic_import.selected_template_name=$.trim($('.wt-iew-import-template-sele option:selected').text());
|
829 |
+
wt_iew_basic_import.refresh_step();
|
830 |
+
}
|
831 |
+
});
|
832 |
+
|
833 |
+
|
834 |
+
/* callback for external adapters */
|
835 |
+
if($('select[name="wt_iew_file_from"]').length>0) /* multiple adapter exists so select box */
|
836 |
+
{
|
837 |
+
this.file_from=$('[name="wt_iew_file_from"]').val();
|
838 |
+
$('[name="wt_iew_file_from"]').unbind('change').on('change',function(){
|
839 |
+
wt_iew_basic_import.file_from=$(this).val();
|
840 |
+
wt_iew_basic_import.is_valid_file=false;
|
841 |
+
wt_iew_set_file_from_fields(wt_iew_basic_import.file_from);
|
842 |
+
});
|
843 |
+
}else /* radio button */
|
844 |
+
{
|
845 |
+
this.file_from=$('[name="wt_iew_file_from"]:checked').val();
|
846 |
+
$('[name="wt_iew_file_from"]').on('click',function(){
|
847 |
+
wt_iew_basic_import.file_from=$('[name="wt_iew_file_from"]:checked').val();
|
848 |
+
wt_iew_basic_import.is_valid_file=false;
|
849 |
+
wt_iew_set_file_from_fields(wt_iew_basic_import.file_from);
|
850 |
+
});
|
851 |
+
}
|
852 |
+
wt_iew_set_file_from_fields(wt_iew_basic_import.file_from);
|
853 |
+
|
854 |
+
/* CSV delimiter form toggler. Custom and preset delimiter */
|
855 |
+
wt_iew_custom_and_preset.delimiter_toggler();
|
856 |
+
|
857 |
+
/* Input date format form toggler. Custom and preset date format */
|
858 |
+
wt_iew_custom_and_preset.date_format_toggler();
|
859 |
+
|
860 |
+
wt_iew_dropzone.init('wt_iew_local_file_dropzone');
|
861 |
+
}
|
862 |
+
else if(step=='mapping') /* mapping page */
|
863 |
+
{
|
864 |
+
this.enable_sortable();
|
865 |
+
this.mapping_box_accordian();
|
866 |
+
this.reg_mapping_field_bulk_action();
|
867 |
+
wt_iew_popover.Set();
|
868 |
+
}
|
869 |
+
else if(step=='advanced')
|
870 |
+
{
|
871 |
+
|
872 |
+
}
|
873 |
+
|
874 |
+
/* common events */
|
875 |
+
if($('.wt_iew_datepicker').length>0)
|
876 |
+
{
|
877 |
+
$('.wt_iew_datepicker').datepicker();
|
878 |
+
}
|
879 |
+
wt_field_group.Set();
|
880 |
+
wt_iew_form_toggler.Set();
|
881 |
+
wt_iew_conditional_help_text.Set(this.get_page_dom_object(step));
|
882 |
+
},
|
883 |
+
enable_sortable:function()
|
884 |
+
{
|
885 |
+
$('.meta_mapping_box_con[data-sortable="0"]').each(function(){
|
886 |
+
var tb=$(this).find(".wt-iew-mapping-tb tbody");
|
887 |
+
if(tb.length>0)
|
888 |
+
{
|
889 |
+
tb.sortable({
|
890 |
+
handle: ".wt_iew_sort_handle",
|
891 |
+
placeholder: "wt-iew-sortable-placeholder",
|
892 |
+
forcePlaceholderSize: true,
|
893 |
+
revert:true
|
894 |
+
});
|
895 |
+
$(this).attr('data-sortable', 1);
|
896 |
+
}
|
897 |
+
});
|
898 |
+
},
|
899 |
+
toggle_import_method_options:function()
|
900 |
+
{
|
901 |
+
$('.wt-iew-import-method-options').hide();
|
902 |
+
$('.wt-iew-import-method-options-'+this.import_method).show();
|
903 |
+
},
|
904 |
+
mapping_box_accordian:function()
|
905 |
+
{
|
906 |
+
$('.meta_mapping_box_hd').unbind('click').click(function()
|
907 |
+
{
|
908 |
+
/* if popover is opened */
|
909 |
+
wt_iew_popover.closePop();
|
910 |
+
|
911 |
+
var c_dv=$(this).parents('.meta_mapping_box').find('.meta_mapping_box_con');
|
912 |
+
if(c_dv.is(':visible'))
|
913 |
+
{
|
914 |
+
c_dv.hide();
|
915 |
+
$(this).find('.dashicons').removeClass('dashicons-arrow-down').addClass('dashicons-arrow-right');
|
916 |
+
}else
|
917 |
+
{
|
918 |
+
c_dv.show();
|
919 |
+
c_dv.find(".wt-iew-mapping-tb tbody tr td").each(function(){
|
920 |
+
$(this).css({'width':$(this).width()});
|
921 |
+
});
|
922 |
+
$(this).find('.dashicons').removeClass('dashicons-arrow-right').addClass('dashicons-arrow-down');
|
923 |
+
}
|
924 |
+
});
|
925 |
+
},
|
926 |
+
mapping_fields_selected_count:function(tb_elm)
|
927 |
+
{
|
928 |
+
tb_elm.parents('.meta_mapping_box').find('.meta_mapping_box_selected_count_box_num').text(tb_elm.find('.wt_iew_mapping_checkbox_sub:checked').length);
|
929 |
+
},
|
930 |
+
reg_mapping_field_bulk_action:function()
|
931 |
+
{
|
932 |
+
$('.wt_iew_mapping_checkbox_main').each(function()
|
933 |
+
{
|
934 |
+
var tb=$(this).parents('.wt-iew-mapping-tb');
|
935 |
+
if(tb.find('.wt_iew_mapping_checkbox_sub:checked').length==tb.find('.wt_iew_mapping_checkbox_sub').length)
|
936 |
+
{
|
937 |
+
tb.find('.wt_iew_mapping_checkbox_main').prop('checked',true);
|
938 |
+
}else
|
939 |
+
{
|
940 |
+
tb.find('.wt_iew_mapping_checkbox_main').prop('checked',false);
|
941 |
+
}
|
942 |
+
wt_iew_basic_import.mapping_fields_selected_count(tb);
|
943 |
+
});
|
944 |
+
|
945 |
+
$('.wt_iew_mapping_checkbox_main').unbind('click').click(function()
|
946 |
+
{
|
947 |
+
var tb=$(this).parents('.wt-iew-mapping-tb');
|
948 |
+
if($(this).is(':checked'))
|
949 |
+
{
|
950 |
+
tb.find('.wt_iew_mapping_checkbox_sub').prop('checked',true);
|
951 |
+
}else
|
952 |
+
{
|
953 |
+
tb.find('.wt_iew_mapping_checkbox_sub').prop('checked',false);
|
954 |
+
}
|
955 |
+
wt_iew_basic_import.mapping_fields_selected_count(tb);
|
956 |
+
});
|
957 |
+
$('.wt_iew_mapping_checkbox_sub').unbind('click').click(function()
|
958 |
+
{
|
959 |
+
var tb=$(this).parents('.wt-iew-mapping-tb');
|
960 |
+
if($(this).is(':checked') && tb.find('.wt_iew_mapping_checkbox_sub:checked').length==tb.find('.wt_iew_mapping_checkbox_sub').length)
|
961 |
+
{
|
962 |
+
tb.find('.wt_iew_mapping_checkbox_main').prop('checked',true);
|
963 |
+
}else
|
964 |
+
{
|
965 |
+
tb.find('.wt_iew_mapping_checkbox_main').prop('checked',false);
|
966 |
+
}
|
967 |
+
wt_iew_basic_import.mapping_fields_selected_count(tb);
|
968 |
+
});
|
969 |
+
},
|
970 |
+
set_step_page:function(data)
|
971 |
+
{
|
972 |
+
page_html=data.page_html;
|
973 |
+
$.each(page_html, function(step_id, page_content){
|
974 |
+
wt_iew_basic_import.get_page_dom_object(step_id).html(page_content);
|
975 |
+
wt_iew_basic_import.page_actions(step_id);
|
976 |
+
|
977 |
+
if(step_id=='method_import' && (wt_iew_basic_import.selected_template>0 || wt_iew_basic_import.on_rerun))
|
978 |
+
{
|
979 |
+
wt_iew_basic_import.form_data=data.template_data;
|
980 |
+
|
981 |
+
if(wt_iew_basic_import.on_rerun)
|
982 |
+
{
|
983 |
+
if($('.wt-iew-import-template-sele').val()==0)
|
984 |
+
{
|
985 |
+
wt_iew_basic_import.selected_template=0;
|
986 |
+
wt_iew_basic_import.selected_template_name='';
|
987 |
+
}else
|
988 |
+
{
|
989 |
+
wt_iew_basic_import.selected_template=$('.wt-iew-import-template-sele').val();
|
990 |
+
wt_iew_basic_import.selected_template_name=$.trim($('.wt-iew-import-template-sele option:selected').text());
|
991 |
+
}
|
992 |
+
}
|
993 |
+
}
|
994 |
+
wt_iew_basic_import.show_post_type_name();
|
995 |
+
});
|
996 |
+
this.reg_button_actions();
|
997 |
+
},
|
998 |
+
prepare_ajax_data:function(action, data_type)
|
999 |
+
{
|
1000 |
+
this.ajax_data = {
|
1001 |
+
'_wpnonce': wt_iew_basic_params.nonces.main,
|
1002 |
+
'action': "iew_import_ajax_basic",
|
1003 |
+
'import_action': action,
|
1004 |
+
'selected_template': this.selected_template,
|
1005 |
+
'to_import': this.to_import,
|
1006 |
+
'data_type': data_type,
|
1007 |
+
'import_method': this.import_method,
|
1008 |
+
'temp_import_file': this.temp_import_file,
|
1009 |
+
};
|
1010 |
+
|
1011 |
+
if($('[name="wt_iew_delimiter"]').length>0){
|
1012 |
+
this.import_delimiter = $('[name="wt_iew_delimiter"]').val();
|
1013 |
+
this.ajax_data['delimiter'] = this.import_delimiter;
|
1014 |
+
}
|
1015 |
+
|
1016 |
+
},
|
1017 |
+
mapping_field_editor:function()
|
1018 |
+
{
|
1019 |
+
mapping_field_editor.Set();
|
1020 |
+
},
|
1021 |
+
mapping_field_editor_validate_column_val:function(vl)
|
1022 |
+
{
|
1023 |
+
return mapping_field_editor.validate_column_val(vl);
|
1024 |
+
},
|
1025 |
+
mapping_field_editor_output_preview:function()
|
1026 |
+
{
|
1027 |
+
mapping_field_editor.output_preview();
|
1028 |
+
},
|
1029 |
+
is_object:function(obj)
|
1030 |
+
{
|
1031 |
+
return obj !== undefined && obj !== null && obj.constructor == Object;
|
1032 |
+
}
|
1033 |
+
}
|
1034 |
+
|
1035 |
+
var mapping_field_editor=
|
1036 |
+
{
|
1037 |
+
text_area_pos:null,
|
1038 |
+
popover:null,
|
1039 |
+
Set:function()
|
1040 |
+
{
|
1041 |
+
this.popover=$('.wt_iew_popover-content');
|
1042 |
+
this.add_fields();
|
1043 |
+
|
1044 |
+
this.popover.find('.wt_iew_mapping_field_editor_expression').unbind('keyup').on('keyup', function(){
|
1045 |
+
mapping_field_editor.text_area_pos=$(this).getCursorPosition();
|
1046 |
+
mapping_field_editor.output_preview();
|
1047 |
+
});
|
1048 |
+
|
1049 |
+
this.search_column();
|
1050 |
+
},
|
1051 |
+
validate_columns:function()
|
1052 |
+
{
|
1053 |
+
$('.meta_mapping_box_con[data-field-validated="0"]').each(function(){
|
1054 |
+
var tb=$(this).find('.wt-iew-mapping-tb');
|
1055 |
+
if($(this).find('.wt-iew-mapping-tb').length>0)
|
1056 |
+
{
|
1057 |
+
$(this).attr({'data-field-validated':1});
|
1058 |
+
tb.find('.columns_val').each(function(){
|
1059 |
+
var vl=$.trim($(this).val());
|
1060 |
+
if(vl!="")
|
1061 |
+
{
|
1062 |
+
var html_vl=mapping_field_editor.validate_column_val(vl);
|
1063 |
+
$(this).siblings('[data-wt_iew_popover="1"]').html(html_vl);
|
1064 |
+
}
|
1065 |
+
});
|
1066 |
+
}
|
1067 |
+
});
|
1068 |
+
},
|
1069 |
+
validate_column_val:function(str)
|
1070 |
+
{
|
1071 |
+
const regex = /\{([^}]+)\}/g;
|
1072 |
+
let m;
|
1073 |
+
var out=str;
|
1074 |
+
while ((m = regex.exec(str)) !== null)
|
1075 |
+
{
|
1076 |
+
/* This is necessary to avoid infinite loops with zero-width matches */
|
1077 |
+
if (m.index === regex.lastIndex) {
|
1078 |
+
regex.lastIndex++;
|
1079 |
+
}
|
1080 |
+
/* The result can be accessed through the `m`-variable. */
|
1081 |
+
m.forEach((match, groupIndex) => {
|
1082 |
+
|
1083 |
+
/* check date format matching */
|
1084 |
+
var match_arr=match.split('@');
|
1085 |
+
if(match_arr.length==2)/* date format matched */
|
1086 |
+
{
|
1087 |
+
match=match_arr[0];
|
1088 |
+
}
|
1089 |
+
|
1090 |
+
if(!wt_iew_file_head_default.hasOwnProperty(match) && !wt_iew_file_head_meta.hasOwnProperty(match))
|
1091 |
+
{
|
1092 |
+
out=out.replace('{'+match+'}', '<span class="wt_iew_invalid_mapping_field">{'+match+'}</span>');
|
1093 |
+
}
|
1094 |
+
});
|
1095 |
+
}
|
1096 |
+
return out;
|
1097 |
+
},
|
1098 |
+
add_fields:function()
|
1099 |
+
{
|
1100 |
+
this.popover.find('.wt_iew_mapping_field_selector li').unbind('click').click(function(){
|
1101 |
+
var vl=' {'+$(this).attr('data-val')+'} ';
|
1102 |
+
var exp_vl=mapping_field_editor.popover.find('.wt_iew_mapping_field_editor_expression').val();
|
1103 |
+
if(mapping_field_editor.text_area_pos!==null)
|
1104 |
+
{
|
1105 |
+
var new_vl=exp_vl.substr(0, mapping_field_editor.text_area_pos)+vl+exp_vl.substr(mapping_field_editor.text_area_pos);
|
1106 |
+
}else
|
1107 |
+
{
|
1108 |
+
var new_vl=exp_vl+vl;
|
1109 |
+
}
|
1110 |
+
mapping_field_editor.popover.find('.wt_iew_mapping_field_editor_expression').val(new_vl);
|
1111 |
+
mapping_field_editor.output_preview();
|
1112 |
+
})
|
1113 |
+
},
|
1114 |
+
search_column:function()
|
1115 |
+
{
|
1116 |
+
/* my template search */
|
1117 |
+
this.popover.find('.wt_iew_mapping_field_editor_column_search').unbind('keyup').on('keyup',function(){
|
1118 |
+
var vl=$.trim($(this).val());
|
1119 |
+
if(vl!="")
|
1120 |
+
{
|
1121 |
+
vl=vl.toLowerCase();
|
1122 |
+
mapping_field_editor.popover.find('.wt_iew_mapping_field_selector li').hide();
|
1123 |
+
var kk=mapping_field_editor.popover.find('.wt_iew_mapping_field_selector li').filter(function(){
|
1124 |
+
var name=$(this).attr('data-val');
|
1125 |
+
name=name.toLowerCase();
|
1126 |
+
if(name.search(vl)!=-1)
|
1127 |
+
{
|
1128 |
+
return true;
|
1129 |
+
}else
|
1130 |
+
{
|
1131 |
+
return false;
|
1132 |
+
}
|
1133 |
+
});
|
1134 |
+
kk.show();
|
1135 |
+
if(mapping_field_editor.popover.find('.wt_iew_mapping_field_selector li:visible').length==0)
|
1136 |
+
{
|
1137 |
+
mapping_field_editor.popover.find('.wt_iew_mapping_field_selector_no_column').show();
|
1138 |
+
}else
|
1139 |
+
{
|
1140 |
+
mapping_field_editor.popover.find('.wt_iew_mapping_field_selector_no_column').hide();
|
1141 |
+
}
|
1142 |
+
}else
|
1143 |
+
{
|
1144 |
+
mapping_field_editor.popover.find('.wt_iew_mapping_field_selector li').show();
|
1145 |
+
}
|
1146 |
+
});
|
1147 |
+
mapping_field_editor.popover.find('.wt_iew_mapping_field_selector_no_column').hide();
|
1148 |
+
},
|
1149 |
+
output_preview:function()
|
1150 |
+
{
|
1151 |
+
this.popover.find('.wt_iew_mapping_field_editor_er').html('');
|
1152 |
+
const str = this.popover.find('.wt_iew_mapping_field_editor_expression').val();
|
1153 |
+
var out='';
|
1154 |
+
out=this.add_sample_data(str);
|
1155 |
+
out=this.do_arithmetic(out);
|
1156 |
+
this.popover.find('.wt_iew_mapping_field_editor_sample').html(out);
|
1157 |
+
},
|
1158 |
+
add_sample_data:function(str)
|
1159 |
+
{
|
1160 |
+
const regex = /\{([^}]+)\}/g;
|
1161 |
+
|
1162 |
+
let m;
|
1163 |
+
var out=str;
|
1164 |
+
|
1165 |
+
while ((m = regex.exec(str)) !== null) {
|
1166 |
+
/* This is necessary to avoid infinite loops with zero-width matches */
|
1167 |
+
if (m.index === regex.lastIndex) {
|
1168 |
+
regex.lastIndex++;
|
1169 |
+
}
|
1170 |
+
/* The result can be accessed through the `m`-variable. */
|
1171 |
+
m.forEach((match, groupIndex) => {
|
1172 |
+
|
1173 |
+
/* check date format matching */
|
1174 |
+
var match_arr=match.split('@');
|
1175 |
+
if(match_arr.length==2)/* date format matched */
|
1176 |
+
{
|
1177 |
+
match=match_arr[0];
|
1178 |
+
}
|
1179 |
+
|
1180 |
+
var sample_vl=' '; /* do not set default value as empty string */
|
1181 |
+
if(wt_iew_file_head_default.hasOwnProperty(match))
|
1182 |
+
{
|
1183 |
+
var sample_vl=$.trim(wt_iew_file_head_default[match]);
|
1184 |
+
}
|
1185 |
+
else if(wt_iew_file_head_meta.hasOwnProperty(match))
|
1186 |
+
{
|
1187 |
+
var sample_vl=$.trim(wt_iew_file_head_meta[match]);
|
1188 |
+
}
|
1189 |
+
|
1190 |
+
if(match_arr.length==2)/* date format matched */
|
1191 |
+
{
|
1192 |
+
match=match_arr.join('@');
|
1193 |
+
if(sample_vl!="")
|
1194 |
+
{
|
1195 |
+
sample_vl=mapping_field_editor.format_date(sample_vl);
|
1196 |
+
}
|
1197 |
+
}
|
1198 |
+
|
1199 |
+
sample_vl=(sample_vl!="" ? sample_vl : '<span class="wt_iew_no_sample_mapping_data">'+match+'</span>');
|
1200 |
+
out=out.replace('{'+match+'}', sample_vl);
|
1201 |
+
});
|
1202 |
+
}
|
1203 |
+
return out;
|
1204 |
+
},
|
1205 |
+
add_zero:function(i)
|
1206 |
+
{
|
1207 |
+
if(i<10)
|
1208 |
+
{
|
1209 |
+
i="0"+i;
|
1210 |
+
}
|
1211 |
+
return i;
|
1212 |
+
},
|
1213 |
+
format_date:function(date_string)
|
1214 |
+
{
|
1215 |
+
var d = new Date(date_string);
|
1216 |
+
if(d instanceof Date && !isNaN(d))
|
1217 |
+
{
|
1218 |
+
date_string=d.getFullYear()+'-'+this.add_zero(d.getMonth()+1)+'-'+this.add_zero(d.getDate())+' '+this.add_zero(d.getHours())+':'+this.add_zero(d.getMinutes())+':'+this.add_zero(d.getSeconds());
|
1219 |
+
}
|
1220 |
+
return date_string;
|
1221 |
+
},
|
1222 |
+
do_arithmetic:function(str)
|
1223 |
+
{
|
1224 |
+
const regex_arith = /\[([0-9()+\-*/. ]+)\]/g;
|
1225 |
+
let m;
|
1226 |
+
var out=str;
|
1227 |
+
while ((m = regex_arith.exec(str)) !== null) {
|
1228 |
+
/* This is necessary to avoid infinite loops with zero-width matches */
|
1229 |
+
if (m.index === regex_arith.lastIndex) {
|
1230 |
+
regex_arith.lastIndex++;
|
1231 |
+
}
|
1232 |
+
try{
|
1233 |
+
eqn='('+m[1]+')';
|
1234 |
+
eval("var eqn_eval = " + eqn.toLowerCase());
|
1235 |
+
out=out.replace(m[0], eqn_eval);
|
1236 |
+
} catch(e) {
|
1237 |
+
mapping_field_editor.popover.find('.wt_iew_mapping_field_editor_er').html(e);
|
1238 |
+
return false;
|
1239 |
+
}
|
1240 |
+
}
|
1241 |
+
return out;
|
1242 |
+
}
|
1243 |
+
}
|
1244 |
+
|
1245 |
+
return wt_iew_basic_import;
|
1246 |
+
})( jQuery );
|
1247 |
+
|
1248 |
+
(function ($, undefined) {
|
1249 |
+
$.fn.getCursorPosition = function() {
|
1250 |
+
var el = $(this).get(0);
|
1251 |
+
var pos = 0;
|
1252 |
+
if('selectionStart' in el) {
|
1253 |
+
pos = el.selectionStart;
|
1254 |
+
} else if('selection' in document) {
|
1255 |
+
el.focus();
|
1256 |
+
var Sel = document.selection.createRange();
|
1257 |
+
var SelLength = document.selection.createRange().text.length;
|
1258 |
+
Sel.moveStart('character', -el.value.length);
|
1259 |
+
pos = Sel.text.length - SelLength;
|
1260 |
+
}
|
1261 |
+
return pos;
|
1262 |
+
}
|
1263 |
+
})(jQuery);
|
1264 |
+
|
1265 |
+
/**
|
1266 |
+
* Dropzone initaiting section
|
1267 |
+
* More info at [www.dropzonejs.com](http://www.dropzonejs.com)
|
1268 |
+
*/
|
1269 |
+
var wt_iew_dropzone=
|
1270 |
+
{
|
1271 |
+
elm:null,
|
1272 |
+
old_file:false,
|
1273 |
+
Set:function()
|
1274 |
+
{
|
1275 |
+
if(typeof Dropzone==='undefined'){
|
1276 |
+
return false;
|
1277 |
+
}
|
1278 |
+
Dropzone.autoDiscover = false;
|
1279 |
+
},
|
1280 |
+
init:function(elm_id)
|
1281 |
+
{
|
1282 |
+
if(typeof Dropzone==='undefined'){
|
1283 |
+
return false;
|
1284 |
+
}
|
1285 |
+
this.elm=jQuery("#"+elm_id);
|
1286 |
+
|
1287 |
+
var ajax_data={
|
1288 |
+
'_wpnonce': wt_iew_basic_params.nonces.main,
|
1289 |
+
'action': "iew_import_ajax_basic",
|
1290 |
+
'import_action': 'upload_import_file',
|
1291 |
+
'data_type': 'json',
|
1292 |
+
'file_url': '',
|
1293 |
+
};
|
1294 |
+
var drop_zone_obj = new Dropzone(
|
1295 |
+
"#"+elm_id, {
|
1296 |
+
url:wt_iew_basic_params.ajax_url,
|
1297 |
+
createImageThumbnails:false,
|
1298 |
+
acceptedFiles:wt_iew_import_basic_params.allowed_import_file_type_mime.join(", "),
|
1299 |
+
paramName:'wt_iew_import_file',
|
1300 |
+
dictDefaultMessage:wt_iew_import_basic_params.msgs.drop_upload,
|
1301 |
+
dictInvalidFileType:wt_iew_import_basic_params.msgs.invalid_file,
|
1302 |
+
dictResponseError:wt_iew_import_basic_params.msgs.server_error,
|
1303 |
+
params:ajax_data,
|
1304 |
+
uploadMultiple:false,
|
1305 |
+
parallelUploads:1,
|
1306 |
+
maxFiles:1,
|
1307 |
+
maxFilesize:wt_iew_import_basic_params.max_import_file_size,
|
1308 |
+
previewTemplate:"<div class=\"dz-preview dz-file-preview\">\n <div class=\"dz-upload-info\"></div> \n <div class=\"dz-details\">\n <div class=\"dz-filename\"><span data-dz-name></span></div>\n </div>\n <div class=\"dz-progress\"><span class=\"dz-upload\" data-dz-uploadprogress></span></div>\n </div>",
|
1309 |
+
}
|
1310 |
+
);
|
1311 |
+
|
1312 |
+
drop_zone_obj.on("addedfile", function(file) {
|
1313 |
+
jQuery(".dz-upload-info").html(wt_iew_import_basic_params.msgs.uploading);
|
1314 |
+
jQuery(".dz-message").css({'margin-top':'85px'});
|
1315 |
+
|
1316 |
+
var dropzone_target=wt_iew_dropzone.elm.attr('wt_iew_dropzone_target');
|
1317 |
+
var dropzone_target_elm=jQuery(dropzone_target);
|
1318 |
+
if(dropzone_target_elm.length>0)
|
1319 |
+
{
|
1320 |
+
var file_url=dropzone_target_elm.val();
|
1321 |
+
if(file_url!="")
|
1322 |
+
{
|
1323 |
+
drop_zone_obj.options.params['file_url']=file_url; /* this is to remove the already uploaded file */
|
1324 |
+
}
|
1325 |
+
}
|
1326 |
+
|
1327 |
+
});
|
1328 |
+
|
1329 |
+
drop_zone_obj.on("dragstart", function(file) {
|
1330 |
+
wt_iew_dropzone.elm.addClass('wt_drag_start');
|
1331 |
+
});
|
1332 |
+
|
1333 |
+
drop_zone_obj.on("dragover", function(file) {
|
1334 |
+
wt_iew_dropzone.elm.addClass('wt_drag_start');
|
1335 |
+
});
|
1336 |
+
|
1337 |
+
drop_zone_obj.on("dragleave", function(file) {
|
1338 |
+
wt_iew_dropzone.elm.removeClass('wt_drag_start');
|
1339 |
+
});
|
1340 |
+
|
1341 |
+
drop_zone_obj.on("drop", function(file) {
|
1342 |
+
wt_iew_dropzone.elm.removeClass('wt_drag_start');
|
1343 |
+
});
|
1344 |
+
|
1345 |
+
drop_zone_obj.on("dragend", function(file) {
|
1346 |
+
wt_iew_dropzone.elm.removeClass('wt_drag_start');
|
1347 |
+
});
|
1348 |
+
|
1349 |
+
drop_zone_obj.on("fallback", function(file) {
|
1350 |
+
wt_iew_dropzone.elm.html(wt_iew_import_basic_params.msgs.outdated);
|
1351 |
+
return null;
|
1352 |
+
});
|
1353 |
+
drop_zone_obj.on("error", function(file, message) {
|
1354 |
+
drop_zone_obj.removeFile(file);
|
1355 |
+
wt_iew_notify_msg.error(message);
|
1356 |
+
});
|
1357 |
+
|
1358 |
+
drop_zone_obj.on("success", function(file, response) {
|
1359 |
+
|
1360 |
+
var file_name=file.name;
|
1361 |
+
|
1362 |
+
/* remove file obj */
|
1363 |
+
drop_zone_obj.removeFile(file);
|
1364 |
+
|
1365 |
+
/* register file deleting event */
|
1366 |
+
wt_iew_dropzone.remove_file();
|
1367 |
+
|
1368 |
+
if(wt_iew_dropzone.isJson(response))
|
1369 |
+
{
|
1370 |
+
response=JSON.parse(response);
|
1371 |
+
if(response.status==1)
|
1372 |
+
{
|
1373 |
+
jQuery(".wt_iew_dz_file_success").html(wt_iew_import_basic_params.msgs.upload_done);
|
1374 |
+
jQuery(".wt_iew_dz_remove_link").html(wt_iew_import_basic_params.msgs.remove);
|
1375 |
+
jQuery(".wt_iew_dz_file_name").html(file_name);
|
1376 |
+
jQuery(".dz-message").css({'margin-top':'60px'});
|
1377 |
+
|
1378 |
+
var dropzone_target=wt_iew_dropzone.elm.attr('wt_iew_dropzone_target');
|
1379 |
+
var dropzone_target_elm=jQuery(dropzone_target);
|
1380 |
+
if(dropzone_target_elm.length>0)
|
1381 |
+
{
|
1382 |
+
dropzone_target_elm.val(response.url);
|
1383 |
+
|
1384 |
+
}
|
1385 |
+
}else
|
1386 |
+
{
|
1387 |
+
wt_iew_notify_msg.error(response.msg);
|
1388 |
+
}
|
1389 |
+
}else
|
1390 |
+
{
|
1391 |
+
wt_iew_notify_msg.error(wt_iew_basic_params.msgs.error);
|
1392 |
+
}
|
1393 |
+
});
|
1394 |
+
},
|
1395 |
+
remove_file:function()
|
1396 |
+
{
|
1397 |
+
jQuery('.wt_iew_dz_remove_link').unbind('click').click(function(e){
|
1398 |
+
e.stopPropagation();
|
1399 |
+
|
1400 |
+
var dropzone_target=wt_iew_dropzone.elm.attr('wt_iew_dropzone_target');
|
1401 |
+
var dropzone_target_elm=jQuery(dropzone_target);
|
1402 |
+
if(dropzone_target_elm.length>0)
|
1403 |
+
{
|
1404 |
+
var file_url=dropzone_target_elm.val();
|
1405 |
+
if(file_url!="")
|
1406 |
+
{
|
1407 |
+
dropzone_target_elm.val('');
|
1408 |
+
jQuery(".wt_iew_dz_file_success, .wt_iew_dz_remove_link, .wt_iew_dz_file_name").html('');
|
1409 |
+
jQuery(".dz-message").css({'margin-top':'85px'});
|
1410 |
+
|
1411 |
+
jQuery.ajax({
|
1412 |
+
type: 'POST',
|
1413 |
+
url:wt_iew_basic_params.ajax_url,
|
1414 |
+
data:{
|
1415 |
+
'_wpnonce': wt_iew_basic_params.nonces.main,
|
1416 |
+
'action': "iew_import_ajax_basic",
|
1417 |
+
'import_action': 'delete_import_file',
|
1418 |
+
'data_type': 'json',
|
1419 |
+
'file_url':file_url,
|
1420 |
+
},
|
1421 |
+
dataType:'json'
|
1422 |
+
|
1423 |
+
});
|
1424 |
+
}
|
1425 |
+
}
|
1426 |
+
});
|
1427 |
+
},
|
1428 |
+
isJson:function(str)
|
1429 |
+
{
|
1430 |
+
try {
|
1431 |
+
JSON.parse(str);
|
1432 |
+
} catch (e) {
|
1433 |
+
return false;
|
1434 |
+
}
|
1435 |
+
return true;
|
1436 |
+
}
|
1437 |
+
}
|
1438 |
+
wt_iew_dropzone.Set();
|
1439 |
+
|
1440 |
+
|
1441 |
+
jQuery(function() {
|
1442 |
+
|
1443 |
+
if(wt_iew_import_basic_params.rerun_id>0)
|
1444 |
+
{
|
1445 |
+
wt_iew_basic_import.to_import=wt_iew_import_basic_params.to_import;
|
1446 |
+
wt_iew_basic_import.import_method=wt_iew_import_basic_params.import_method;
|
1447 |
+
wt_iew_basic_import.rerun_id=wt_iew_import_basic_params.rerun_id;
|
1448 |
+
wt_iew_basic_import.on_rerun=true;
|
1449 |
+
wt_iew_basic_import.is_valid_file=true;
|
1450 |
+
wt_iew_basic_import.temp_import_file=wt_iew_import_basic_params.temp_import_file;
|
1451 |
+
}
|
1452 |
+
wt_iew_basic_import.Set();
|
1453 |
+
});
|
admin/modules/import/classes/class-import-ajax.php
ADDED
@@ -0,0 +1,1215 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Ajax section of the Import module
|
4 |
+
*
|
5 |
+
* @link
|
6 |
+
*
|
7 |
+
* @package Wt_Import_Export_For_Woo
|
8 |
+
*/
|
9 |
+
if (!defined('ABSPATH')) {
|
10 |
+
exit;
|
11 |
+
}
|
12 |
+
|
13 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Basic_Import_Ajax')){
|
14 |
+
class Wt_Import_Export_For_Woo_Basic_Import_Ajax
|
15 |
+
{
|
16 |
+
public $step='';
|
17 |
+
public $steps=array();
|
18 |
+
public $step_btns=array();
|
19 |
+
public $import_method='';
|
20 |
+
public $to_import='';
|
21 |
+
|
22 |
+
protected $step_title='';
|
23 |
+
protected $step_keys=array();
|
24 |
+
protected $current_step_index=0;
|
25 |
+
protected $current_step_number=1;
|
26 |
+
protected $last_page=false;
|
27 |
+
protected $total_steps=0;
|
28 |
+
protected $step_summary='';
|
29 |
+
protected $step_description='';
|
30 |
+
protected $mapping_enabled_fields=array();
|
31 |
+
protected $mapping_templates=array();
|
32 |
+
protected $selected_template=0;
|
33 |
+
protected $selected_template_form_data=array();
|
34 |
+
protected $import_obj=null;
|
35 |
+
protected $field_group_prefixes=array();
|
36 |
+
protected $rerun_id=0;
|
37 |
+
|
38 |
+
public function __construct($import_obj, $to_import, $steps, $import_method, $selected_template, $rerun_id)
|
39 |
+
{
|
40 |
+
$this->import_obj=$import_obj;
|
41 |
+
$this->to_import=$to_import;
|
42 |
+
$this->steps=$steps;
|
43 |
+
$this->import_method=$import_method;
|
44 |
+
$this->selected_template=$selected_template;
|
45 |
+
$this->rerun_id=$rerun_id;
|
46 |
+
|
47 |
+
/**
|
48 |
+
* This array is to group the fields in the input file that are not in the default list.
|
49 |
+
*/
|
50 |
+
$this->field_group_prefixes=array(
|
51 |
+
'taxonomies'=>array('tax'),
|
52 |
+
'meta'=>array('meta'),
|
53 |
+
'attributes'=>array('attribute', 'attribute_data', 'attribute_default', 'meta:attribute'),
|
54 |
+
'hidden_meta'=>array('meta:_'),
|
55 |
+
);
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Ajax main function to retrive steps HTML
|
60 |
+
*/
|
61 |
+
public function get_steps($out)
|
62 |
+
{
|
63 |
+
//sleep(3);
|
64 |
+
$steps=(is_array($_POST['steps']) ? $_POST['steps'] : array($_POST['steps']));
|
65 |
+
$steps=Wt_Iew_Sh::sanitize_item($steps, 'text_arr');
|
66 |
+
$page_html=array();
|
67 |
+
|
68 |
+
if($this->selected_template>0) /* taking selected tamplate formdata */
|
69 |
+
{
|
70 |
+
$this->get_template_form_data($this->selected_template);
|
71 |
+
|
72 |
+
}elseif($this->rerun_id>0)
|
73 |
+
{
|
74 |
+
$this->selected_template_form_data=$this->import_obj->form_data;
|
75 |
+
}
|
76 |
+
|
77 |
+
foreach($steps as $step)
|
78 |
+
{
|
79 |
+
$method_name=$step.'_page';
|
80 |
+
if(method_exists($this, $method_name))
|
81 |
+
{
|
82 |
+
$page_html[$step]=$this->{$method_name}();
|
83 |
+
|
84 |
+
if($step=='method_import' && ($this->selected_template>0 || $this->rerun_id>0))
|
85 |
+
{
|
86 |
+
$out['template_data']=$this->selected_template_form_data;
|
87 |
+
}
|
88 |
+
}
|
89 |
+
}
|
90 |
+
$out['status']=1;
|
91 |
+
$out['page_html']=$page_html;
|
92 |
+
return $out;
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Delete uploaded import file
|
97 |
+
*
|
98 |
+
*/
|
99 |
+
public function delete_import_file($out)
|
100 |
+
{
|
101 |
+
$file_url=(isset($_POST['file_url']) ? esc_url_raw($_POST['file_url']) : '');
|
102 |
+
$out['file_url']=$file_url;
|
103 |
+
if($file_url!="" && $this->import_obj->delete_import_file($file_url))
|
104 |
+
{
|
105 |
+
$out['status']=1;
|
106 |
+
$out['msg']='';
|
107 |
+
}
|
108 |
+
return $out;
|
109 |
+
}
|
110 |
+
|
111 |
+
/**
|
112 |
+
* Upload import file (Drag and drop upload)
|
113 |
+
*
|
114 |
+
*/
|
115 |
+
public function upload_import_file($out)
|
116 |
+
{
|
117 |
+
if(isset($_FILES['wt_iew_import_file']))
|
118 |
+
{
|
119 |
+
|
120 |
+
$is_file_type_allowed=false;
|
121 |
+
if(!in_array($_FILES['wt_iew_import_file']['type'], $this->import_obj->allowed_import_file_type_mime)) /* Not allowed file type. [Bug fix for Windows OS]Then verify it again with file extension */
|
122 |
+
{
|
123 |
+
$ext=pathinfo($_FILES['wt_iew_import_file']['name'], PATHINFO_EXTENSION);
|
124 |
+
if(isset($this->import_obj->allowed_import_file_type_mime[$ext])) /* extension exists. */
|
125 |
+
{
|
126 |
+
$is_file_type_allowed=true;
|
127 |
+
}
|
128 |
+
}else
|
129 |
+
{
|
130 |
+
$is_file_type_allowed=true;
|
131 |
+
}
|
132 |
+
|
133 |
+
if($is_file_type_allowed) /* Allowed file type */
|
134 |
+
{
|
135 |
+
|
136 |
+
@set_time_limit(3600); // 1 hour
|
137 |
+
|
138 |
+
$max_bytes=($this->import_obj->max_import_file_size*1000000); //convert to bytes
|
139 |
+
if($max_bytes>=$_FILES['wt_iew_import_file']['size'])
|
140 |
+
{
|
141 |
+
$file_name='local_file_'.time().'_'.sanitize_file_name($_FILES['wt_iew_import_file']['name']); //sanitize the file name, add a timestamp prefix to avoid conflict
|
142 |
+
$file_path=$this->import_obj->get_file_path($file_name);
|
143 |
+
if(@move_uploaded_file($_FILES['wt_iew_import_file']['tmp_name'], $file_path))
|
144 |
+
{
|
145 |
+
$out['msg']='';
|
146 |
+
$out['status']=1;
|
147 |
+
$out['url']=$this->import_obj->get_file_url($file_name);
|
148 |
+
|
149 |
+
/**
|
150 |
+
* Check old file exists, and delete it
|
151 |
+
*/
|
152 |
+
$file_url=(isset($_POST['file_url']) ? esc_url_raw($_POST['file_url']) : '');
|
153 |
+
if($file_url!="")
|
154 |
+
{
|
155 |
+
$this->import_obj->delete_import_file($file_url);
|
156 |
+
}
|
157 |
+
}else
|
158 |
+
{
|
159 |
+
$out['msg']=__('Unable to upload file. Please check write permission of your `wp-content` folder.');
|
160 |
+
}
|
161 |
+
}else
|
162 |
+
{
|
163 |
+
$out['msg']=sprintf(__('File size exceeds the limit. %dMB max'), $this->import_obj->max_import_file_size);
|
164 |
+
}
|
165 |
+
}else
|
166 |
+
{
|
167 |
+
$out['msg']=sprintf(__('Invalid file type. Only %s are allowed.'), implode(", ", array_values($this->import_obj->allowed_import_file_type)));
|
168 |
+
}
|
169 |
+
}
|
170 |
+
|
171 |
+
return $out;
|
172 |
+
}
|
173 |
+
|
174 |
+
/**
|
175 |
+
* Ajax hook to download the input file as temp file and validate its extension.
|
176 |
+
*/
|
177 |
+
public function validate_file($out)
|
178 |
+
{
|
179 |
+
/* process form data */
|
180 |
+
$form_data=(isset($_POST['form_data']) ? Wt_Import_Export_For_Woo_Basic_Common_Helper::process_formdata(maybe_unserialize(($_POST['form_data']))) : array());
|
181 |
+
$response=$this->import_obj->download_remote_file($form_data);
|
182 |
+
|
183 |
+
if($response['response']) /* temp file created. Then delete old temp file if exists */
|
184 |
+
{
|
185 |
+
$temp_import_file=(isset($_POST['temp_import_file']) ? sanitize_file_name($_POST['temp_import_file']) : '');
|
186 |
+
if($temp_import_file!="")
|
187 |
+
{
|
188 |
+
$file_path=$this->import_obj->get_file_path($temp_import_file);
|
189 |
+
if(file_exists($file_path))
|
190 |
+
{
|
191 |
+
@unlink($file_path);
|
192 |
+
}
|
193 |
+
}
|
194 |
+
}
|
195 |
+
|
196 |
+
$out['status']=($response['response'] ? 1 : 0);
|
197 |
+
$out['msg']=($response['msg']!="" ? $response['msg'] : $out['msg']);
|
198 |
+
$out['file_name']=(isset($response['file_name']) ? $response['file_name'] : '');
|
199 |
+
|
200 |
+
return $out;
|
201 |
+
}
|
202 |
+
|
203 |
+
/**
|
204 |
+
* Ajax function to retrive meta step data
|
205 |
+
*/
|
206 |
+
public function get_meta_mapping_fields($out)
|
207 |
+
{
|
208 |
+
if($this->selected_template>0) /* taking selected tamplate formdata */
|
209 |
+
{
|
210 |
+
$this->get_template_form_data($this->selected_template);
|
211 |
+
|
212 |
+
}elseif($this->rerun_id>0)
|
213 |
+
{
|
214 |
+
$this->selected_template_form_data=$this->import_obj->form_data;
|
215 |
+
}
|
216 |
+
|
217 |
+
/* This is the sample data from input file */
|
218 |
+
$file_heading_meta_fields=(isset($_POST['file_head_meta']) ? json_decode(stripslashes($_POST['file_head_meta']), true) : array());
|
219 |
+
|
220 |
+
//taking current page form data
|
221 |
+
$meta_step_form_data=(isset($this->selected_template_form_data['meta_step_form_data']) ? $this->selected_template_form_data['meta_step_form_data'] : array());
|
222 |
+
|
223 |
+
/* formdata/template data of fields in mapping page */
|
224 |
+
$form_data_meta_mapping_fields=isset($meta_step_form_data['mapping_fields']) ? $meta_step_form_data['mapping_fields'] : array();
|
225 |
+
|
226 |
+
|
227 |
+
$meta_mapping_screen_fields=$this->_get_meta_mapping_screen_fields($form_data_meta_mapping_fields);
|
228 |
+
|
229 |
+
$draggable_tooltip=__("Drag to rearrange the columns");
|
230 |
+
$module_url=plugin_dir_url(dirname(__FILE__));
|
231 |
+
|
232 |
+
|
233 |
+
/* preparing meta fields. */
|
234 |
+
$prepared_meta_fields=array();
|
235 |
+
if($meta_mapping_screen_fields && is_array($meta_mapping_screen_fields))
|
236 |
+
{
|
237 |
+
/* loop through mapping fields */
|
238 |
+
foreach($meta_mapping_screen_fields as $meta_mapping_screen_field_key=>$meta_mapping_screen_field_val)
|
239 |
+
{
|
240 |
+
/* decalaring an empty array*/
|
241 |
+
$temp_arr=array();
|
242 |
+
|
243 |
+
/* current field group(tax, meta) formdata */
|
244 |
+
$current_meta_step_form_data=(isset($form_data_meta_mapping_fields[$meta_mapping_screen_field_key]) ? $form_data_meta_mapping_fields[$meta_mapping_screen_field_key] : array());
|
245 |
+
|
246 |
+
/* default field list from post type module */
|
247 |
+
$mapping_fields=((isset($meta_mapping_screen_field_val['fields']) && is_array($meta_mapping_screen_field_val['fields'])) ? $meta_mapping_screen_field_val['fields'] : array());
|
248 |
+
|
249 |
+
/* loop through form data */
|
250 |
+
foreach($current_meta_step_form_data as $key=>$val_arr) /* looping the template form data */
|
251 |
+
{
|
252 |
+
$val=$val_arr[0]; /* normal column val */
|
253 |
+
$checked=$val_arr[1]; /* import this column? */
|
254 |
+
|
255 |
+
if(isset($mapping_fields[$key])) /* found in default field list */
|
256 |
+
{
|
257 |
+
$label=(isset($mapping_fields[$key]['title']) ? $mapping_fields[$key]['title'] : '');
|
258 |
+
$description=(isset($mapping_fields[$key]['description']) ? $mapping_fields[$key]['title'] : '');
|
259 |
+
$type=(isset($mapping_fields[$key]['type']) ? $mapping_fields[$key]['type'] : '');
|
260 |
+
unset($mapping_fields[$key]); //remove the field from default list
|
261 |
+
|
262 |
+
if(isset($file_heading_meta_fields[$key])) /* also found in file heading list */
|
263 |
+
{
|
264 |
+
unset($file_heading_meta_fields[$key]); //remove the field from file heading list
|
265 |
+
}
|
266 |
+
$temp_arr[$key]=array('label'=>$label, 'description'=>$description, 'val'=>$val, 'checked'=>$checked, 'type'=>$type);
|
267 |
+
}
|
268 |
+
elseif(isset($file_heading_meta_fields[$key])) /* found in file heading list */
|
269 |
+
{
|
270 |
+
$label=$key;
|
271 |
+
$description=$this->prepare_field_description($key);
|
272 |
+
$type='';
|
273 |
+
unset($file_heading_meta_fields[$key]); //remove the field from file heading list
|
274 |
+
$temp_arr[$key]=array('label'=>$label, 'description'=>$description, 'val'=>$val, 'checked'=>$checked, 'type'=>$type);
|
275 |
+
}
|
276 |
+
}
|
277 |
+
|
278 |
+
/* loop through mapping fields */
|
279 |
+
if(count($mapping_fields)>0)
|
280 |
+
{
|
281 |
+
foreach($mapping_fields as $key=>$val_arr)
|
282 |
+
{
|
283 |
+
$label=(isset($val_arr['title']) ? $val_arr['title'] : '');
|
284 |
+
$description=(isset($val_arr['description']) ? $val_arr['description'] : '');
|
285 |
+
$type=(isset($val_arr['type']) ? $val_arr['type'] : '');
|
286 |
+
$val='';
|
287 |
+
$checked=0; /* import this column? */
|
288 |
+
if(isset($file_heading_meta_fields[$key]))
|
289 |
+
{
|
290 |
+
$checked=1; /* import this column? */
|
291 |
+
$val='{'.$key.'}';
|
292 |
+
unset($file_heading_meta_fields[$key]); //remove the field from file heading list
|
293 |
+
}
|
294 |
+
$temp_arr[$key]=array('label'=>$label, 'description'=>$description, 'val'=>$val, 'checked'=>$checked, 'type'=>$type);
|
295 |
+
}
|
296 |
+
}
|
297 |
+
|
298 |
+
if(count($file_heading_meta_fields)>0)
|
299 |
+
{
|
300 |
+
$current_field_group_prefix_arr=(isset($this->field_group_prefixes[$meta_mapping_screen_field_key]) ? $this->field_group_prefixes[$meta_mapping_screen_field_key] : array());
|
301 |
+
foreach($file_heading_meta_fields as $key=>$sample_val)
|
302 |
+
{
|
303 |
+
$is_include=$this->_is_include_meta_in_this_group($current_field_group_prefix_arr, $key);
|
304 |
+
if($is_include==1)
|
305 |
+
{
|
306 |
+
$label=Wt_Iew_Sh::sanitize_item($key);
|
307 |
+
$description=$this->prepare_field_description($key);
|
308 |
+
$type='';
|
309 |
+
$val='{'.$key.'}';
|
310 |
+
$checked=1; /* import this column? */
|
311 |
+
unset($file_heading_meta_fields[$key]); //remove the field from file heading list
|
312 |
+
$temp_arr[$key]=array('label'=>$label, 'description'=>$description, 'val'=>$val, 'checked'=>$checked, 'type'=>$type);
|
313 |
+
}
|
314 |
+
}
|
315 |
+
}
|
316 |
+
|
317 |
+
/* adding value to main array */
|
318 |
+
$prepared_meta_fields[$meta_mapping_screen_field_key]=array('fields'=>$temp_arr, 'checked'=>(isset($meta_mapping_screen_field_val['checked']) && $meta_mapping_screen_field_val['checked']==1 ? 1 : 0) );
|
319 |
+
}
|
320 |
+
|
321 |
+
/* if any columns that not in the above list */
|
322 |
+
if(count($file_heading_meta_fields)>0)
|
323 |
+
{
|
324 |
+
//do something
|
325 |
+
}
|
326 |
+
}
|
327 |
+
|
328 |
+
/* prepare HTML for meta mapping step */
|
329 |
+
$meta_html=array();
|
330 |
+
|
331 |
+
/* loop through prepared meta fields */
|
332 |
+
foreach($prepared_meta_fields as $meta_mapping_screen_field_key=>$meta_mapping_screen_field_val)
|
333 |
+
{
|
334 |
+
ob_start();
|
335 |
+
include dirname(plugin_dir_path(__FILE__)).'/views/_import_meta_step_page.php';
|
336 |
+
$meta_html[$meta_mapping_screen_field_key]=ob_get_clean();
|
337 |
+
}
|
338 |
+
|
339 |
+
$out['status']=1;
|
340 |
+
$out['meta_html']=$meta_html;
|
341 |
+
return $out;
|
342 |
+
}
|
343 |
+
|
344 |
+
public function save_template($out)
|
345 |
+
{
|
346 |
+
return $this->do_save_template('save', $out);
|
347 |
+
}
|
348 |
+
|
349 |
+
public function save_template_as($out)
|
350 |
+
{
|
351 |
+
return $this->do_save_template('save_as', $out);
|
352 |
+
}
|
353 |
+
|
354 |
+
public function update_template($out)
|
355 |
+
{
|
356 |
+
return $this->do_save_template('update', $out);
|
357 |
+
}
|
358 |
+
|
359 |
+
/**
|
360 |
+
* Download the input file and create history entry.
|
361 |
+
* This is the primary step before Import
|
362 |
+
* On XML import the file will be converted to CSV (Batch processing)
|
363 |
+
*/
|
364 |
+
public function download($out)
|
365 |
+
{
|
366 |
+
$this->import_obj->temp_import_file=(isset($_POST['temp_import_file']) ? sanitize_file_name($_POST['temp_import_file']) : '');
|
367 |
+
|
368 |
+
$offset=(isset($_POST['offset']) ? floatval($_POST['offset']) : 0);
|
369 |
+
$import_id=(isset($_POST['import_id']) ? intval($_POST['import_id']) : 0);
|
370 |
+
$import_method=(isset($_POST['import_method']) ? sanitize_text_field($_POST['import_method']) : $this->import_obj->default_import_method);
|
371 |
+
|
372 |
+
if($offset==0)
|
373 |
+
{
|
374 |
+
/* process form data */
|
375 |
+
$form_data=(isset($_POST['form_data']) ? Wt_Import_Export_For_Woo_Basic_Common_Helper::process_formdata(maybe_unserialize(($_POST['form_data']))) : array());
|
376 |
+
|
377 |
+
//sanitize form data
|
378 |
+
$form_data=Wt_Iew_IE_Basic_Helper::sanitize_formdata($form_data, $this->import_obj);
|
379 |
+
}else
|
380 |
+
{
|
381 |
+
/* no need to process the formdata steps other than first */
|
382 |
+
$form_data=array();
|
383 |
+
}
|
384 |
+
|
385 |
+
$out=$this->import_obj->process_download($form_data, 'download', $this->to_import, $import_id, $offset);
|
386 |
+
if($out['response']===true)
|
387 |
+
{
|
388 |
+
$import_id=$out['import_id'];
|
389 |
+
|
390 |
+
/**
|
391 |
+
* Prepare default mapping data for quick import
|
392 |
+
* After preparing update the Formdata in history table
|
393 |
+
*/
|
394 |
+
if($import_method=='quick' && $import_id>0 && $out['finished']==3)
|
395 |
+
{
|
396 |
+
$this->_prepare_for_quick($import_id);
|
397 |
+
}
|
398 |
+
|
399 |
+
|
400 |
+
$out['status']=1;
|
401 |
+
}else
|
402 |
+
{
|
403 |
+
$out['status']=0;
|
404 |
+
}
|
405 |
+
return $out;
|
406 |
+
}
|
407 |
+
|
408 |
+
/**
|
409 |
+
* Process the import
|
410 |
+
*
|
411 |
+
* @return array
|
412 |
+
*/
|
413 |
+
public function import($out)
|
414 |
+
{
|
415 |
+
$offset=(isset($_POST['offset']) ? floatval($_POST['offset']) : 0);
|
416 |
+
$import_id=(isset($_POST['import_id']) ? intval($_POST['import_id']) : 0);
|
417 |
+
|
418 |
+
/* no need to send formdata. It will take from history table by `process_action` method */
|
419 |
+
$form_data=array();
|
420 |
+
|
421 |
+
/* do the export process */
|
422 |
+
$out=$this->import_obj->process_action($form_data, 'import', $this->to_import, '', $import_id, $offset);
|
423 |
+
if($out['response']===true)
|
424 |
+
{
|
425 |
+
$out['status']=1;
|
426 |
+
}else
|
427 |
+
{
|
428 |
+
$out['status']=0;
|
429 |
+
}
|
430 |
+
return $out;
|
431 |
+
}
|
432 |
+
|
433 |
+
/**
|
434 |
+
* Save/Update template (Ajax sub function)
|
435 |
+
* @param boolean $is_update is update existing template or save as new
|
436 |
+
* @return array response status, name, id
|
437 |
+
*/
|
438 |
+
public function do_save_template($step, $out)
|
439 |
+
{
|
440 |
+
$is_update=($step=='update' ? true : false);
|
441 |
+
|
442 |
+
/* take template name from post data, if not then create from time stamp */
|
443 |
+
$template_name=(isset($_POST['template_name']) ? sanitize_text_field($_POST['template_name']) : date('d-M-Y h:i:s A'));
|
444 |
+
|
445 |
+
$template_name = stripslashes($template_name);
|
446 |
+
$out['name']= $template_name;
|
447 |
+
$out['id']=0;
|
448 |
+
$out['status']=1;
|
449 |
+
|
450 |
+
if($this->to_import!='')
|
451 |
+
{
|
452 |
+
global $wpdb;
|
453 |
+
|
454 |
+
/* checking: just saved and again click the button so shift the action as update */
|
455 |
+
if($step=='save' && $this->selected_template>0)
|
456 |
+
{
|
457 |
+
$is_update=true;
|
458 |
+
}
|
459 |
+
|
460 |
+
/* checking template with same name exists */
|
461 |
+
$template_data=$this->get_mapping_template_by_name($template_name);
|
462 |
+
if($template_data)
|
463 |
+
{
|
464 |
+
$is_throw_warn=false;
|
465 |
+
if($is_update)
|
466 |
+
{
|
467 |
+
if($template_data['id']!=$this->selected_template)
|
468 |
+
{
|
469 |
+
$is_throw_warn=true;
|
470 |
+
}
|
471 |
+
}else
|
472 |
+
{
|
473 |
+
$is_throw_warn=true;
|
474 |
+
}
|
475 |
+
|
476 |
+
if($is_throw_warn)
|
477 |
+
{
|
478 |
+
$out['status']=0;
|
479 |
+
if($step=='save_as')
|
480 |
+
{
|
481 |
+
$out['msg']=__('Please enter a different name');
|
482 |
+
}else
|
483 |
+
{
|
484 |
+
$out['msg']=__('Template with same name already exists');
|
485 |
+
}
|
486 |
+
return $out;
|
487 |
+
}
|
488 |
+
}
|
489 |
+
|
490 |
+
$tb=$wpdb->prefix.Wt_Import_Export_For_Woo_Basic::$template_tb;
|
491 |
+
|
492 |
+
/* process form data */
|
493 |
+
$form_data=(isset($_POST['form_data']) ? Wt_Import_Export_For_Woo_Basic_Common_Helper::process_formdata(maybe_unserialize(($_POST['form_data']))) : array());
|
494 |
+
|
495 |
+
//sanitize form data
|
496 |
+
$form_data=Wt_Iew_IE_Basic_Helper::sanitize_formdata($form_data, $this->import_obj);
|
497 |
+
|
498 |
+
/* upadte the template */
|
499 |
+
if($is_update)
|
500 |
+
{
|
501 |
+
|
502 |
+
$update_data=array(
|
503 |
+
'data'=>maybe_serialize($form_data),
|
504 |
+
'name'=>$template_name, //may be a rename
|
505 |
+
);
|
506 |
+
$update_data_type=array(
|
507 |
+
'%s',
|
508 |
+
'%s'
|
509 |
+
);
|
510 |
+
$update_where=array(
|
511 |
+
'id'=>$this->selected_template
|
512 |
+
);
|
513 |
+
$update_where_type=array(
|
514 |
+
'%d'
|
515 |
+
);
|
516 |
+
if($wpdb->update($tb, $update_data, $update_where, $update_data_type, $update_where_type)!==false)
|
517 |
+
{
|
518 |
+
$out['id']=$this->selected_template;
|
519 |
+
$out['msg']=__('Template updated successfully');
|
520 |
+
$out['name']=$template_name;
|
521 |
+
return $out;
|
522 |
+
}
|
523 |
+
}else
|
524 |
+
{
|
525 |
+
$insert_data=array(
|
526 |
+
'template_type'=>'import',
|
527 |
+
'item_type'=>$this->to_import,
|
528 |
+
'name'=>$template_name,
|
529 |
+
'data'=>maybe_serialize($form_data),
|
530 |
+
);
|
531 |
+
$insert_data_type=array(
|
532 |
+
'%s','%s','%s','%s'
|
533 |
+
);
|
534 |
+
if($wpdb->insert($tb, $insert_data, $insert_data_type)) //success
|
535 |
+
{
|
536 |
+
$out['id']=$wpdb->insert_id;
|
537 |
+
$out['msg']=__('Template saved successfully');
|
538 |
+
return $out;
|
539 |
+
}
|
540 |
+
}
|
541 |
+
}
|
542 |
+
$out['status']=0;
|
543 |
+
return $out;
|
544 |
+
}
|
545 |
+
|
546 |
+
/*
|
547 |
+
* Get step information
|
548 |
+
* @param string $step
|
549 |
+
*/
|
550 |
+
|
551 |
+
public function get_step_info( $step ) {
|
552 |
+
return isset( $this->steps[ $step ] ) ? $this->steps[ $step ] : array( 'title' => ' ', 'description' => ' ' );
|
553 |
+
}
|
554 |
+
/**
|
555 |
+
* Step 1 (Ajax sub function)
|
556 |
+
* Built in steps, post type choosing page
|
557 |
+
*/
|
558 |
+
public function post_type_page()
|
559 |
+
{
|
560 |
+
$post_types=apply_filters('wt_iew_importer_post_types_basic', array());
|
561 |
+
$post_types=(!is_array($post_types) ? array() : $post_types);
|
562 |
+
$this->step='post_type';
|
563 |
+
|
564 |
+
$this->prepare_step_summary();
|
565 |
+
$this->prepare_footer_button_list();
|
566 |
+
|
567 |
+
ob_start();
|
568 |
+
$this->prepare_step_header_html();
|
569 |
+
include_once dirname(plugin_dir_path(__FILE__)).'/views/_import_post_type_page.php';
|
570 |
+
$this->prepare_step_footer_html();
|
571 |
+
return ob_get_clean();
|
572 |
+
}
|
573 |
+
|
574 |
+
/**
|
575 |
+
* Step 2 (Ajax sub function)
|
576 |
+
* Built in steps, import method choosing page
|
577 |
+
*/
|
578 |
+
public function method_import_page()
|
579 |
+
{
|
580 |
+
$this->step='method_import';
|
581 |
+
if($this->to_import!="")
|
582 |
+
{
|
583 |
+
/* setting a default import method */
|
584 |
+
$this->import_method=($this->import_method=='' ? $this->import_obj->default_import_method : $this->import_method);
|
585 |
+
$this->import_obj->import_method=$this->import_method;
|
586 |
+
$this->steps=$this->import_obj->get_steps();
|
587 |
+
|
588 |
+
$this->prepare_step_summary();
|
589 |
+
$this->prepare_footer_button_list();
|
590 |
+
|
591 |
+
//taking current page form data
|
592 |
+
$method_import_form_data=(isset($this->selected_template_form_data['method_import_form_data']) ? $this->selected_template_form_data['method_import_form_data'] : array());
|
593 |
+
|
594 |
+
$method_import_screen_fields=$this->import_obj->get_method_import_screen_fields($method_import_form_data);
|
595 |
+
|
596 |
+
|
597 |
+
$form_data_import_template=$this->selected_template;
|
598 |
+
if($this->rerun_id>0)
|
599 |
+
{
|
600 |
+
if(isset($method_import_form_data['selected_template']))
|
601 |
+
{
|
602 |
+
/* do not set this value to `$this->selected_template` */
|
603 |
+
$form_data_import_template=$method_import_form_data['selected_template'];
|
604 |
+
}
|
605 |
+
}
|
606 |
+
|
607 |
+
/* meta field list for quick import */
|
608 |
+
$this->get_mapping_templates();
|
609 |
+
|
610 |
+
ob_start();
|
611 |
+
$this->prepare_step_header_html();
|
612 |
+
include_once dirname(plugin_dir_path(__FILE__)).'/views/_import_method_import_page.php';
|
613 |
+
$this->prepare_step_footer_html();
|
614 |
+
return ob_get_clean();
|
615 |
+
}else
|
616 |
+
{
|
617 |
+
return '';
|
618 |
+
}
|
619 |
+
}
|
620 |
+
|
621 |
+
/**
|
622 |
+
* Step 3 (Ajax sub function)
|
623 |
+
* Built in steps, Import mapping page
|
624 |
+
*/
|
625 |
+
public function mapping_page()
|
626 |
+
{
|
627 |
+
$this->step='mapping';
|
628 |
+
if($this->to_import!="")
|
629 |
+
{
|
630 |
+
$this->prepare_step_summary();
|
631 |
+
$this->prepare_footer_button_list();
|
632 |
+
|
633 |
+
|
634 |
+
$temp_import_file=(isset($_POST['temp_import_file']) ? sanitize_file_name($_POST['temp_import_file']) : '');
|
635 |
+
$file_path=$this->import_obj->get_file_path($temp_import_file);
|
636 |
+
if($temp_import_file!="" && file_exists($file_path))
|
637 |
+
{
|
638 |
+
$ext_arr=explode('.', $temp_import_file);
|
639 |
+
$ext= strtolower(end($ext_arr));
|
640 |
+
if(isset($this->import_obj->allowed_import_file_type[$ext])) /* file type is in allowed list */
|
641 |
+
{
|
642 |
+
// if($ext=='xml')
|
643 |
+
// {
|
644 |
+
// include_once WT_O_IEW_PLUGIN_PATH.'admin/classes/class-xmlreader.php';
|
645 |
+
// $reader=new Wt_Import_Export_For_Woo_Basic_Xmlreader();
|
646 |
+
// }else /* csv */
|
647 |
+
// {
|
648 |
+
include_once WT_O_IEW_PLUGIN_PATH.'admin/classes/class-csvreader.php';
|
649 |
+
$delimiter=(isset($_POST['delimiter']) ? ($_POST['delimiter']) : ','); //no sanitization
|
650 |
+
$reader=new Wt_Import_Export_For_Woo_Basic_Csvreader($delimiter);
|
651 |
+
// }
|
652 |
+
|
653 |
+
/* take first two rows in csv and in xml takes column keys and a sample data */
|
654 |
+
$sample_data=$reader->get_sample_data($file_path, true);
|
655 |
+
|
656 |
+
$file_heading_data=$this->process_file_heading_data($sample_data);
|
657 |
+
$file_heading_default_fields=$file_heading_data['default'];
|
658 |
+
$file_heading_meta_fields=$file_heading_data['meta'];
|
659 |
+
|
660 |
+
|
661 |
+
//taking current page form data
|
662 |
+
$mapping_form_data=(isset($this->selected_template_form_data['mapping_form_data']) ? $this->selected_template_form_data['mapping_form_data'] : array());
|
663 |
+
|
664 |
+
/* formdata/template data of fields in mapping page */
|
665 |
+
$form_data_mapping_fields=isset($mapping_form_data['mapping_fields']) ? $mapping_form_data['mapping_fields'] : array();
|
666 |
+
|
667 |
+
/**
|
668 |
+
* default mapping page fields
|
669 |
+
* Format: 'field_key'=>array('title'=>'', 'description'=>'')
|
670 |
+
*/
|
671 |
+
$mapping_fields=array();
|
672 |
+
$mapping_fields=apply_filters('wt_iew_importer_alter_mapping_fields_basic', $mapping_fields, $this->to_import, $form_data_mapping_fields);
|
673 |
+
|
674 |
+
/* meta fields list */
|
675 |
+
$this->get_mapping_enabled_fields();
|
676 |
+
|
677 |
+
/* mapping enabled meta fields */
|
678 |
+
$form_data_mapping_enabled_fields=(isset($mapping_form_data['mapping_enabled_fields']) ? $mapping_form_data['mapping_enabled_fields'] : array());
|
679 |
+
}
|
680 |
+
}
|
681 |
+
|
682 |
+
ob_start();
|
683 |
+
$this->prepare_step_header_html();
|
684 |
+
include_once dirname(plugin_dir_path(__FILE__)).'/views/_import_mapping_page.php';
|
685 |
+
$this->prepare_step_footer_html();
|
686 |
+
return ob_get_clean();
|
687 |
+
|
688 |
+
}else
|
689 |
+
{
|
690 |
+
return '';
|
691 |
+
}
|
692 |
+
}
|
693 |
+
|
694 |
+
/**
|
695 |
+
* Step 4 (Ajax sub function)
|
696 |
+
* Built in steps, Advanced settings page
|
697 |
+
*/
|
698 |
+
public function advanced_page()
|
699 |
+
{
|
700 |
+
$this->step='advanced';
|
701 |
+
if($this->to_import!="")
|
702 |
+
{
|
703 |
+
$this->prepare_step_summary();
|
704 |
+
$this->prepare_footer_button_list();
|
705 |
+
|
706 |
+
//taking current page form data
|
707 |
+
$advanced_form_data=(isset($this->selected_template_form_data['advanced_form_data']) ? $this->selected_template_form_data['advanced_form_data'] : array());
|
708 |
+
|
709 |
+
$advanced_screen_fields=$this->import_obj->get_advanced_screen_fields($advanced_form_data);
|
710 |
+
|
711 |
+
ob_start();
|
712 |
+
$this->prepare_step_header_html();
|
713 |
+
include_once dirname(plugin_dir_path(__FILE__)).'/views/_import_advanced_page.php';
|
714 |
+
$this->prepare_step_footer_html();
|
715 |
+
return ob_get_clean();
|
716 |
+
|
717 |
+
}else
|
718 |
+
{
|
719 |
+
return '';
|
720 |
+
}
|
721 |
+
}
|
722 |
+
|
723 |
+
/**
|
724 |
+
* Prepare description for mapping step fields
|
725 |
+
*/
|
726 |
+
protected function prepare_field_description($key)
|
727 |
+
{
|
728 |
+
$out='';
|
729 |
+
if(strpos($key, 'tax:')!==false) /* taxonomy */
|
730 |
+
{
|
731 |
+
$column=trim(str_replace('tax:', '', $key));
|
732 |
+
if(substr($column, 0, 3)!== 'pa_')
|
733 |
+
{
|
734 |
+
$out=__('Product taxonomies');
|
735 |
+
}else
|
736 |
+
{
|
737 |
+
$out=__('New taxonomy: ').$column;
|
738 |
+
}
|
739 |
+
}
|
740 |
+
elseif(strpos($key, 'meta:')!==false) /* meta */
|
741 |
+
{
|
742 |
+
$column=trim(str_replace('meta:', '', $key));
|
743 |
+
$out=__('Custom Field: ').$column;
|
744 |
+
}
|
745 |
+
elseif(strpos($key, 'attribute:')!==false) /* attribute */
|
746 |
+
{
|
747 |
+
$column=trim(str_replace('attribute:', '', $key));
|
748 |
+
if(substr($column, 0, 3)== 'pa_')
|
749 |
+
{
|
750 |
+
$out=__('Taxonomy attributes');
|
751 |
+
}else
|
752 |
+
{
|
753 |
+
$out=__('New attribute: ').$column;
|
754 |
+
}
|
755 |
+
}
|
756 |
+
elseif(strpos($key, 'attribute_data:')!==false) /* attribute data */
|
757 |
+
{
|
758 |
+
$column=trim(str_replace('attribute_data:', '', $key));
|
759 |
+
$out=__('Attribute data: ').$column;
|
760 |
+
}
|
761 |
+
elseif(strpos($key, 'attribute_default:')!==false) /* attribute default */
|
762 |
+
{
|
763 |
+
$column=trim(str_replace('attribute_default:', '', $key));
|
764 |
+
$out=__('Attribute default value: ').$column;
|
765 |
+
}
|
766 |
+
return $out;
|
767 |
+
}
|
768 |
+
|
769 |
+
/**
|
770 |
+
* split default mapping fields and meta mapping fields
|
771 |
+
*/
|
772 |
+
protected function process_file_heading_data($arr)
|
773 |
+
{
|
774 |
+
$default=array();
|
775 |
+
$meta=array();
|
776 |
+
foreach($arr as $key=>$v)
|
777 |
+
{
|
778 |
+
if(is_array($v))
|
779 |
+
{
|
780 |
+
$meta=array_merge($meta, $v);
|
781 |
+
}else
|
782 |
+
{
|
783 |
+
$default[$key]=$v;
|
784 |
+
}
|
785 |
+
}
|
786 |
+
return array('default'=>$default, 'meta'=>$meta);
|
787 |
+
}
|
788 |
+
|
789 |
+
/**
|
790 |
+
* Get template form data
|
791 |
+
*/
|
792 |
+
protected function get_template_form_data($id)
|
793 |
+
{
|
794 |
+
$template_data=$this->get_mapping_template_by_id($id);
|
795 |
+
if($template_data)
|
796 |
+
{
|
797 |
+
$decoded_form_data=Wt_Import_Export_For_Woo_Basic_Common_Helper::process_formdata(maybe_unserialize($template_data['data']));
|
798 |
+
$this->selected_template_form_data=(!is_array($decoded_form_data) ? array() : $decoded_form_data);
|
799 |
+
}
|
800 |
+
}
|
801 |
+
|
802 |
+
|
803 |
+
/**
|
804 |
+
* Taking mapping template by Name
|
805 |
+
*/
|
806 |
+
protected function get_mapping_template_by_name($name)
|
807 |
+
{
|
808 |
+
global $wpdb;
|
809 |
+
$tb=$wpdb->prefix.Wt_Import_Export_For_Woo_Basic::$template_tb;
|
810 |
+
$qry=$wpdb->prepare("SELECT * FROM $tb WHERE template_type=%s AND item_type=%s AND name=%s",array('import', $this->to_import, $name));
|
811 |
+
return $wpdb->get_row($qry, ARRAY_A);
|
812 |
+
}
|
813 |
+
|
814 |
+
|
815 |
+
/**
|
816 |
+
* Taking mapping template by ID
|
817 |
+
*/
|
818 |
+
protected function get_mapping_template_by_id($id)
|
819 |
+
{
|
820 |
+
global $wpdb;
|
821 |
+
$tb=$wpdb->prefix.Wt_Import_Export_For_Woo_Basic::$template_tb;
|
822 |
+
$qry=$wpdb->prepare("SELECT * FROM $tb WHERE template_type=%s AND item_type=%s AND id=%d",array('import', $this->to_import, $id));
|
823 |
+
return $wpdb->get_row($qry, ARRAY_A);
|
824 |
+
}
|
825 |
+
|
826 |
+
/**
|
827 |
+
* Taking all mapping templates
|
828 |
+
*/
|
829 |
+
protected function get_mapping_templates()
|
830 |
+
{
|
831 |
+
if($this->to_import=='')
|
832 |
+
{
|
833 |
+
return;
|
834 |
+
}
|
835 |
+
global $wpdb;
|
836 |
+
$tb=$wpdb->prefix.Wt_Import_Export_For_Woo_Basic::$template_tb;
|
837 |
+
$val=$wpdb->get_results("SELECT * FROM $tb WHERE template_type='import' AND item_type='".$this->to_import."' ORDER BY id DESC", ARRAY_A);
|
838 |
+
|
839 |
+
//add a filter here for modules to alter the data
|
840 |
+
$this->mapping_templates=($val ? $val : array());
|
841 |
+
}
|
842 |
+
|
843 |
+
|
844 |
+
/**
|
845 |
+
* Get meta field list for mapping page
|
846 |
+
*
|
847 |
+
*/
|
848 |
+
protected function get_mapping_enabled_fields()
|
849 |
+
{
|
850 |
+
$mapping_enabled_fields=array(
|
851 |
+
// 'hidden_meta'=>array(__('Hidden meta'),0),
|
852 |
+
// 'meta'=>array(__('Meta'),1),
|
853 |
+
);
|
854 |
+
$this->mapping_enabled_fields=apply_filters('wt_iew_importer_alter_mapping_enabled_fields_basic', $mapping_enabled_fields, $this->to_import, array());
|
855 |
+
}
|
856 |
+
|
857 |
+
protected function prepare_step_summary()
|
858 |
+
{
|
859 |
+
$step_info= $this->get_step_info($this->step);
|
860 |
+
$this->step_title=$step_info['title'];
|
861 |
+
$this->step_keys=array_keys($this->steps);
|
862 |
+
$this->current_step_index=array_search($this->step, $this->step_keys);
|
863 |
+
$this->current_step_number=$this->current_step_index+1;
|
864 |
+
$this->last_page=(!isset($this->step_keys[$this->current_step_index+1]) ? true : false);
|
865 |
+
$this->total_steps=count($this->step_keys);
|
866 |
+
$this->step_summary=__(sprintf("Step %d of %d", $this->current_step_number, $this->total_steps));
|
867 |
+
$this->step_description=$step_info['description'];
|
868 |
+
}
|
869 |
+
|
870 |
+
protected function prepare_step_header_html()
|
871 |
+
{
|
872 |
+
include dirname(plugin_dir_path(__FILE__)).'/views/_import_header.php';
|
873 |
+
}
|
874 |
+
|
875 |
+
protected function prepare_step_footer_html()
|
876 |
+
{
|
877 |
+
include dirname(plugin_dir_path(__FILE__)).'/views/_import_footer.php';
|
878 |
+
}
|
879 |
+
|
880 |
+
protected function prepare_footer_button_list()
|
881 |
+
{
|
882 |
+
$out=array();
|
883 |
+
$step_keys=$this->step_keys;
|
884 |
+
$current_index=$this->current_step_index;
|
885 |
+
$last_page=$this->last_page;
|
886 |
+
if($current_index!==false) /* step exists */
|
887 |
+
{
|
888 |
+
if($current_index>0) //add back button
|
889 |
+
{
|
890 |
+
$out['back']=array(
|
891 |
+
'type'=>'button',
|
892 |
+
'action_type'=>'step',
|
893 |
+
'key'=>$step_keys[$current_index-1],
|
894 |
+
'text'=>'<span class="dashicons dashicons-arrow-left-alt2" style="line-height:27px;"></span> '.__('Back'),
|
895 |
+
);
|
896 |
+
}
|
897 |
+
|
898 |
+
if(isset($step_keys[$current_index+1])) /* not last step */
|
899 |
+
{
|
900 |
+
$next_number=$current_index+2;
|
901 |
+
$next_key=$step_keys[$current_index+1];
|
902 |
+
$next_title=$this->steps[$next_key]['title'];
|
903 |
+
$out['next']=array(
|
904 |
+
'type'=>'button',
|
905 |
+
'action_type'=>'step',
|
906 |
+
'key'=>$next_key,
|
907 |
+
'text'=>__('Step').' '.$next_number.': '.$next_title.' <span class="dashicons dashicons-arrow-right-alt2" style="line-height:27px;"></span>',
|
908 |
+
);
|
909 |
+
|
910 |
+
if($this->import_method=='quick' || $this->import_method=='template') //Quick Or Template method
|
911 |
+
{
|
912 |
+
$out['or']=array(
|
913 |
+
'type'=>'text',
|
914 |
+
'text'=>__('Or'),
|
915 |
+
);
|
916 |
+
}
|
917 |
+
|
918 |
+
}else
|
919 |
+
{
|
920 |
+
$last_page=true;
|
921 |
+
}
|
922 |
+
|
923 |
+
if($this->import_method=='quick' || $this->import_method=='template' || $last_page) //template method, or last page, or quick import
|
924 |
+
{
|
925 |
+
if($last_page && $this->import_method!='quick') //last page and not quick import
|
926 |
+
{
|
927 |
+
if($this->import_method=='template')
|
928 |
+
{
|
929 |
+
$out['save']=array(
|
930 |
+
'key'=>'save',
|
931 |
+
'icon'=>'',
|
932 |
+
'type'=>'dropdown_button',
|
933 |
+
'text'=>__('Save template'),
|
934 |
+
'items'=>array(
|
935 |
+
'update'=>array(
|
936 |
+
'key'=>'update_template',
|
937 |
+
'text'=>__('Save'), //no prompt
|
938 |
+
),
|
939 |
+
'save'=>array(
|
940 |
+
'key'=>'save_template_as',
|
941 |
+
'text'=>__('Save As'), //prompt for name
|
942 |
+
)
|
943 |
+
)
|
944 |
+
);
|
945 |
+
}else
|
946 |
+
{
|
947 |
+
$out['save']=array(
|
948 |
+
'key'=>'save_template',
|
949 |
+
'icon'=>'',
|
950 |
+
'type'=>'button',
|
951 |
+
'text'=>__('Save template'), //prompt for name
|
952 |
+
);
|
953 |
+
}
|
954 |
+
}
|
955 |
+
$out['download']=array(
|
956 |
+
'key'=>'download', /* first step of import must be download the input file */
|
957 |
+
'class'=>'iew_import_btn',
|
958 |
+
'icon'=>'',
|
959 |
+
'type'=>'button',
|
960 |
+
'text'=>__('Import'),
|
961 |
+
);
|
962 |
+
}
|
963 |
+
}
|
964 |
+
$this->step_btns=apply_filters('wt_iew_importer_alter_footer_btns_basic', $out, $this->step, $this->steps);
|
965 |
+
}
|
966 |
+
|
967 |
+
/**
|
968 |
+
* Prepare default mapping data for quick import
|
969 |
+
* After preparing update the Formdata in history table
|
970 |
+
*/
|
971 |
+
protected function _prepare_for_quick($import_id)
|
972 |
+
{
|
973 |
+
//take history data by import_id
|
974 |
+
$import_data=Wt_Import_Export_For_Woo_Basic_History::get_history_entry_by_id($import_id);
|
975 |
+
|
976 |
+
//processing form data
|
977 |
+
$form_data=(isset($import_data['data']) ? maybe_unserialize($import_data['data']) : array());
|
978 |
+
|
979 |
+
|
980 |
+
$ext_arr=explode('.', $this->import_obj->temp_import_file);
|
981 |
+
// if(strtolower(end($ext_arr))=='xml') /* no chance for XML. anyway we are not skipping the future possibilities */
|
982 |
+
// {
|
983 |
+
// include_once WT_O_IEW_PLUGIN_PATH.'admin/classes/class-xmlreader.php';
|
984 |
+
// $reader=new Wt_Import_Export_For_Woo_Basic_Xmlreader();
|
985 |
+
//
|
986 |
+
// }else /* csv */
|
987 |
+
// {
|
988 |
+
include_once WT_O_IEW_PLUGIN_PATH.'admin/classes/class-csvreader.php';
|
989 |
+
$delimiter=(isset($form_data['method_import_form_data']['wt_iew_delimiter']) ? ($form_data['method_import_form_data']['wt_iew_delimiter']) : ',');
|
990 |
+
$reader=new Wt_Import_Export_For_Woo_Basic_Csvreader($delimiter);
|
991 |
+
// }
|
992 |
+
|
993 |
+
$file_path=$this->import_obj->get_file_path($this->import_obj->temp_import_file);
|
994 |
+
|
995 |
+
/* take first two rows in csv and in xml takes column keys and a sample data */
|
996 |
+
$sample_data=$reader->get_sample_data($file_path, true);
|
997 |
+
|
998 |
+
$file_heading_data=$this->process_file_heading_data($sample_data);
|
999 |
+
$file_heading_default_fields=$file_heading_data['default'];
|
1000 |
+
$file_heading_meta_fields=$file_heading_data['meta'];
|
1001 |
+
|
1002 |
+
|
1003 |
+
/**
|
1004 |
+
* Default mapping fields
|
1005 |
+
* Format: 'field_key'=>array('title'=>'', 'description'=>'')
|
1006 |
+
*/
|
1007 |
+
$mapping_fields=array();
|
1008 |
+
$mapping_fields=apply_filters('wt_iew_importer_alter_mapping_fields_basic', $mapping_fields, $this->to_import, array());
|
1009 |
+
|
1010 |
+
$array_keys_file_heading_default_fields = array_keys($file_heading_default_fields);
|
1011 |
+
$mapping_form_data=array('mapping_fields'=>array(), 'mapping_selected_fields'=>array());
|
1012 |
+
$allowed_field_types=array('start_with', 'end_with', 'contain');
|
1013 |
+
|
1014 |
+
foreach($mapping_fields as $key=>$val_arr)
|
1015 |
+
{
|
1016 |
+
$val='';
|
1017 |
+
$checked=0; /* import this column? */
|
1018 |
+
$type=(isset($val_arr['type']) ? $val_arr['type'] : '');
|
1019 |
+
// if(isset($file_heading_default_fields[$key]))
|
1020 |
+
if($case_key = preg_grep("/^$key$/i", $array_keys_file_heading_default_fields)) //preg_grep used escape from case sensitive check.
|
1021 |
+
{
|
1022 |
+
$checked=1; /* import this column? */
|
1023 |
+
// $val='{'.$key.'}';
|
1024 |
+
$val='{'.array_shift($case_key).'}'; // preg_grep give an array with actual index and value
|
1025 |
+
unset($file_heading_default_fields[$key]); //remove the field from file heading list
|
1026 |
+
}
|
1027 |
+
elseif(isset($file_heading_meta_fields[$key])) /* some meta items will show inside default field list, Eg: yoast */
|
1028 |
+
{
|
1029 |
+
$checked=1; /* import this column? */
|
1030 |
+
$val='{'.$key.'}';
|
1031 |
+
unset($file_heading_meta_fields[$key]); //remove the field from file heading list
|
1032 |
+
}else
|
1033 |
+
{
|
1034 |
+
$field_type=(isset($val_arr['field_type']) ? $val_arr['field_type'] : '');
|
1035 |
+
if($field_type!="" && in_array($field_type, $allowed_field_types)) // it may be a different field type
|
1036 |
+
{
|
1037 |
+
foreach ($file_heading_default_fields as $def_key => $def_val)
|
1038 |
+
{
|
1039 |
+
$matched=false;
|
1040 |
+
if($field_type=='start_with' && strpos($def_key, $key)===0)
|
1041 |
+
{
|
1042 |
+
$matched=true;
|
1043 |
+
}
|
1044 |
+
elseif($field_type=='ends_with' && strrpos($def_key, $key)===(strlen($def_key) - strlen($key)))
|
1045 |
+
{
|
1046 |
+
$matched=true;
|
1047 |
+
}
|
1048 |
+
elseif($field_type=='contains' && strpos($def_key, $key)!==false)
|
1049 |
+
{
|
1050 |
+
$matched=true;
|
1051 |
+
}
|
1052 |
+
if($matched)
|
1053 |
+
{
|
1054 |
+
$val='{'.$def_key.'}';
|
1055 |
+
unset($file_heading_default_fields[$def_key]); //remove the field from file heading list
|
1056 |
+
$mapping_form_data['mapping_selected_fields'][$def_key]=$val;
|
1057 |
+
$mapping_form_data['mapping_fields'][$def_key]=array($val, 1, $type); //value, enabled, type
|
1058 |
+
}
|
1059 |
+
}
|
1060 |
+
}else /* unmatched keys */
|
1061 |
+
{
|
1062 |
+
$checked=0;
|
1063 |
+
$val='';
|
1064 |
+
}
|
1065 |
+
}
|
1066 |
+
if($checked==1)
|
1067 |
+
{
|
1068 |
+
$mapping_form_data['mapping_selected_fields'][$key]=$val;
|
1069 |
+
$mapping_form_data['mapping_fields'][$key]=array($val, 1, $type); //value, enabled, type
|
1070 |
+
}
|
1071 |
+
}
|
1072 |
+
|
1073 |
+
/**
|
1074 |
+
* Meta mapping fields
|
1075 |
+
*
|
1076 |
+
*/
|
1077 |
+
$form_data_meta_mapping_fields = array(); // recheck the need of this variable in the below context.
|
1078 |
+
$meta_mapping_screen_fields=$this->_get_meta_mapping_screen_fields($form_data_meta_mapping_fields);
|
1079 |
+
|
1080 |
+
/* preparing meta fields. */
|
1081 |
+
$meta_mapping_form_data=array('mapping_fields'=>array(), 'mapping_selected_fields'=>array());
|
1082 |
+
if($meta_mapping_screen_fields && is_array($meta_mapping_screen_fields))
|
1083 |
+
{
|
1084 |
+
/* loop through mapping fields */
|
1085 |
+
foreach($meta_mapping_screen_fields as $meta_mapping_screen_field_key=>$meta_mapping_screen_field_val)
|
1086 |
+
{
|
1087 |
+
/* decalaring an empty array*/
|
1088 |
+
$temp_arr=array();
|
1089 |
+
$temp_fields_arr=array(); /* this is to store mapping field other details */
|
1090 |
+
|
1091 |
+
/* default field list from post type module */
|
1092 |
+
$mapping_fields=((isset($meta_mapping_screen_field_val['fields']) && is_array($meta_mapping_screen_field_val['fields'])) ? $meta_mapping_screen_field_val['fields'] : array());
|
1093 |
+
|
1094 |
+
/* loop through mapping fields */
|
1095 |
+
if(count($mapping_fields)>0)
|
1096 |
+
{
|
1097 |
+
foreach($mapping_fields as $key=>$val_arr)
|
1098 |
+
{
|
1099 |
+
$val='';
|
1100 |
+
$checked=0; /* import this column? */
|
1101 |
+
$type=(isset($val_arr['type']) ? $val_arr['type'] : '');
|
1102 |
+
|
1103 |
+
if(isset($file_heading_meta_fields[$key]))
|
1104 |
+
{
|
1105 |
+
$checked=1; /* import this column? */
|
1106 |
+
$val='{'.$key.'}';
|
1107 |
+
unset($file_heading_meta_fields[$key]); //remove the field from file heading list
|
1108 |
+
}
|
1109 |
+
if($checked==1)
|
1110 |
+
{
|
1111 |
+
$temp_arr[$key]=$val;
|
1112 |
+
$temp_fields_arr[$key]=array($val, 1, $type);
|
1113 |
+
}
|
1114 |
+
}
|
1115 |
+
}
|
1116 |
+
if(count($file_heading_meta_fields)>0)
|
1117 |
+
{
|
1118 |
+
$current_field_group_prefix_arr=(isset($this->field_group_prefixes[$meta_mapping_screen_field_key]) ? $this->field_group_prefixes[$meta_mapping_screen_field_key] : array());
|
1119 |
+
foreach($file_heading_meta_fields as $key=>$sample_val)
|
1120 |
+
{
|
1121 |
+
$is_include=$this->_is_include_meta_in_this_group($current_field_group_prefix_arr, $key);
|
1122 |
+
if($is_include==1)
|
1123 |
+
{
|
1124 |
+
$val='{'.$key.'}';
|
1125 |
+
$checked=1; /* import this column? */
|
1126 |
+
unset($file_heading_meta_fields[$key]); //remove the field from file heading list
|
1127 |
+
$temp_arr[$key]=$val;
|
1128 |
+
$temp_fields_arr[$key]=array($val, 1, '');
|
1129 |
+
}
|
1130 |
+
}
|
1131 |
+
}
|
1132 |
+
|
1133 |
+
/* adding value to main array */
|
1134 |
+
$meta_mapping_form_data['mapping_selected_fields'][$meta_mapping_screen_field_key]=$temp_arr;
|
1135 |
+
$meta_mapping_form_data['mapping_fields'][$meta_mapping_screen_field_key]=$temp_fields_arr;
|
1136 |
+
$mapping_fields=$temp_arr=$temp_fields_arr=null;
|
1137 |
+
unset($temp_arr, $temp_fields_arr, $mapping_fields);
|
1138 |
+
}
|
1139 |
+
|
1140 |
+
/* if any columns that not in the above list */
|
1141 |
+
if(count($file_heading_meta_fields)>0)
|
1142 |
+
{
|
1143 |
+
//do something
|
1144 |
+
}
|
1145 |
+
}
|
1146 |
+
|
1147 |
+
/**
|
1148 |
+
* update form data with prepared mapping form data
|
1149 |
+
*/
|
1150 |
+
$form_data['mapping_form_data']=$mapping_form_data;
|
1151 |
+
$form_data['meta_step_form_data']=$meta_mapping_form_data;
|
1152 |
+
|
1153 |
+
|
1154 |
+
$update_data=array(
|
1155 |
+
'data'=>maybe_serialize($form_data), //formadata
|
1156 |
+
);
|
1157 |
+
$update_data_type=array(
|
1158 |
+
'%s',
|
1159 |
+
);
|
1160 |
+
Wt_Import_Export_For_Woo_Basic_History::update_history_entry($import_id, $update_data, $update_data_type);
|
1161 |
+
|
1162 |
+
$mapping_form_data=$meta_mapping_form_data=$form_data=null;
|
1163 |
+
unset($mapping_form_data, $meta_mapping_form_data, $form_data);
|
1164 |
+
}
|
1165 |
+
|
1166 |
+
protected function _get_meta_mapping_screen_fields($form_data_meta_mapping_fields)
|
1167 |
+
{
|
1168 |
+
$this->get_mapping_enabled_fields();
|
1169 |
+
$meta_mapping_screen_fields=array();
|
1170 |
+
foreach($this->mapping_enabled_fields as $field_key=>$field_vl)
|
1171 |
+
{
|
1172 |
+
$field_vl=(!is_array($field_vl) ? array($field_vl, 0) : $field_vl);
|
1173 |
+
$meta_mapping_screen_fields[$field_key]=array(
|
1174 |
+
'title'=>'',
|
1175 |
+
'checked'=>$field_vl[1],
|
1176 |
+
'fields'=>array(),
|
1177 |
+
);
|
1178 |
+
}
|
1179 |
+
|
1180 |
+
/**
|
1181 |
+
* default mapping page fields
|
1182 |
+
* Format: 'field_key'=>array('title'=>'', 'description'=>'')
|
1183 |
+
*/
|
1184 |
+
return apply_filters('wt_iew_importer_alter_meta_mapping_fields_basic', $meta_mapping_screen_fields, $this->to_import, $form_data_meta_mapping_fields);
|
1185 |
+
}
|
1186 |
+
|
1187 |
+
protected function _is_include_meta_in_this_group($current_field_group_prefix_arr, $key)
|
1188 |
+
{
|
1189 |
+
$is_include=0;
|
1190 |
+
foreach ($current_field_group_prefix_arr as $_prefix)
|
1191 |
+
{
|
1192 |
+
if(strpos($key, $_prefix)===0) /* find as first occurrence */
|
1193 |
+
{
|
1194 |
+
if($_prefix=='meta') /* avoid conflict with hidden meta */
|
1195 |
+
{
|
1196 |
+
$name=str_replace('meta:', '', $key);
|
1197 |
+
if(substr($name, 0, 1)!='_') /* not hidden meta */
|
1198 |
+
{
|
1199 |
+
if(strpos($name, 'attribute')!==0) /* its not meta attribute */
|
1200 |
+
{
|
1201 |
+
$is_include=1;
|
1202 |
+
break;
|
1203 |
+
}
|
1204 |
+
}
|
1205 |
+
}else
|
1206 |
+
{
|
1207 |
+
$is_include=1;
|
1208 |
+
break;
|
1209 |
+
}
|
1210 |
+
}
|
1211 |
+
}
|
1212 |
+
return $is_include;
|
1213 |
+
}
|
1214 |
+
}
|
1215 |
+
}
|
admin/modules/import/import.php
ADDED
@@ -0,0 +1,1282 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Import section of the plugin
|
4 |
+
*
|
5 |
+
* @link
|
6 |
+
*
|
7 |
+
* @package Wt_Import_Export_For_Woo
|
8 |
+
*/
|
9 |
+
if (!defined('ABSPATH')) {
|
10 |
+
exit;
|
11 |
+
}
|
12 |
+
|
13 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Basic_Import')){
|
14 |
+
class Wt_Import_Export_For_Woo_Basic_Import
|
15 |
+
{
|
16 |
+
public $module_id='';
|
17 |
+
public static $module_id_static='';
|
18 |
+
public $module_base='import';
|
19 |
+
|
20 |
+
public static $import_dir=WP_CONTENT_DIR.'/webtoffee_import';
|
21 |
+
public static $import_dir_name='/webtoffee_import';
|
22 |
+
public $steps=array();
|
23 |
+
public $allowed_import_file_type=array();
|
24 |
+
public $max_import_file_size=10; //in MB
|
25 |
+
|
26 |
+
private $to_import_id='';
|
27 |
+
private $to_import='';
|
28 |
+
private $rerun_id=0;
|
29 |
+
public $import_method='';
|
30 |
+
public $import_methods=array();
|
31 |
+
public $selected_template=0;
|
32 |
+
public $default_batch_count=0; /* configure this value in `advanced_setting_fields` method */
|
33 |
+
public $selected_template_data=array();
|
34 |
+
public $default_import_method=''; /* configure this value in `advanced_setting_fields` method */
|
35 |
+
public $form_data=array();
|
36 |
+
public $temp_import_file='';
|
37 |
+
private $to_process='';
|
38 |
+
|
39 |
+
public function __construct()
|
40 |
+
{
|
41 |
+
$this->module_id=Wt_Import_Export_For_Woo_Basic::get_module_id($this->module_base);
|
42 |
+
self::$module_id_static=$this->module_id;
|
43 |
+
|
44 |
+
$this->max_import_file_size=wp_max_upload_size()/1000000; //in MB
|
45 |
+
|
46 |
+
/* allowed file types */
|
47 |
+
$this->allowed_import_file_type=array(
|
48 |
+
'csv'=>__('CSV'),
|
49 |
+
);
|
50 |
+
$this->allowed_import_file_type_mime=array(
|
51 |
+
'csv'=>'text/csv',
|
52 |
+
);
|
53 |
+
|
54 |
+
/* default step list */
|
55 |
+
$this->steps=array(
|
56 |
+
'post_type'=>array(
|
57 |
+
'title'=>__('Select post type'),
|
58 |
+
'description'=>__('Import the respective post type from a CSV. As a first step you need to choose the post type to start the import.'),
|
59 |
+
),
|
60 |
+
'method_import'=>array(
|
61 |
+
'title'=>__('Select import method'),
|
62 |
+
'description'=>__('Choose from the options below to continue with your import: quick import, based on a pre-saved template or a new import with advanced options.'),
|
63 |
+
),
|
64 |
+
'mapping'=>array(
|
65 |
+
'title'=>__('Map and reorder import columns'),
|
66 |
+
'description'=>__('Map the standard columns with your CSV column names.'),
|
67 |
+
),
|
68 |
+
'advanced'=>array(
|
69 |
+
'title'=>__('Advanced options/Batch import'),
|
70 |
+
'description'=>__('Use advanced options from below to decide on the delimiter options, updates to existing products, batch import count or schedule an import. You can also save the template file for future imports.'),
|
71 |
+
),
|
72 |
+
);
|
73 |
+
|
74 |
+
$this->import_methods=array(
|
75 |
+
'quick'=>array('title'=>__('Quick import'), 'description'=> __('Use this option primarily when your input file was exported using the same plugin.')),
|
76 |
+
'template'=>array('title'=>__('Pre-saved template'), 'description'=> __('Using a pre-saved template retains the previous filter criteria and other column specifications as per the chosen file and imports data accordingly.')),
|
77 |
+
'new'=>array('title'=>__('Advanced Import'), 'description'=> __('This option will take you through the entire process of filtering/column selection/advanced options that may be required for your import. You can also save your selections as a template for future use.')),
|
78 |
+
);
|
79 |
+
|
80 |
+
$this->step_need_validation_filter=array('method_import', 'mapping', 'advanced');
|
81 |
+
|
82 |
+
/* advanced plugin settings */
|
83 |
+
add_filter('wt_iew_advanced_setting_fields_basic', array($this, 'advanced_setting_fields'));
|
84 |
+
|
85 |
+
/* setting default values this method must be below of advanced setting filter */
|
86 |
+
$this->get_defaults();
|
87 |
+
|
88 |
+
/* main ajax hook. The callback function will decide which is to execute. */
|
89 |
+
add_action('wp_ajax_iew_import_ajax_basic', array($this, 'ajax_main'), 11);
|
90 |
+
|
91 |
+
/* Admin menu for import */
|
92 |
+
add_filter('wt_iew_admin_menu_basic', array($this, 'add_admin_pages'), 10, 1);
|
93 |
+
|
94 |
+
}
|
95 |
+
|
96 |
+
public function get_defaults()
|
97 |
+
{
|
98 |
+
$this->default_import_method= Wt_Import_Export_For_Woo_Basic_Common_Helper::get_advanced_settings('default_import_method');
|
99 |
+
$this->default_batch_count=Wt_Import_Export_For_Woo_Basic_Common_Helper::get_advanced_settings('default_import_batch');
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* Fields for advanced settings
|
104 |
+
*
|
105 |
+
*/
|
106 |
+
public function advanced_setting_fields($fields)
|
107 |
+
{
|
108 |
+
$fields['enable_import_log']=array(
|
109 |
+
'label'=>__("Save Import log"),
|
110 |
+
'type'=>'radio',
|
111 |
+
'radio_fields'=>array(
|
112 |
+
1=>__('Yes'),
|
113 |
+
0=>__('No')
|
114 |
+
),
|
115 |
+
'value' =>1,
|
116 |
+
'field_name'=>'enable_import_log',
|
117 |
+
'field_group'=>'advanced_field',
|
118 |
+
'help_text'=>__('Save import log as text file and make it available in the history section.'),
|
119 |
+
'validation_rule'=>array('type'=>'absint'),
|
120 |
+
);
|
121 |
+
$import_methods=array_map(function($vl){ return $vl['title']; }, $this->import_methods);
|
122 |
+
$fields['default_import_method']=array(
|
123 |
+
'label'=>__("Default Import method"),
|
124 |
+
'type'=>'select',
|
125 |
+
'sele_vals'=>$import_methods,
|
126 |
+
'value' =>'quick',
|
127 |
+
'field_name'=>'default_import_method',
|
128 |
+
'field_group'=>'advanced_field',
|
129 |
+
'help_text'=>__('Select the default method of import.'),
|
130 |
+
);
|
131 |
+
$fields['default_import_batch']=array(
|
132 |
+
'label'=>__("Default Import batch count"),
|
133 |
+
'type'=>'number',
|
134 |
+
'value' =>100, /* If altering then please also change batch count field help text section */
|
135 |
+
'field_name'=>'default_import_batch',
|
136 |
+
'help_text'=>__('Provide the default count for the records to be imported in a batch.'),
|
137 |
+
'validation_rule'=>array('type'=>'absint'),
|
138 |
+
);
|
139 |
+
return $fields;
|
140 |
+
}
|
141 |
+
|
142 |
+
/**
|
143 |
+
* Fields for Import advanced step
|
144 |
+
*/
|
145 |
+
public function get_advanced_screen_fields($advanced_form_data)
|
146 |
+
{
|
147 |
+
$advanced_screen_fields=array(
|
148 |
+
|
149 |
+
'batch_count'=>array(
|
150 |
+
'label'=>__("Import in batches of"),
|
151 |
+
'type'=>'text',
|
152 |
+
'value'=>$this->default_batch_count,
|
153 |
+
'field_name'=>'batch_count',
|
154 |
+
'help_text'=>sprintf(__('The number of records that the server will process for every iteration within the configured timeout interval. If the import fails you can lower this number accordingly and try again. Defaulted to %d records.'), 100),
|
155 |
+
'validation_rule'=>array('type'=>'absint'),
|
156 |
+
)
|
157 |
+
);
|
158 |
+
|
159 |
+
/* taking advanced fields from post type modules */
|
160 |
+
$advanced_screen_fields=apply_filters('wt_iew_importer_alter_advanced_fields_basic', $advanced_screen_fields, $this->to_import, $advanced_form_data);
|
161 |
+
return $advanced_screen_fields;
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* Fields for Import method step
|
166 |
+
*/
|
167 |
+
public function get_method_import_screen_fields($method_import_form_data)
|
168 |
+
{
|
169 |
+
$file_from_arr=array(
|
170 |
+
'local'=>__('Local'),
|
171 |
+
);
|
172 |
+
|
173 |
+
/* taking available remote adapters */
|
174 |
+
$remote_adapter_names=array();
|
175 |
+
$remote_adapter_names=apply_filters('wt_iew_importer_remote_adapter_names_basic', $remote_adapter_names);
|
176 |
+
if($remote_adapter_names && is_array($remote_adapter_names))
|
177 |
+
{
|
178 |
+
foreach($remote_adapter_names as $remote_adapter_key => $remote_adapter_vl)
|
179 |
+
{
|
180 |
+
$file_from_arr[$remote_adapter_key]=$remote_adapter_vl;
|
181 |
+
}
|
182 |
+
}
|
183 |
+
|
184 |
+
//prepare file from field type based on remote type adapters
|
185 |
+
$file_from_field_arr=array(
|
186 |
+
'label'=>__("Choose file for Import"),
|
187 |
+
'type'=>'select',
|
188 |
+
'tr_class'=>'wt-iew-import-method-options wt-iew-import-method-options-quick wt-iew-import-method-options-new',
|
189 |
+
'sele_vals'=>$file_from_arr,
|
190 |
+
'field_name'=>'file_from',
|
191 |
+
'default_value'=>'local',
|
192 |
+
'form_toggler'=>array(
|
193 |
+
'type'=>'parent',
|
194 |
+
'target'=>'wt_iew_file_from'
|
195 |
+
)
|
196 |
+
);
|
197 |
+
|
198 |
+
|
199 |
+
$method_import_screen_fields=array(
|
200 |
+
'file_from'=>$file_from_field_arr,
|
201 |
+
'local_file'=>array(
|
202 |
+
'label'=>__("Select a file"),
|
203 |
+
'type'=>'dropzone',
|
204 |
+
'merge_left'=>true,
|
205 |
+
'merge_right'=>true,
|
206 |
+
'tr_id'=>'local_file_tr',
|
207 |
+
'tr_class'=>$file_from_field_arr['tr_class'], //add tr class from parent.Because we need to toggle the tr when parent tr toggles.
|
208 |
+
'field_name'=>'local_file',
|
209 |
+
'html_id'=>'local_file',
|
210 |
+
'form_toggler'=>array(
|
211 |
+
'type'=>'child',
|
212 |
+
'id'=>'wt_iew_file_from',
|
213 |
+
'val'=>'local',
|
214 |
+
),
|
215 |
+
),
|
216 |
+
|
217 |
+
);
|
218 |
+
|
219 |
+
/* taking import_method fields from other modules */
|
220 |
+
$method_import_screen_fields=apply_filters('wt_iew_importer_alter_method_import_fields_basic', $method_import_screen_fields, $this->to_import, $method_import_form_data);
|
221 |
+
|
222 |
+
|
223 |
+
$method_import_screen_fields['delimiter']=array(
|
224 |
+
'label'=>__("Delimiter"),
|
225 |
+
'type'=>'select',
|
226 |
+
'value'=>",",
|
227 |
+
'css_class'=>"wt_iew_delimiter_preset",
|
228 |
+
'tr_id'=>'delimiter_tr',
|
229 |
+
'tr_class'=>$file_from_field_arr['tr_class'], //add tr class from parent.Because we need to toggle the tr when parent tr toggles.
|
230 |
+
'field_name'=>'delimiter_preset',
|
231 |
+
'sele_vals'=>Wt_Iew_IE_Basic_Helper::_get_csv_delimiters(),
|
232 |
+
'help_text'=>__('Only applicable for CSV imports in order to separate the columns in the CSV file. Takes comma(,) by default.'),
|
233 |
+
'validation_rule'=>array('type'=>'skip'),
|
234 |
+
'after_form_field'=>'<input type="text" class="wt_iew_custom_delimiter" name="wt_iew_delimiter" value="," />',
|
235 |
+
);
|
236 |
+
|
237 |
+
|
238 |
+
|
239 |
+
return $method_import_screen_fields;
|
240 |
+
}
|
241 |
+
|
242 |
+
/**
|
243 |
+
* Adding admin menus
|
244 |
+
*/
|
245 |
+
public function add_admin_pages($menus)
|
246 |
+
{
|
247 |
+
$first = array_slice($menus, 0, 3, true);
|
248 |
+
$last=array_slice($menus, 3, (count($menus)-1), true);
|
249 |
+
|
250 |
+
$menu=array(
|
251 |
+
$this->module_base=>array(
|
252 |
+
'submenu',
|
253 |
+
WT_IEW_PLUGIN_ID_BASIC,
|
254 |
+
__('Import'),
|
255 |
+
__('Import'),
|
256 |
+
'manage_options',
|
257 |
+
$this->module_id,
|
258 |
+
array($this, 'admin_settings_page')
|
259 |
+
)
|
260 |
+
);
|
261 |
+
|
262 |
+
$menus=array_merge($first, $menu, $last);
|
263 |
+
return $menus;
|
264 |
+
}
|
265 |
+
|
266 |
+
/**
|
267 |
+
* Import page
|
268 |
+
*/
|
269 |
+
public function admin_settings_page()
|
270 |
+
{
|
271 |
+
/**
|
272 |
+
* Check it is a rerun call
|
273 |
+
*/
|
274 |
+
$requested_rerun_id=(isset($_GET['wt_iew_rerun']) ? absint($_GET['wt_iew_rerun']) : 0);
|
275 |
+
$this->_process_rerun($requested_rerun_id);
|
276 |
+
|
277 |
+
if($this->rerun_id>0) /* this is a rerun request. Then validate the file */
|
278 |
+
{
|
279 |
+
$response=$this->download_remote_file($this->form_data);
|
280 |
+
if($response['response']) /* temp file created. */
|
281 |
+
{
|
282 |
+
$this->temp_import_file=$response['file_name'];
|
283 |
+
|
284 |
+
/* delete temp files other than the current temp file of same rerun id, if exists */
|
285 |
+
$file_path=$this->get_file_path();
|
286 |
+
$temp_files = glob($file_path.'/rerun_'.$this->rerun_id.'_*');
|
287 |
+
if(count($temp_files)>1) /* Other than the current temp file */
|
288 |
+
{
|
289 |
+
foreach($temp_files as $key => $temp_file)
|
290 |
+
{
|
291 |
+
if(basename($temp_file)!=$this->temp_import_file)
|
292 |
+
{
|
293 |
+
@unlink($temp_file); //delete it
|
294 |
+
}
|
295 |
+
}
|
296 |
+
}
|
297 |
+
|
298 |
+
}else /* unable to create temp file, then abort the rerun request */
|
299 |
+
{
|
300 |
+
$this->rerun_id=0;
|
301 |
+
$this->form_data=array();
|
302 |
+
}
|
303 |
+
}
|
304 |
+
$this->enqueue_assets();
|
305 |
+
include plugin_dir_path(__FILE__).'views/main.php';
|
306 |
+
}
|
307 |
+
|
308 |
+
|
309 |
+
/**
|
310 |
+
* Validating and Processing rerun action
|
311 |
+
*/
|
312 |
+
protected function _process_rerun($rerun_id)
|
313 |
+
{
|
314 |
+
if($rerun_id>0)
|
315 |
+
{
|
316 |
+
/* check the history module is available */
|
317 |
+
$history_module_obj=Wt_Import_Export_For_Woo_Basic::load_modules('history');
|
318 |
+
if(!is_null($history_module_obj))
|
319 |
+
{
|
320 |
+
/* check the history entry is for import and also has form_data */
|
321 |
+
$history_data=$history_module_obj->get_history_entry_by_id($rerun_id);
|
322 |
+
if($history_data && $history_data['template_type']==$this->module_base)
|
323 |
+
{
|
324 |
+
$form_data=maybe_unserialize($history_data['data']);
|
325 |
+
if($form_data && is_array($form_data))
|
326 |
+
{
|
327 |
+
$this->to_import=(isset($form_data['post_type_form_data']) && isset($form_data['post_type_form_data']['item_type']) ? $form_data['post_type_form_data']['item_type'] : '');
|
328 |
+
if($this->to_import!="")
|
329 |
+
{
|
330 |
+
$this->import_method=(isset($form_data['method_import_form_data']) && isset($form_data['method_import_form_data']['method_import']) && $form_data['method_import_form_data']['method_import']!="" ? $form_data['method_import_form_data']['method_import'] : $this->default_import_method);
|
331 |
+
$this->rerun_id=$rerun_id;
|
332 |
+
$this->form_data=$form_data;
|
333 |
+
//process steps based on the import method in the history entry
|
334 |
+
$this->get_steps();
|
335 |
+
|
336 |
+
return true;
|
337 |
+
}
|
338 |
+
}
|
339 |
+
}
|
340 |
+
}
|
341 |
+
}
|
342 |
+
return false;
|
343 |
+
}
|
344 |
+
|
345 |
+
protected function enqueue_assets()
|
346 |
+
{
|
347 |
+
if(Wt_Import_Export_For_Woo_Basic_Common_Helper::wt_is_screen_allowed()){
|
348 |
+
/* adding dropzone JS */
|
349 |
+
wp_enqueue_script(WT_IEW_PLUGIN_ID_BASIC.'-dropzone', WT_O_IEW_PLUGIN_URL.'admin/js/dropzone.min.js', array('jquery'), WT_O_IEW_VERSION);
|
350 |
+
|
351 |
+
wp_enqueue_script($this->module_id, plugin_dir_url(__FILE__).'assets/js/main.js', array('jquery', 'jquery-ui-sortable', 'jquery-ui-datepicker'), WT_O_IEW_VERSION);
|
352 |
+
wp_enqueue_style('jquery-ui-datepicker');
|
353 |
+
//wp_enqueue_media();
|
354 |
+
|
355 |
+
wp_enqueue_style(WT_IEW_PLUGIN_ID_BASIC.'-jquery-ui', WT_O_IEW_PLUGIN_URL.'admin/css/jquery-ui.css', array(), WT_O_IEW_VERSION, 'all');
|
356 |
+
|
357 |
+
$file_extensions=array_keys($this->allowed_import_file_type_mime);
|
358 |
+
$file_extensions=array_map(function($vl){
|
359 |
+
return '.'.$vl;
|
360 |
+
}, $file_extensions);
|
361 |
+
|
362 |
+
$params=array(
|
363 |
+
'item_type'=>'',
|
364 |
+
'steps'=>$this->steps,
|
365 |
+
'rerun_id'=>$this->rerun_id,
|
366 |
+
'to_import'=>$this->to_import,
|
367 |
+
'import_method'=>$this->import_method,
|
368 |
+
'temp_import_file'=>$this->temp_import_file,
|
369 |
+
'allowed_import_file_type_mime'=>$file_extensions,
|
370 |
+
'max_import_file_size'=>$this->max_import_file_size,
|
371 |
+
'msgs'=>array(
|
372 |
+
'choosed_template'=>__('Choosed template: '),
|
373 |
+
'choose_import_method'=>__('Please select an import method.'),
|
374 |
+
'choose_template'=>__('Please select an import template.'),
|
375 |
+
'step'=>__('Step'),
|
376 |
+
'choose_ftp_profile'=>__('Please select an FTP profile.'),
|
377 |
+
'choose_import_from'=>__('Please choose import from.'),
|
378 |
+
'choose_a_file'=>__('Please choose an import file.'),
|
379 |
+
'select_an_import_template'=>__('Please select an import template.'),
|
380 |
+
'validating_file'=>__('Creating temp file and validating.'),
|
381 |
+
'processing_file'=>__('Processing input file...'),
|
382 |
+
'column_not_in_the_list'=>__('This column is not present in the import list. Please tick the checkbox to include.'),
|
383 |
+
'uploading'=>__('Uploading...'),
|
384 |
+
'outdated'=>__('You are using an outdated browser. Please upgarde your browser.'),
|
385 |
+
'server_error'=>__('An error occured.'),
|
386 |
+
'invalid_file'=>sprintf(__('Invalid file type. Only %s are allowed'), implode(", ", array_values($this->allowed_import_file_type))),
|
387 |
+
'drop_upload'=>__('Drop files here or click to upload'),
|
388 |
+
'upload_done'=>sprintf(__('%s Done.'), '<span class="dashicons dashicons-yes-alt" style="color:#3fa847;"></span>'),
|
389 |
+
'remove'=>__('Remove'),
|
390 |
+
),
|
391 |
+
);
|
392 |
+
wp_localize_script($this->module_id, 'wt_iew_import_basic_params', $params);
|
393 |
+
|
394 |
+
$this->add_select2_lib(); //adding select2 JS, It checks the availibility of woocommerce
|
395 |
+
}
|
396 |
+
}
|
397 |
+
|
398 |
+
/**
|
399 |
+
*
|
400 |
+
* Enqueue select2 library, if woocommerce available use that
|
401 |
+
*/
|
402 |
+
protected function add_select2_lib()
|
403 |
+
{
|
404 |
+
/* enqueue scripts */
|
405 |
+
if(!function_exists('is_plugin_active'))
|
406 |
+
{
|
407 |
+
include_once(ABSPATH.'wp-admin/includes/plugin.php');
|
408 |
+
}
|
409 |
+
if(is_plugin_active('woocommerce/woocommerce.php'))
|
410 |
+
{
|
411 |
+
wp_enqueue_script('wc-enhanced-select');
|
412 |
+
wp_enqueue_style('woocommerce_admin_styles', WC()->plugin_url().'/assets/css/admin.css');
|
413 |
+
}else
|
414 |
+
{
|
415 |
+
wp_enqueue_style(WT_IEW_PLUGIN_ID_BASIC.'-select2', WT_O_IEW_PLUGIN_URL. 'admin/css/select2.css', array(), WT_O_IEW_VERSION, 'all' );
|
416 |
+
wp_enqueue_script(WT_IEW_PLUGIN_ID_BASIC.'-select2', WT_O_IEW_PLUGIN_URL.'admin/js/select2.js', array('jquery'), WT_O_IEW_VERSION, false );
|
417 |
+
}
|
418 |
+
}
|
419 |
+
|
420 |
+
/**
|
421 |
+
* Get steps
|
422 |
+
*
|
423 |
+
*/
|
424 |
+
public function get_steps()
|
425 |
+
{
|
426 |
+
if($this->import_method=='quick') /* if quick import then remove some steps */
|
427 |
+
{
|
428 |
+
$out=array(
|
429 |
+
'post_type'=>$this->steps['post_type'],
|
430 |
+
'method_import'=>$this->steps['method_import'],
|
431 |
+
'advanced'=>$this->steps['advanced'],
|
432 |
+
);
|
433 |
+
$this->steps=$out;
|
434 |
+
}
|
435 |
+
$this->steps=apply_filters('wt_iew_importer_steps_basic', $this->steps, $this->to_import);
|
436 |
+
return $this->steps;
|
437 |
+
}
|
438 |
+
|
439 |
+
/**
|
440 |
+
* Download and save file into web server
|
441 |
+
*
|
442 |
+
*/
|
443 |
+
public function download_remote_file($form_data)
|
444 |
+
{
|
445 |
+
$out=array(
|
446 |
+
'response'=>false,
|
447 |
+
'file_name'=>'',
|
448 |
+
'msg'=>'',
|
449 |
+
);
|
450 |
+
|
451 |
+
$method_import_form_data=(isset($form_data['method_import_form_data']) ? $form_data['method_import_form_data'] : array());
|
452 |
+
$file_from=(isset($method_import_form_data['wt_iew_file_from']) ? Wt_Iew_Sh::sanitize_item($method_import_form_data['wt_iew_file_from']) : '');
|
453 |
+
|
454 |
+
if($file_from=="")
|
455 |
+
{
|
456 |
+
return $out;
|
457 |
+
}
|
458 |
+
if($file_from=='local' || $file_from=='url')
|
459 |
+
{
|
460 |
+
if($file_from=='local')
|
461 |
+
{
|
462 |
+
$file_url=(isset($method_import_form_data['wt_iew_local_file']) ? Wt_Iew_Sh::sanitize_item($method_import_form_data['wt_iew_local_file'], 'url') : '');
|
463 |
+
$local_file_path=Wt_Iew_IE_Basic_Helper::_get_local_file_path($file_url);
|
464 |
+
if(!$local_file_path) /* no local file found */
|
465 |
+
{
|
466 |
+
$file_url='';
|
467 |
+
}
|
468 |
+
}else
|
469 |
+
{
|
470 |
+
$file_url=(isset($method_import_form_data['wt_iew_url_file']) ? Wt_Iew_Sh::sanitize_item($method_import_form_data['wt_iew_url_file'], 'url') : '');
|
471 |
+
}
|
472 |
+
|
473 |
+
if($file_url!="") /* file URL not empty */
|
474 |
+
{
|
475 |
+
if($this->is_extension_allowed($file_url)) /* file type is in allowed list */
|
476 |
+
{
|
477 |
+
$ext_arr=explode('.', $file_url);
|
478 |
+
$ext=end($ext_arr);
|
479 |
+
|
480 |
+
$file_name=$this->get_temp_file_name($ext);
|
481 |
+
$file_path=$this->get_file_path($file_name);
|
482 |
+
if($file_path)
|
483 |
+
{
|
484 |
+
if($file_from=='local')
|
485 |
+
{
|
486 |
+
if(@copy($local_file_path, $file_path))
|
487 |
+
{
|
488 |
+
$out=array(
|
489 |
+
'response'=>true,
|
490 |
+
'file_name'=>$file_name,
|
491 |
+
'msg'=>'',
|
492 |
+
);
|
493 |
+
}else
|
494 |
+
{
|
495 |
+
$out['msg']=__('Unable to create temp file.');
|
496 |
+
}
|
497 |
+
}else
|
498 |
+
{
|
499 |
+
$file_data=$this->remote_get($file_url);
|
500 |
+
|
501 |
+
if(!is_wp_error($file_data) && wp_remote_retrieve_response_code($file_data)==200)
|
502 |
+
{
|
503 |
+
$file_data=wp_remote_retrieve_body($file_data);
|
504 |
+
if(@file_put_contents($file_path, $file_data))
|
505 |
+
{
|
506 |
+
$out=array(
|
507 |
+
'response'=>true,
|
508 |
+
'file_name'=>$file_name,
|
509 |
+
'msg'=>'',
|
510 |
+
);
|
511 |
+
}else
|
512 |
+
{
|
513 |
+
$out['msg']=__('Unable to create temp file.');
|
514 |
+
}
|
515 |
+
}else
|
516 |
+
{
|
517 |
+
$out['msg']=__('Unable to fetch file data.');
|
518 |
+
}
|
519 |
+
}
|
520 |
+
}else
|
521 |
+
{
|
522 |
+
$out['msg']=__('Unable to create temp directory.');
|
523 |
+
}
|
524 |
+
}else
|
525 |
+
{
|
526 |
+
$out['msg']=__('File type not allowed.');
|
527 |
+
}
|
528 |
+
}else
|
529 |
+
{
|
530 |
+
$out['msg']=__('File not found.');
|
531 |
+
}
|
532 |
+
}else
|
533 |
+
{
|
534 |
+
$out['response']=true;
|
535 |
+
$out=apply_filters('wt_iew_validate_file_basic', $out, $file_from, $method_import_form_data);
|
536 |
+
|
537 |
+
if(is_array($out) && isset($out['response']) && $out['response']) /* a form validation hook for remote modules */
|
538 |
+
{
|
539 |
+
$remote_adapter=Wt_Import_Export_For_Woo_Basic::get_remote_adapters('import', $file_from);
|
540 |
+
|
541 |
+
if(is_null($remote_adapter)) /* adapter object not found */
|
542 |
+
{
|
543 |
+
$msg=sprintf('Unable to initailize %s', $file_from);
|
544 |
+
$out['msg']=__($msg);
|
545 |
+
$out['response']=false;
|
546 |
+
}else
|
547 |
+
{
|
548 |
+
/* download the file */
|
549 |
+
$out = $remote_adapter->download($method_import_form_data, $out, $this);
|
550 |
+
}
|
551 |
+
}
|
552 |
+
}
|
553 |
+
if($out['response']!==false)
|
554 |
+
{
|
555 |
+
$file_path=self::get_file_path($out['file_name']);
|
556 |
+
/**
|
557 |
+
* Filter to modify the import file before processing.
|
558 |
+
* @param string $file_name name of the file
|
559 |
+
* @param string $file_path path of the file
|
560 |
+
* @return string $file_name name of the new altered file
|
561 |
+
*/
|
562 |
+
$out['file_name']=apply_filters('wt_iew_alter_import_file_basic', $out['file_name'], $file_path);
|
563 |
+
}
|
564 |
+
|
565 |
+
return $out;
|
566 |
+
}
|
567 |
+
|
568 |
+
public function remote_get($target_url)
|
569 |
+
{
|
570 |
+
global $wp_version;
|
571 |
+
|
572 |
+
$def_args = array(
|
573 |
+
'timeout' => 5,
|
574 |
+
'redirection' => 5,
|
575 |
+
'httpversion' => '1.0',
|
576 |
+
'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url(),
|
577 |
+
'blocking' => true,
|
578 |
+
'headers' => array(),
|
579 |
+
'cookies' => array(),
|
580 |
+
'body' => null,
|
581 |
+
'compress' => false,
|
582 |
+
'decompress' => true,
|
583 |
+
'sslverify' => false,
|
584 |
+
'stream' => false,
|
585 |
+
'filename' => null
|
586 |
+
);
|
587 |
+
return wp_remote_get($target_url, $def_args);
|
588 |
+
}
|
589 |
+
|
590 |
+
public function get_log_file_name($history_id)
|
591 |
+
{
|
592 |
+
return 'log_'.$history_id.'.log';
|
593 |
+
}
|
594 |
+
|
595 |
+
public function get_temp_file_name($ext)
|
596 |
+
{
|
597 |
+
/* adding rerun prefix is to easily identify rerun temp files */
|
598 |
+
$rerun_prefix=($this->rerun_id>0 ? 'rerun_'.$this->rerun_id.'_' : '');
|
599 |
+
return $rerun_prefix.'temp_'.$this->to_import.'_'.time().'.'.$ext;
|
600 |
+
}
|
601 |
+
|
602 |
+
/**
|
603 |
+
* Get given file url.
|
604 |
+
* If file name is empty then URL will return
|
605 |
+
*/
|
606 |
+
public static function get_file_url($file_name="")
|
607 |
+
{
|
608 |
+
return WP_CONTENT_URL.self::$import_dir_name.'/'.$file_name;
|
609 |
+
}
|
610 |
+
|
611 |
+
/**
|
612 |
+
* Checks the file extension is in allowed list
|
613 |
+
* @param string File name/ URL
|
614 |
+
* @return boolean
|
615 |
+
*/
|
616 |
+
public function is_extension_allowed($file_url)
|
617 |
+
{
|
618 |
+
$ext_arr=explode('.', $file_url);
|
619 |
+
$ext=strtolower(end($ext_arr));
|
620 |
+
if(isset($this->allowed_import_file_type[$ext])) /* file type is in allowed list */
|
621 |
+
{
|
622 |
+
return true;
|
623 |
+
}
|
624 |
+
return false;
|
625 |
+
}
|
626 |
+
|
627 |
+
/**
|
628 |
+
* Delete import file
|
629 |
+
* @param string File path/ URL
|
630 |
+
* @return boolean
|
631 |
+
*/
|
632 |
+
public function delete_import_file($file_url)
|
633 |
+
{
|
634 |
+
$file_path_arr=explode("/", $file_url);
|
635 |
+
$file_name=end($file_path_arr);
|
636 |
+
$file_path=$this->get_file_path($file_name);
|
637 |
+
if(file_exists($file_path))
|
638 |
+
{
|
639 |
+
if($this->is_extension_allowed($file_url))/* file type is in allowed list */
|
640 |
+
{
|
641 |
+
@unlink($file_path);
|
642 |
+
return true;
|
643 |
+
}
|
644 |
+
}
|
645 |
+
return false;
|
646 |
+
}
|
647 |
+
|
648 |
+
/**
|
649 |
+
* Get given temp file path.
|
650 |
+
* If file name is empty then file path will return
|
651 |
+
*/
|
652 |
+
public static function get_file_path($file_name="")
|
653 |
+
{
|
654 |
+
if(!is_dir(self::$import_dir))
|
655 |
+
{
|
656 |
+
if(!mkdir(self::$import_dir, 0700))
|
657 |
+
{
|
658 |
+
return false;
|
659 |
+
}else
|
660 |
+
{
|
661 |
+
$files_to_create=array('.htaccess' => 'deny from all', 'index.php'=>'<?php // Silence is golden');
|
662 |
+
foreach($files_to_create as $file=>$file_content)
|
663 |
+
{
|
664 |
+
if(!file_exists(self::$import_dir.'/'.$file))
|
665 |
+
{
|
666 |
+
$fh=@fopen(self::$import_dir.'/'.$file, "w");
|
667 |
+
if(is_resource($fh))
|
668 |
+
{
|
669 |
+
fwrite($fh, $file_content);
|
670 |
+
fclose($fh);
|
671 |
+
}
|
672 |
+
}
|
673 |
+
}
|
674 |
+
}
|
675 |
+
}
|
676 |
+
return self::$import_dir.'/'.$file_name;
|
677 |
+
}
|
678 |
+
|
679 |
+
/**
|
680 |
+
* Download and create a temp file. And create a history entry
|
681 |
+
* @param string $step the action to perform, here 'download'
|
682 |
+
*
|
683 |
+
* @return array
|
684 |
+
*/
|
685 |
+
public function process_download($form_data, $step, $to_process, $import_id=0, $offset=0)
|
686 |
+
{
|
687 |
+
$out=array(
|
688 |
+
'response'=>false,
|
689 |
+
'new_offset'=>0,
|
690 |
+
'import_id'=>0,
|
691 |
+
'history_id'=>0, //same as that of import id
|
692 |
+
'total_records'=>0,
|
693 |
+
'finished'=>0,
|
694 |
+
'msg'=>'',
|
695 |
+
);
|
696 |
+
$this->to_import=$to_process;
|
697 |
+
|
698 |
+
if($import_id>0)
|
699 |
+
{
|
700 |
+
//take history data by import_id
|
701 |
+
$import_data=Wt_Import_Export_For_Woo_Basic_History::get_history_entry_by_id($import_id);
|
702 |
+
if(is_null($import_data)) //no record found so it may be an error
|
703 |
+
{
|
704 |
+
return $out;
|
705 |
+
}else
|
706 |
+
{
|
707 |
+
$file_name=(isset($import_data['file_name']) ? $import_data['file_name'] : '');
|
708 |
+
$file_path=$this->get_file_path($file_name);
|
709 |
+
if($file_path && file_exists($file_path))
|
710 |
+
{
|
711 |
+
$this->temp_import_file=$file_name;
|
712 |
+
}else
|
713 |
+
{
|
714 |
+
$msg='Error occurred while processing the file';
|
715 |
+
Wt_Import_Export_For_Woo_Basic_History::record_failure($import_id, $msg);
|
716 |
+
$out['msg']=__($msg);
|
717 |
+
return $out;
|
718 |
+
}
|
719 |
+
}
|
720 |
+
}else
|
721 |
+
{
|
722 |
+
if($offset==0)
|
723 |
+
{
|
724 |
+
if($this->temp_import_file!="") /* its a non schedule import */
|
725 |
+
{
|
726 |
+
$file_path=$this->get_file_path($this->temp_import_file);
|
727 |
+
if($file_path && file_exists($file_path))
|
728 |
+
{
|
729 |
+
if($this->is_extension_allowed($this->temp_import_file)) /* file type is in allowed list */
|
730 |
+
{
|
731 |
+
$import_id=Wt_Import_Export_For_Woo_Basic_History::create_history_entry('', $form_data, $to_process, 'import');
|
732 |
+
}else
|
733 |
+
{
|
734 |
+
return $out;
|
735 |
+
}
|
736 |
+
}else
|
737 |
+
{
|
738 |
+
$out['msg']=__('Temp file missing.');
|
739 |
+
return $out;
|
740 |
+
}
|
741 |
+
}else /* in scheduled import need to prepare the temp file */
|
742 |
+
{
|
743 |
+
$import_id=Wt_Import_Export_For_Woo_Basic_History::create_history_entry('', $form_data, $to_process, 'import');
|
744 |
+
$response=$this->download_remote_file($form_data);
|
745 |
+
|
746 |
+
if(!$response['response']) /* not validated successfully */
|
747 |
+
{
|
748 |
+
Wt_Import_Export_For_Woo_Basic_History::record_failure($import_id, $response['msg']);
|
749 |
+
$out['msg']=$response['msg'];
|
750 |
+
return $out;
|
751 |
+
}else
|
752 |
+
{
|
753 |
+
$file_path=$this->get_file_path($response['file_name']);
|
754 |
+
$this->temp_import_file=$response['file_name'];
|
755 |
+
}
|
756 |
+
}
|
757 |
+
}
|
758 |
+
}
|
759 |
+
|
760 |
+
/**
|
761 |
+
* In XML import we need to convert the file into CSV before processing
|
762 |
+
* It may be a batched processing for larger files
|
763 |
+
*/
|
764 |
+
$ext_arr=explode('.', $this->temp_import_file);
|
765 |
+
|
766 |
+
$out=$this->_set_import_file_processing_finished($file_path, $import_id);
|
767 |
+
return $out;
|
768 |
+
}
|
769 |
+
|
770 |
+
/**
|
771 |
+
* If the file type is not CSV (Eg: XML) Then the delimiter must be ",".
|
772 |
+
* Because we are converting XML to CSV
|
773 |
+
*
|
774 |
+
*/
|
775 |
+
protected function _set_csv_delimiter($form_data, $import_id)
|
776 |
+
{
|
777 |
+
$form_data['method_import_form_data']['wt_iew_delimiter']=",";
|
778 |
+
|
779 |
+
$update_data=array(
|
780 |
+
'data'=>maybe_serialize($form_data), //formadata
|
781 |
+
);
|
782 |
+
$update_data_type=array(
|
783 |
+
'%s',
|
784 |
+
);
|
785 |
+
Wt_Import_Export_For_Woo_Basic_History::update_history_entry($import_id, $update_data, $update_data_type);
|
786 |
+
|
787 |
+
return $form_data;
|
788 |
+
}
|
789 |
+
|
790 |
+
protected function _set_import_file_processing_finished($file_path, $import_id)
|
791 |
+
{
|
792 |
+
/* update total records, temp file name in history table */
|
793 |
+
$total_records=filesize($file_path); /* in this case we cannot count number of rows */
|
794 |
+
$update_data=array(
|
795 |
+
'total'=>$total_records,
|
796 |
+
'file_name'=>$this->temp_import_file,
|
797 |
+
);
|
798 |
+
$update_data_type=array(
|
799 |
+
'%d',
|
800 |
+
'%s',
|
801 |
+
);
|
802 |
+
Wt_Import_Export_For_Woo_Basic_History::update_history_entry($import_id, $update_data, $update_data_type);
|
803 |
+
|
804 |
+
return array(
|
805 |
+
'response'=>true,
|
806 |
+
'finished'=>3,
|
807 |
+
'import_id'=>$import_id,
|
808 |
+
'history_id'=>$import_id, //same as that of import id
|
809 |
+
'total_records'=>$total_records,
|
810 |
+
'temp_import_file'=>$this->temp_import_file,
|
811 |
+
'msg'=>sprintf(__('Importing...(%d processed)'), 0),
|
812 |
+
);
|
813 |
+
}
|
814 |
+
|
815 |
+
|
816 |
+
/**
|
817 |
+
* Do the import process
|
818 |
+
*/
|
819 |
+
public function process_action($form_data, $step, $to_process, $file_name='', $import_id=0, $offset=0)
|
820 |
+
{
|
821 |
+
$out=array(
|
822 |
+
'response'=>false,
|
823 |
+
'new_offset'=>0,
|
824 |
+
'import_id'=>0,
|
825 |
+
'history_id'=>0, //same as that of import id
|
826 |
+
'total_records'=>0,
|
827 |
+
'offset_count'=>0,
|
828 |
+
'finished'=>0,
|
829 |
+
'msg'=>'',
|
830 |
+
'total_success'=>0,
|
831 |
+
'total_failed'=>0,
|
832 |
+
);
|
833 |
+
|
834 |
+
$this->to_import=$to_process;
|
835 |
+
$this->to_process=$to_process;
|
836 |
+
|
837 |
+
/* prepare formdata, If this was not first batch */
|
838 |
+
if($import_id>0)
|
839 |
+
{
|
840 |
+
//take history data by import_id
|
841 |
+
$import_data=Wt_Import_Export_For_Woo_Basic_History::get_history_entry_by_id($import_id);
|
842 |
+
if(is_null($import_data)) //no record found so it may be an error
|
843 |
+
{
|
844 |
+
return $out;
|
845 |
+
}
|
846 |
+
|
847 |
+
//processing form data
|
848 |
+
$form_data=(isset($import_data['data']) ? maybe_unserialize($import_data['data']) : array());
|
849 |
+
|
850 |
+
}
|
851 |
+
else // No import id so it may be an error
|
852 |
+
{
|
853 |
+
return $out;
|
854 |
+
}
|
855 |
+
|
856 |
+
/* setting history_id in Log section */
|
857 |
+
Wt_Import_Export_For_Woo_Basic_Log::$history_id=$import_id;
|
858 |
+
|
859 |
+
$file_name=(isset($import_data['file_name']) ? $import_data['file_name'] : '');
|
860 |
+
$file_path=$this->get_file_path($file_name);
|
861 |
+
if($file_path)
|
862 |
+
{
|
863 |
+
if(!file_exists($file_path))
|
864 |
+
{
|
865 |
+
$msg='Temp file missing';
|
866 |
+
//no need to add translation function in message
|
867 |
+
Wt_Import_Export_For_Woo_Basic_History::record_failure($import_id, $msg);
|
868 |
+
$out['msg']=__($msg);
|
869 |
+
return $out;
|
870 |
+
}
|
871 |
+
}else
|
872 |
+
{
|
873 |
+
$msg='Temp file missing';
|
874 |
+
//no need to add translation function in message
|
875 |
+
Wt_Import_Export_For_Woo_Basic_History::record_failure($import_id, $msg);
|
876 |
+
$out['msg']=__($msg);
|
877 |
+
return $out;
|
878 |
+
}
|
879 |
+
|
880 |
+
$default_batch_count=absint(apply_filters('wt_iew_importer_alter_default_batch_count_basic', $this->default_batch_count, $to_process, $form_data));
|
881 |
+
$default_batch_count=($default_batch_count==0 ? $this->default_batch_count : $default_batch_count);
|
882 |
+
|
883 |
+
$batch_count=$default_batch_count;
|
884 |
+
$csv_delimiter=',';
|
885 |
+
$total_records=(isset($import_data['total']) ? $import_data['total'] : 0);
|
886 |
+
$file_ext_arr=explode('.', $file_name);
|
887 |
+
$file_type= strtolower(end($file_ext_arr));
|
888 |
+
$file_type=(isset($this->allowed_import_file_type[$file_type]) ? $file_type : 'csv');
|
889 |
+
|
890 |
+
if(isset($form_data['advanced_form_data']))
|
891 |
+
{
|
892 |
+
$batch_count=(isset($form_data['advanced_form_data']['wt_iew_batch_count']) ? $form_data['advanced_form_data']['wt_iew_batch_count'] : $batch_count);
|
893 |
+
}
|
894 |
+
if(isset($form_data['method_import_form_data']) && $file_type=='csv')
|
895 |
+
{
|
896 |
+
$csv_delimiter=(isset($form_data['method_import_form_data']['wt_iew_delimiter']) ? $form_data['method_import_form_data']['wt_iew_delimiter'] : $csv_delimiter);
|
897 |
+
$csv_delimiter=($csv_delimiter=="" ? ',' : $csv_delimiter);
|
898 |
+
}
|
899 |
+
|
900 |
+
|
901 |
+
|
902 |
+
include_once WT_O_IEW_PLUGIN_PATH.'admin/classes/class-csvreader.php';
|
903 |
+
$reader=new Wt_Import_Export_For_Woo_Basic_Csvreader($csv_delimiter);
|
904 |
+
|
905 |
+
|
906 |
+
/* important: prepare deafult mapping formdata for quick import */
|
907 |
+
$input_data=$reader->get_data_as_batch($file_path, $offset, $batch_count, $this, $form_data);
|
908 |
+
|
909 |
+
if(empty($input_data['data_arr'])){
|
910 |
+
$out['msg']=__('CSV is empty');
|
911 |
+
return $out;
|
912 |
+
}
|
913 |
+
|
914 |
+
if(!$input_data || !is_array($input_data))
|
915 |
+
{
|
916 |
+
$msg='Unable to process the file';
|
917 |
+
//no need to add translation function in message
|
918 |
+
Wt_Import_Export_For_Woo_Basic_History::record_failure($import_id, $msg);
|
919 |
+
$out['msg']=__($msg);
|
920 |
+
return $out;
|
921 |
+
}
|
922 |
+
|
923 |
+
/* checking action is finshed */
|
924 |
+
$is_last_offset=false;
|
925 |
+
$new_offset=$input_data['offset']; //increase the offset
|
926 |
+
if($new_offset>=$total_records) //finished
|
927 |
+
{
|
928 |
+
$is_last_offset=true;
|
929 |
+
}
|
930 |
+
|
931 |
+
/**
|
932 |
+
* In case of non schedule import. Offset row count.
|
933 |
+
* The real internal offset is in bytes, This offset is total row processed.
|
934 |
+
*/
|
935 |
+
$offset_count=(isset($_POST['offset_count']) ? absint($_POST['offset_count']) : 0);
|
936 |
+
|
937 |
+
/* giving full data */
|
938 |
+
$form_data=apply_filters('wt_iew_import_full_form_data_basic', $form_data, $to_process, $step, $this->selected_template_data);
|
939 |
+
|
940 |
+
/* in scheduled import. The import method will not available so we need to take it from formdata */
|
941 |
+
$formdata_import_method=(isset($formdata['method_import_form_data']) && isset($formdata['method_import_form_data']['method_import']) ? $formdata['method_import_form_data']['method_import'] : 'quick');
|
942 |
+
$this->import_method=($this->import_method=="" ? $formdata_import_method : $this->import_method);
|
943 |
+
|
944 |
+
/**
|
945 |
+
* Import response format
|
946 |
+
*/
|
947 |
+
$import_response=array(
|
948 |
+
'total_success'=>$batch_count,
|
949 |
+
'total_failed'=>0,
|
950 |
+
'log_data'=>array(
|
951 |
+
array('row'=>$offset_count, 'message'=>'', 'status'=>true, 'post_id'=>''),
|
952 |
+
),
|
953 |
+
);
|
954 |
+
|
955 |
+
$import_response=apply_filters('wt_iew_importer_do_import_basic', $input_data['data_arr'], $to_process, $step, $form_data, $this->selected_template_data, $this->import_method, $offset_count, $is_last_offset);
|
956 |
+
|
957 |
+
/**
|
958 |
+
* Writing import log to file
|
959 |
+
*/
|
960 |
+
if(!empty($import_response) && is_array($import_response) && Wt_Import_Export_For_Woo_Basic_Common_Helper::get_advanced_settings('enable_import_log')==1)
|
961 |
+
{
|
962 |
+
$log_writer=new Wt_Import_Export_For_Woo_Basic_Logwriter();
|
963 |
+
$log_file_name=$this->get_log_file_name($import_id);
|
964 |
+
$log_file_path=$this->get_file_path($log_file_name);
|
965 |
+
$log_data=(isset($import_response['log_data']) && is_array($import_response['log_data']) ? $import_response['log_data'] : array());
|
966 |
+
$log_writer->write_import_log($log_data, $log_file_path);
|
967 |
+
}
|
968 |
+
|
969 |
+
|
970 |
+
/* updating completed offset */
|
971 |
+
$update_data=array(
|
972 |
+
'offset'=>$offset
|
973 |
+
);
|
974 |
+
$update_data_type=array(
|
975 |
+
'%d'
|
976 |
+
);
|
977 |
+
Wt_Import_Export_For_Woo_Basic_History::update_history_entry($import_id, $update_data, $update_data_type);
|
978 |
+
|
979 |
+
|
980 |
+
/* updating output parameters */
|
981 |
+
$out['total_records']=$total_records;
|
982 |
+
$out['import_id']=$import_id;
|
983 |
+
$out['history_id']=$import_id;
|
984 |
+
$out['response']=true;
|
985 |
+
|
986 |
+
/* In case of non schedule import. total success, totla failed count */
|
987 |
+
$total_success=(isset($_POST['total_success']) ? absint($_POST['total_success']) : 0);
|
988 |
+
$total_failed=(isset($_POST['total_failed']) ? absint($_POST['total_failed']) : 0);
|
989 |
+
|
990 |
+
$out['total_success']=(isset($import_response['total_success']) ? $import_response['total_success'] : 0)+$total_success;
|
991 |
+
$out['total_failed']=(isset($import_response['total_failed']) ? $import_response['total_failed'] : 0)+$total_failed;
|
992 |
+
|
993 |
+
/* updating action is finshed */
|
994 |
+
if($is_last_offset) //finished
|
995 |
+
{
|
996 |
+
/* delete the temp file */
|
997 |
+
@unlink($file_path);
|
998 |
+
|
999 |
+
$log_summary_msg=$this->generate_log_summary($out, $is_last_offset);
|
1000 |
+
|
1001 |
+
$out['finished']=1; //finished
|
1002 |
+
$out['msg']=$log_summary_msg;
|
1003 |
+
|
1004 |
+
/* updating finished status */
|
1005 |
+
$update_data=array(
|
1006 |
+
'status'=>Wt_Import_Export_For_Woo_Basic_History::$status_arr['finished'],
|
1007 |
+
'status_text'=>'Finished' //translation function not needed
|
1008 |
+
);
|
1009 |
+
$update_data_type=array(
|
1010 |
+
'%d',
|
1011 |
+
'%s',
|
1012 |
+
);
|
1013 |
+
Wt_Import_Export_For_Woo_Basic_History::update_history_entry($import_id, $update_data, $update_data_type);
|
1014 |
+
}else
|
1015 |
+
{
|
1016 |
+
$rows_processed=$input_data['rows_processed'];
|
1017 |
+
$total_processed=$rows_processed+$offset_count;
|
1018 |
+
|
1019 |
+
$out['offset_count']=$total_processed;
|
1020 |
+
$out['new_offset']=$new_offset;
|
1021 |
+
|
1022 |
+
$log_summary_msg=$this->generate_log_summary($out, $is_last_offset);
|
1023 |
+
|
1024 |
+
$out['msg']=$log_summary_msg;
|
1025 |
+
}
|
1026 |
+
|
1027 |
+
return $out;
|
1028 |
+
}
|
1029 |
+
|
1030 |
+
protected function generate_log_summary($data, $is_last_offset)
|
1031 |
+
{
|
1032 |
+
if($is_last_offset)
|
1033 |
+
{
|
1034 |
+
$msg='<span class="wt_iew_info_box_title">'.__('Finished').'</span>';
|
1035 |
+
}else
|
1036 |
+
{
|
1037 |
+
$msg='<span class="wt_iew_info_box_title">'.sprintf(__('Importing...(%d processed)'), $data['offset_count']).'</span>';
|
1038 |
+
}
|
1039 |
+
$msg.='<br />'.__('Total success: ').$data['total_success'].'<br />'.__('Total failed: ').$data['total_failed'];
|
1040 |
+
if($is_last_offset)
|
1041 |
+
{
|
1042 |
+
$msg.='<span class="wt_iew_info_box_finished_text">';
|
1043 |
+
if(Wt_Import_Export_For_Woo_Admin_Basic::module_exists('history'))
|
1044 |
+
{
|
1045 |
+
$history_module_id=Wt_Import_Export_For_Woo_Basic::get_module_id('history');
|
1046 |
+
$history_page_url=admin_url('admin.php?page='.$history_module_id);
|
1047 |
+
$msg.='<br />'.sprintf(__('View detailed log from %s History %s section'), '<a href="'.$history_page_url.'" target="_blank">', '</a>');
|
1048 |
+
}
|
1049 |
+
$msg.='<br /><a class="button button-secondary" style="margin-top:5px;" onclick="wt_iew_basic_import.hide_import_info_box();">'.__('Close').'</a></span>';
|
1050 |
+
}
|
1051 |
+
return $msg;
|
1052 |
+
}
|
1053 |
+
|
1054 |
+
/**
|
1055 |
+
* Main ajax hook to handle all import related requests
|
1056 |
+
*/
|
1057 |
+
public function ajax_main()
|
1058 |
+
{
|
1059 |
+
include_once plugin_dir_path(__FILE__).'classes/class-import-ajax.php';
|
1060 |
+
if(Wt_Iew_Sh::check_write_access(WT_IEW_PLUGIN_ID_BASIC))
|
1061 |
+
{
|
1062 |
+
/**
|
1063 |
+
* Check it is a rerun call
|
1064 |
+
*/
|
1065 |
+
if(!$this->_process_rerun((isset($_POST['rerun_id']) ? absint($_POST['rerun_id']) : 0)))
|
1066 |
+
{
|
1067 |
+
$this->import_method=(isset($_POST['import_method']) ? Wt_Iew_Sh::sanitize_item($_POST['import_method'], 'text') : '');
|
1068 |
+
$this->to_import=(isset($_POST['to_import']) ? Wt_Iew_Sh::sanitize_item($_POST['to_import'], 'text') : '');
|
1069 |
+
$this->selected_template=(isset($_POST['selected_template']) ? Wt_Iew_Sh::sanitize_item($_POST['selected_template'], 'int') : 0);
|
1070 |
+
}
|
1071 |
+
|
1072 |
+
$this->get_steps();
|
1073 |
+
|
1074 |
+
$ajax_obj=new Wt_Import_Export_For_Woo_Basic_Import_Ajax($this, $this->to_import, $this->steps, $this->import_method, $this->selected_template, $this->rerun_id);
|
1075 |
+
|
1076 |
+
$import_action=Wt_Iew_Sh::sanitize_item($_POST['import_action'], 'text');
|
1077 |
+
$data_type=Wt_Iew_Sh::sanitize_item($_POST['data_type'], 'text');
|
1078 |
+
|
1079 |
+
$allowed_ajax_actions=array('get_steps', 'validate_file', 'get_meta_mapping_fields', 'save_template', 'save_template_as', 'update_template', 'download', 'import', 'upload_import_file', 'delete_import_file');
|
1080 |
+
|
1081 |
+
$out=array(
|
1082 |
+
'status'=>0,
|
1083 |
+
'msg'=>__('Error'),
|
1084 |
+
);
|
1085 |
+
|
1086 |
+
if(method_exists($ajax_obj, $import_action) && in_array($import_action, $allowed_ajax_actions))
|
1087 |
+
{
|
1088 |
+
$out=$ajax_obj->{$import_action}($out);
|
1089 |
+
}
|
1090 |
+
|
1091 |
+
if($data_type=='json')
|
1092 |
+
{
|
1093 |
+
echo json_encode($out);
|
1094 |
+
}
|
1095 |
+
}
|
1096 |
+
exit();
|
1097 |
+
}
|
1098 |
+
|
1099 |
+
public function process_column_val($input_file_data_row, $form_data)
|
1100 |
+
{
|
1101 |
+
$out=array(
|
1102 |
+
'mapping_fields'=>array(),
|
1103 |
+
'meta_mapping_fields'=>array()
|
1104 |
+
);
|
1105 |
+
|
1106 |
+
/**
|
1107 |
+
* Default columns
|
1108 |
+
*/
|
1109 |
+
$mapping_form_data=(isset($form_data['mapping_form_data']) ? $form_data['mapping_form_data'] : array());
|
1110 |
+
$mapping_selected_fields=(isset($mapping_form_data['mapping_selected_fields']) ? $mapping_form_data['mapping_selected_fields'] : array());
|
1111 |
+
$mapping_fields=(isset($mapping_form_data['mapping_fields']) ? $mapping_form_data['mapping_fields'] : array());
|
1112 |
+
|
1113 |
+
/**
|
1114 |
+
* Input date format.
|
1115 |
+
* This will be taken as the global date format for all date fields in the input file.
|
1116 |
+
* If date format is specified in the evaluation section. Then this value will be overriden.
|
1117 |
+
*/
|
1118 |
+
$method_import_form_data=(isset($form_data['method_import_form_data']) ? $form_data['method_import_form_data'] : array());
|
1119 |
+
$input_date_format=(isset($method_import_form_data['wt_iew_date_format']) ? $method_import_form_data['wt_iew_date_format'] : '');
|
1120 |
+
|
1121 |
+
foreach ($mapping_selected_fields as $key => $value)
|
1122 |
+
{
|
1123 |
+
$out['mapping_fields'][$key]=$this->evaluate_data($key, $value, $input_file_data_row, $mapping_fields, $input_date_format);
|
1124 |
+
}
|
1125 |
+
$mapping_form_data=$mapping_fields=$mapping_selected_fields=null;
|
1126 |
+
unset($mapping_form_data, $mapping_fields, $mapping_selected_fields);
|
1127 |
+
|
1128 |
+
/**
|
1129 |
+
* Meta columns
|
1130 |
+
*/
|
1131 |
+
$meta_step_form_data=(isset($form_data['meta_step_form_data']) ? $form_data['meta_step_form_data'] : array());
|
1132 |
+
$mapping_selected_fields=(isset($meta_step_form_data['mapping_selected_fields']) ? $meta_step_form_data['mapping_selected_fields'] : array());
|
1133 |
+
$mapping_fields=(isset($meta_step_form_data['mapping_fields']) ? $meta_step_form_data['mapping_fields'] : array());
|
1134 |
+
foreach ($mapping_selected_fields as $meta_key => $meta_val_arr)
|
1135 |
+
{
|
1136 |
+
$out['meta_mapping_fields'][$meta_key]=array();
|
1137 |
+
$meta_fields_arr=(isset($mapping_fields[$meta_key]) ? $mapping_fields[$meta_key] : array());
|
1138 |
+
foreach ($meta_val_arr as $key => $value)
|
1139 |
+
{
|
1140 |
+
$out['meta_mapping_fields'][$meta_key][$key]=$this->evaluate_data($key, $value, $input_file_data_row, $meta_fields_arr, $input_date_format);
|
1141 |
+
}
|
1142 |
+
}
|
1143 |
+
$meta_step_form_data=$mapping_fields=$mapping_selected_fields=$input_file_data_row=$form_data=null;
|
1144 |
+
unset($meta_step_form_data, $mapping_fields, $mapping_selected_fields, $input_file_data_row, $form_data);
|
1145 |
+
|
1146 |
+
return $out;
|
1147 |
+
}
|
1148 |
+
protected function evaluate_data($key, $value, $data_row, $mapping_fields, $input_date_format)
|
1149 |
+
{
|
1150 |
+
$value=$this->add_input_file_data($key, $value, $data_row, $mapping_fields, $input_date_format);
|
1151 |
+
$value=$this->do_arithmetic($value);
|
1152 |
+
$data_row=null;
|
1153 |
+
unset($data_row);
|
1154 |
+
return $value;
|
1155 |
+
}
|
1156 |
+
protected function do_arithmetic($str)
|
1157 |
+
{
|
1158 |
+
$re = '/\[([0-9()+\-*\/. ]+)\]/m';
|
1159 |
+
$matches=array();
|
1160 |
+
$find=array();
|
1161 |
+
$replace=array();
|
1162 |
+
if(preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0))
|
1163 |
+
{
|
1164 |
+
foreach ($matches as $key => $value)
|
1165 |
+
{
|
1166 |
+
if(is_array($value) && count($value)>1)
|
1167 |
+
{
|
1168 |
+
$synatx=$this->validate_syntax($value[1]);
|
1169 |
+
if($synatx)
|
1170 |
+
{
|
1171 |
+
$replace[]=eval('return '.$synatx.';');
|
1172 |
+
}else
|
1173 |
+
{
|
1174 |
+
$replace[]='';
|
1175 |
+
}
|
1176 |
+
$find[]=$value[0];
|
1177 |
+
unset($synatx);
|
1178 |
+
}
|
1179 |
+
}
|
1180 |
+
}
|
1181 |
+
return str_replace($find, $replace, $str);
|
1182 |
+
}
|
1183 |
+
protected function validate_syntax($val)
|
1184 |
+
{
|
1185 |
+
$open_bracket=substr_count($val, '(');
|
1186 |
+
$close_bracket=substr_count($val, ')');
|
1187 |
+
if($close_bracket!=$open_bracket)
|
1188 |
+
{
|
1189 |
+
return false; //invalid
|
1190 |
+
}
|
1191 |
+
|
1192 |
+
//remove whitespaces
|
1193 |
+
$val=str_replace(' ', '', $val);
|
1194 |
+
$re_after='/\b[\+|*|\-|\/]([^0-9\+\-\(])/m';
|
1195 |
+
$re_before='/([^0-9\+\-\)])[\+|*|\-|\/]/m';
|
1196 |
+
|
1197 |
+
$match_after=array();
|
1198 |
+
$match_before=array();
|
1199 |
+
if(preg_match_all($re_after, $val, $match_after, PREG_SET_ORDER, 0) || preg_match_all($re_before, $val, $match_before, PREG_SET_ORDER, 0))
|
1200 |
+
{
|
1201 |
+
return false; //invalid
|
1202 |
+
}
|
1203 |
+
|
1204 |
+
unset($match_after, $match_before, $re_after, $re_before);
|
1205 |
+
|
1206 |
+
/* process + and - symbols */
|
1207 |
+
$val=preg_replace(array('/\+{2,}/m', '/\-{2,}/m'), array('+', '- -'), $val);
|
1208 |
+
|
1209 |
+
return $val;
|
1210 |
+
}
|
1211 |
+
protected function add_input_file_data($key, $str, $data_row, $mapping_fields, $input_date_format)
|
1212 |
+
{
|
1213 |
+
$re = '/\{([^}]+)\}/m';
|
1214 |
+
$matches=array();
|
1215 |
+
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
|
1216 |
+
$find=array();
|
1217 |
+
$replace=array();
|
1218 |
+
foreach ($matches as $key => $value)
|
1219 |
+
{
|
1220 |
+
if(is_array($value) && count($value)>1)
|
1221 |
+
{
|
1222 |
+
$data_key=trim($value[1]);
|
1223 |
+
|
1224 |
+
/* Check for date formatting */
|
1225 |
+
$data_key_arr=explode("@", $data_key);
|
1226 |
+
$data_format='';
|
1227 |
+
if(count($data_key_arr)==2) /* date format field given while on import */
|
1228 |
+
{
|
1229 |
+
$data_key=$data_key_arr[0]; //first value is the field key
|
1230 |
+
$data_format=$data_key_arr[1]; //second value will be the format
|
1231 |
+
}
|
1232 |
+
|
1233 |
+
/* Pre-defined date field */
|
1234 |
+
if(isset($mapping_fields[$data_key]) && isset($mapping_fields[$data_key][2]) && $mapping_fields[$data_key][2]='date')
|
1235 |
+
{
|
1236 |
+
/**
|
1237 |
+
* Always give preference to evaluation section
|
1238 |
+
* If not specified in evaluation section. Use default format
|
1239 |
+
*/
|
1240 |
+
if($data_format=="")
|
1241 |
+
{
|
1242 |
+
$data_format=$input_date_format;
|
1243 |
+
}
|
1244 |
+
}
|
1245 |
+
|
1246 |
+
$output_val='';
|
1247 |
+
if(isset($data_row[$data_key]))
|
1248 |
+
{
|
1249 |
+
// $output_val=sanitize_text_field($data_row[$data_key]); sanitize_text_field stripping html content
|
1250 |
+
$output_val=($data_row[$data_key]);
|
1251 |
+
}
|
1252 |
+
|
1253 |
+
/**
|
1254 |
+
* This is a date field
|
1255 |
+
*/
|
1256 |
+
if(trim($data_format)!="" && trim($output_val)!="")
|
1257 |
+
{
|
1258 |
+
if(version_compare(PHP_VERSION, '5.6.0', '>='))
|
1259 |
+
{
|
1260 |
+
$date_obj=DateTime::createFromFormat($data_format, $output_val);
|
1261 |
+
if($date_obj)
|
1262 |
+
{
|
1263 |
+
$output_val=$date->format('Y-m-d H:i:s');
|
1264 |
+
}
|
1265 |
+
}else
|
1266 |
+
{
|
1267 |
+
$output_val=date("Y-m-d H:i:s", strtotime(trim(str_replace('/', '-', str_replace('-', '', $output_val)))));
|
1268 |
+
}
|
1269 |
+
}
|
1270 |
+
|
1271 |
+
$replace[]=$output_val;
|
1272 |
+
$find[]=$value[0];
|
1273 |
+
unset($data_key);
|
1274 |
+
}
|
1275 |
+
}
|
1276 |
+
$data_row=null;
|
1277 |
+
unset($data_row);
|
1278 |
+
return str_replace($find, $replace, $str);
|
1279 |
+
}
|
1280 |
+
}
|
1281 |
+
}
|
1282 |
+
Wt_Import_Export_For_Woo_Basic::$loaded_modules['import']=new Wt_Import_Export_For_Woo_Basic_Import();
|
admin/modules/import/views/_import_advanced_page.php
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
?>
|
6 |
+
<div class="wt_iew_import_main">
|
7 |
+
<p><?php echo $this->step_description;?></p>
|
8 |
+
<form class="wt_iew_import_advanced_form">
|
9 |
+
<table class="form-table wt-iew-form-table">
|
10 |
+
<?php
|
11 |
+
Wt_Import_Export_For_Woo_Basic_Common_Helper::field_generator($advanced_screen_fields, $advanced_form_data);
|
12 |
+
?>
|
13 |
+
</table>
|
14 |
+
</form>
|
15 |
+
</div>
|
16 |
+
<script type="text/javascript">
|
17 |
+
/* custom action: other than import, save, update. Eg: schedule */
|
18 |
+
function wt_iew_custom_action_basic(ajx_dta, action, id)
|
19 |
+
{
|
20 |
+
ajx_dta['item_type']=ajx_dta['to_import'];
|
21 |
+
<?php
|
22 |
+
do_action('wt_iew_custom_action_basic');
|
23 |
+
?>
|
24 |
+
}
|
25 |
+
</script>
|
admin/modules/import/views/_import_footer.php
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
?>
|
6 |
+
<div class="wt-iew-plugin-toolbar bottom">
|
7 |
+
<div style="float:left; padding-top:10px;" class="wt_iew_import_template_name"> </div>
|
8 |
+
<div style="float:right;">
|
9 |
+
<div style="float:right;">
|
10 |
+
<?php
|
11 |
+
$button_types = array_column(array_values($this->step_btns), 'type');
|
12 |
+
$last_button_key = array_search('button', array_reverse($button_types, true));
|
13 |
+
$count = 0;
|
14 |
+
$button_standard_class = 'media-button';
|
15 |
+
foreach($this->step_btns as $btnk=>$btnv)
|
16 |
+
{
|
17 |
+
$css_class=(isset($btnv['class']) ? $btnv['class'] : '');
|
18 |
+
$action_type=(isset($btnv['action_type']) ? $btnv['action_type'] : 'non-step');
|
19 |
+
if($count == $last_button_key){
|
20 |
+
$button_standard_class = 'button-primary';
|
21 |
+
}
|
22 |
+
if($btnv['type']=='button')
|
23 |
+
{
|
24 |
+
?>
|
25 |
+
<button class="button <?php echo $button_standard_class; ?> wt_iew_import_action_btn <?php echo $css_class; ?>" data-action-type="<?php echo $action_type; ?>" data-action="<?php echo $btnv['key'];?>" type="submit">
|
26 |
+
<?php echo $btnv['text'];?>
|
27 |
+
</button>
|
28 |
+
<?php
|
29 |
+
|
30 |
+
}
|
31 |
+
elseif($btnv['type']=='dropdown_button')
|
32 |
+
{
|
33 |
+
$btn_arr=(isset($btnv['items']) && is_array($btnv['items']) ? $btnv['items'] : array());
|
34 |
+
?>
|
35 |
+
<button type="button" class="button button-primary wt_iew_drp_menu <?php echo $css_class; ?>" data-target="wt_iew_<?php echo $btnk; ?>_drp">
|
36 |
+
<?php echo $btnv['text'];?> <span class="dashicons dashicons-arrow-down" style="line-height: 28px;"></span>
|
37 |
+
</button>
|
38 |
+
<ul class="wt_iew_dropdown <?php echo $css_class; ?>" data-id="wt_iew_<?php echo $btnk; ?>_drp">
|
39 |
+
<?php
|
40 |
+
foreach($btn_arr as $btnkk => $btnvv)
|
41 |
+
{
|
42 |
+
$field_attr=(isset($btnvv['field_attr']) ? $btnvv['field_attr'] : '');
|
43 |
+
$action_type=(isset($btnvv['action_type']) ? $btnvv['action_type'] : 'non-step');
|
44 |
+
?>
|
45 |
+
<li class="wt_iew_import_action_btn" data-action-type="<?php echo $action_type; ?>" data-action="<?php echo $btnvv['key'];?>" <?php echo $field_attr;?> ><?php echo $btnvv['text'];?></li>
|
46 |
+
<?php
|
47 |
+
}
|
48 |
+
?>
|
49 |
+
</ul>
|
50 |
+
<?php
|
51 |
+
}
|
52 |
+
elseif($btnv['type']=='hidden_button')
|
53 |
+
{
|
54 |
+
?>
|
55 |
+
<button style="display:none;" class="button button-primary wt_iew_import_action_btn <?php echo $css_class; ?>" data-action-type="<?php echo $action_type; ?>" data-action="<?php echo $btnv['key'];?>" type="submit">
|
56 |
+
<?php echo $btnv['text'];?>
|
57 |
+
</button>
|
58 |
+
<?php
|
59 |
+
|
60 |
+
}
|
61 |
+
elseif($btnv['type']=='text')
|
62 |
+
{
|
63 |
+
?>
|
64 |
+
<span style="line-height:40px; font-weight:bold;" class="<?php echo $css_class; ?>"><?php echo $btnv['text'];?></span>
|
65 |
+
<?php
|
66 |
+
}
|
67 |
+
$count++;
|
68 |
+
}
|
69 |
+
?>
|
70 |
+
</div>
|
71 |
+
</div>
|
72 |
+
<span class="spinner" style="margin-top:11px;"></span>
|
73 |
+
</div>
|
admin/modules/import/views/_import_header.php
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
?>
|
6 |
+
<div class="wt-iew-settings-header">
|
7 |
+
<h3>
|
8 |
+
<?php _e('Import'); ?><?php if($this->step!='post_type'){ ?> <span class="wt_iew_step_head_post_type_name"></span><?php } ?>: <?php echo $this->step_title; ?>
|
9 |
+
</h3>
|
10 |
+
<span class="wt_iew_step_info" title="<?php echo $this->step_summary; ?>">
|
11 |
+
<?php /* step count summary */
|
12 |
+
echo $this->step_summary;
|
13 |
+
?>
|
14 |
+
</span>
|
15 |
+
</div>
|
admin/modules/import/views/_import_mapping_page.php
ADDED
@@ -0,0 +1,281 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
?>
|
6 |
+
<?php
|
7 |
+
$click_to_use=__('Click to use');
|
8 |
+
?>
|
9 |
+
<script type="text/javascript">
|
10 |
+
var wt_iew_file_head_default=<?php echo json_encode($file_heading_default_fields);?>;
|
11 |
+
var wt_iew_file_head_meta=<?php echo json_encode($file_heading_meta_fields);?>;
|
12 |
+
</script>
|
13 |
+
|
14 |
+
<!-- Mapping field editor popup -->
|
15 |
+
<div class="wt_iew_mapping_field_editor_container" data-title="<?php _e('Set value for column:');?> <span class='wt_iew_target_column'></span>" data-module="import">
|
16 |
+
<div class="wt_iew_mapping_field_editor">
|
17 |
+
<p class="wt_iew_mapping_field_editor_info" style="margin-bottom:5px;"><?php _e('Select and map any column from the input file or compute values with expressions.'); ?></p>
|
18 |
+
|
19 |
+
<label><?php _e('Expression');?></label>
|
20 |
+
<p class="wt_iew_mapping_field_editor_info">
|
21 |
+
<?php _e('Any of the operators +*/-()&@ or string constants can be used along with the attributes to manipulate the respective value.'); ?>
|
22 |
+
<br />
|
23 |
+
<?php echo sprintf(__('Enclose the operations within square brackets. e.g. if you want to increase the stock quantity of %sall imported products%s by 5 units during import simply use [{_stock}+5].'), '<b>', '</b>');?>
|
24 |
+
</p>
|
25 |
+
<p class="wt_iew_mapping_field_editor_er"></p>
|
26 |
+
<div class="wt_iew_mapping_field_editor_box">
|
27 |
+
<textarea class="wt_iew_mapping_field_editor_expression"></textarea>
|
28 |
+
</div>
|
29 |
+
|
30 |
+
<label><?php _e('Input file columns');?></label>
|
31 |
+
<div class="wt_iew_mapping_field_editor_box">
|
32 |
+
<input type="text" class="wt_iew_mapping_field_editor_column_search" placeholder="<?php _e('Type here to search');?>">
|
33 |
+
<div class="wt_iew_mapping_field_selector_box">
|
34 |
+
<ul class="wt_iew_mapping_field_selector">
|
35 |
+
<?php
|
36 |
+
foreach ($file_heading_default_fields as $key => $value)
|
37 |
+
{
|
38 |
+
?>
|
39 |
+
<li title="<?php echo $click_to_use;?>" data-val="<?php echo $key;?>"><?php echo $key;?></li>
|
40 |
+
<?php
|
41 |
+
}
|
42 |
+
foreach ($file_heading_meta_fields as $key => $value)
|
43 |
+
{
|
44 |
+
?>
|
45 |
+
<li title="<?php echo $click_to_use;?>" data-val="<?php echo $key;?>"><?php echo $key;?></li>
|
46 |
+
<?php
|
47 |
+
}
|
48 |
+
?>
|
49 |
+
</ul>
|
50 |
+
<div class="wt_iew_mapping_field_selector_no_column"><?php _e('No column found.');?></div>
|
51 |
+
</div>
|
52 |
+
</div>
|
53 |
+
|
54 |
+
<label><?php _e('Output');?></label>
|
55 |
+
<p class="wt_iew_mapping_field_editor_info">
|
56 |
+
<?php _e('Sample value based on first record from input file. Columns that have no values in the input file may cause syntax errors if used in an expression as above.'); ?>
|
57 |
+
</p>
|
58 |
+
<div class="wt_iew_mapping_field_editor_box" style="max-height:80px; overflow:auto; margin-bottom:0px; border:dashed 1px #ccc; padding:5px;">
|
59 |
+
<div class="wt_iew_mapping_field_editor_sample"></div>
|
60 |
+
</div>
|
61 |
+
</div>
|
62 |
+
</div>
|
63 |
+
<!-- Mapping field editor popup -->
|
64 |
+
|
65 |
+
<div class="wt_iew_import_main">
|
66 |
+
<p><?php echo $this->step_description;?></p>
|
67 |
+
|
68 |
+
<p class="wt_iew_info_box wt_iew_info">
|
69 |
+
<?php _e('Columns are mapped automatically only if a matching header name is found in the input file. If not the value is left blank.');?>
|
70 |
+
<br />
|
71 |
+
<?php _e('If your input file header does not have exact names or if you need to edit the existing mapping you can simply click on the respective value fields corresponding to each row. Furthermore you can also assign expressions based on the existing input file columns.');?>
|
72 |
+
</p>
|
73 |
+
|
74 |
+
<div class="meta_mapping_box">
|
75 |
+
<div class="meta_mapping_box_hd_nil wt_iew_noselect">
|
76 |
+
<?php _e('Default fields');?>
|
77 |
+
<span class="meta_mapping_box_selected_count_box"><span class="meta_mapping_box_selected_count_box_num">0</span> <?php _e(' columns(s) selected'); ?></span>
|
78 |
+
</div>
|
79 |
+
<div style="clear:both;"></div>
|
80 |
+
<div class="meta_mapping_box_con" data-sortable="0" data-loaded="1" data-field-validated="0" data-key="" style="display:inline-block;">
|
81 |
+
<table class="wt-iew-mapping-tb wt-iew-importer-default-mapping-tb">
|
82 |
+
<thead>
|
83 |
+
<tr>
|
84 |
+
<th>
|
85 |
+
<input type="checkbox" name="" class="wt_iew_mapping_checkbox_main">
|
86 |
+
</th>
|
87 |
+
<th width="35%"><?php _e('Column');?></th>
|
88 |
+
<th><?php _e('Column name');?></th>
|
89 |
+
</tr>
|
90 |
+
</thead>
|
91 |
+
<tbody>
|
92 |
+
<?php
|
93 |
+
$draggable_tooltip=__("Drag to rearrange the columns");
|
94 |
+
$tr_count=0;
|
95 |
+
foreach($form_data_mapping_fields as $key=>$val_arr) /* looping the template form data */
|
96 |
+
{
|
97 |
+
$val=$val_arr[0]; /* normal column val */
|
98 |
+
$checked=$val_arr[1]; /* import this column? */
|
99 |
+
|
100 |
+
if(isset($mapping_fields[$key])) /* found in default field list */
|
101 |
+
{
|
102 |
+
$label=(isset($mapping_fields[$key]['title']) ? $mapping_fields[$key]['title'] : '');
|
103 |
+
$description=(isset($mapping_fields[$key]['description']) ? $mapping_fields[$key]['description'] : '');
|
104 |
+
$type=(isset($mapping_fields[$key]['type']) ? $mapping_fields[$key]['type'] : '');
|
105 |
+
unset($mapping_fields[$key]); //remove the field from default list
|
106 |
+
|
107 |
+
if(isset($file_heading_default_fields[$key])) /* also found in file heading list */
|
108 |
+
{
|
109 |
+
unset($file_heading_default_fields[$key]); //remove the field from file heading list
|
110 |
+
}
|
111 |
+
|
112 |
+
include "_import_mapping_tr_html.php";
|
113 |
+
$tr_count++;
|
114 |
+
}
|
115 |
+
elseif(isset($file_heading_default_fields[$key])) /* found in file heading list */
|
116 |
+
{
|
117 |
+
$label=$key;
|
118 |
+
$description=$key;
|
119 |
+
$type='';
|
120 |
+
unset($file_heading_default_fields[$key]); //remove the field from file heading list
|
121 |
+
include "_import_mapping_tr_html.php";
|
122 |
+
$tr_count++;
|
123 |
+
}
|
124 |
+
elseif(isset($file_heading_meta_fields[$key])) /* some meta items will show inside default field list, Eg: yoast */
|
125 |
+
{
|
126 |
+
$label=$key;
|
127 |
+
$description=$key;
|
128 |
+
$type='';
|
129 |
+
unset($file_heading_meta_fields[$key]); //remove the field from file heading list
|
130 |
+
include "_import_mapping_tr_html.php";
|
131 |
+
$tr_count++;
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
/**
|
136 |
+
* ####Important####
|
137 |
+
* The similar code also done in Default mapping preparation step for quick import.
|
138 |
+
* If any updates done please update there also
|
139 |
+
* Method _prepare_for_quick in import ajax class
|
140 |
+
*/
|
141 |
+
|
142 |
+
if(count($mapping_fields)>0)
|
143 |
+
{
|
144 |
+
$array_keys_file_heading_default_fields = array_keys($file_heading_default_fields);
|
145 |
+
$allowed_field_types=array('start_with', 'end_with', 'contain');
|
146 |
+
foreach($mapping_fields as $key=>$val_arr)
|
147 |
+
{
|
148 |
+
$label=(isset($val_arr['title']) ? $val_arr['title'] : '');
|
149 |
+
$description=(isset($val_arr['description']) ? $val_arr['description'] : '');
|
150 |
+
$type=(isset($val_arr['type']) ? $val_arr['type'] : '');
|
151 |
+
$val='';
|
152 |
+
$checked=0; /* import this column? */
|
153 |
+
// if(isset($file_heading_default_fields[$key]))
|
154 |
+
if($case_key = preg_grep("/^$key$/i", $array_keys_file_heading_default_fields)) //preg_grep used escape from case sensitive check.
|
155 |
+
{
|
156 |
+
$checked=1; /* import this column? */
|
157 |
+
// $val='{'.$key.'}';
|
158 |
+
$val='{'.array_shift($case_key).'}'; // preg_grep give an array with actual index and value
|
159 |
+
unset($file_heading_default_fields[$key]); //remove the field from file heading list
|
160 |
+
unset($array_keys_file_heading_default_fields[$key]);
|
161 |
+
include "_import_mapping_tr_html.php";
|
162 |
+
$tr_count++;
|
163 |
+
}
|
164 |
+
elseif(isset($file_heading_meta_fields[$key])) /* some meta items will show inside default field list, Eg: yoast */
|
165 |
+
{
|
166 |
+
$checked=1; /* import this column? */
|
167 |
+
$val='{'.$key.'}';
|
168 |
+
unset($file_heading_meta_fields[$key]); //remove the field from file heading list
|
169 |
+
include "_import_mapping_tr_html.php";
|
170 |
+
$tr_count++;
|
171 |
+
}else
|
172 |
+
{
|
173 |
+
|
174 |
+
$field_type=(isset($val_arr['field_type']) ? $val_arr['field_type'] : '');
|
175 |
+
if($field_type!="" && in_array($field_type, $allowed_field_types)) // it may be a different field type
|
176 |
+
{
|
177 |
+
foreach ($file_heading_default_fields as $def_key => $def_val)
|
178 |
+
{
|
179 |
+
$matched=false;
|
180 |
+
if($field_type=='start_with' && strpos($def_key, $key)===0)
|
181 |
+
{
|
182 |
+
$matched=true;
|
183 |
+
}
|
184 |
+
elseif($field_type=='ends_with' && strrpos($def_key, $key)===(strlen($def_key) - strlen($key)))
|
185 |
+
{
|
186 |
+
$matched=true;
|
187 |
+
}
|
188 |
+
elseif($field_type=='contains' && strpos($def_key, $key)!==false)
|
189 |
+
{
|
190 |
+
$matched=true;
|
191 |
+
}
|
192 |
+
if($matched)
|
193 |
+
{
|
194 |
+
$checked=1; // import this column?
|
195 |
+
$val='{'.$def_key.'}';
|
196 |
+
$label=$def_key;
|
197 |
+
$key_backup=$key;
|
198 |
+
$key=$def_key;
|
199 |
+
unset($file_heading_default_fields[$def_key]); //remove the field from file heading list
|
200 |
+
include "_import_mapping_tr_html.php";
|
201 |
+
$tr_count++;
|
202 |
+
$key=$key_backup;
|
203 |
+
}
|
204 |
+
}
|
205 |
+
}else /* unmatched keys */
|
206 |
+
{
|
207 |
+
$checked=0; /* import this column? */
|
208 |
+
$val='';
|
209 |
+
include "_import_mapping_tr_html.php";
|
210 |
+
$tr_count++;
|
211 |
+
}
|
212 |
+
}
|
213 |
+
}
|
214 |
+
}
|
215 |
+
if(count($file_heading_default_fields)>0) /* show the remaining items */
|
216 |
+
{
|
217 |
+
/*
|
218 |
+
foreach($file_heading_default_fields as $key=>$sample_val)
|
219 |
+
{
|
220 |
+
$label=$key;
|
221 |
+
$description=$key;
|
222 |
+
$val='{'.$key.'}';
|
223 |
+
$checked=1;
|
224 |
+
include "_import_mapping_tr_html.php";
|
225 |
+
$tr_count++;
|
226 |
+
}
|
227 |
+
*/
|
228 |
+
}
|
229 |
+
if($tr_count==0)
|
230 |
+
{
|
231 |
+
?>
|
232 |
+
<tr>
|
233 |
+
<td colspan="3" style="text-align:center;">
|
234 |
+
<?php _e('No fields found.'); ?>
|
235 |
+
</td>
|
236 |
+
</tr>
|
237 |
+
<?php
|
238 |
+
}
|
239 |
+
?>
|
240 |
+
</tbody>
|
241 |
+
</table>
|
242 |
+
</div>
|
243 |
+
</div>
|
244 |
+
<div style="clear:both;"></div>
|
245 |
+
|
246 |
+
<?php
|
247 |
+
if($this->mapping_enabled_fields)
|
248 |
+
{
|
249 |
+
foreach($this->mapping_enabled_fields as $mapping_enabled_field_key=>$mapping_enabled_field)
|
250 |
+
{
|
251 |
+
$mapping_enabled_field=(!is_array($mapping_enabled_field) ? array($mapping_enabled_field, 0) : $mapping_enabled_field);
|
252 |
+
|
253 |
+
if(count($form_data_mapping_enabled_fields)>0)
|
254 |
+
{
|
255 |
+
if(in_array($mapping_enabled_field_key, $form_data_mapping_enabled_fields))
|
256 |
+
{
|
257 |
+
$mapping_enabled_field[1]=1;
|
258 |
+
}else
|
259 |
+
{
|
260 |
+
$mapping_enabled_field[1]=0;
|
261 |
+
}
|
262 |
+
}
|
263 |
+
?>
|
264 |
+
<div class="meta_mapping_box">
|
265 |
+
<div class="meta_mapping_box_hd wt_iew_noselect">
|
266 |
+
<span class="dashicons dashicons-arrow-right"></span>
|
267 |
+
<?php echo $mapping_enabled_field[0];?>
|
268 |
+
<span class="meta_mapping_box_selected_count_box"><span class="meta_mapping_box_selected_count_box_num">0</span> <?php _e(' columns(s) selected'); ?></span>
|
269 |
+
</div>
|
270 |
+
<div style="clear:both;"></div>
|
271 |
+
<div class="meta_mapping_box_con" data-sortable="0" data-loaded="0" data-field-validated="0" data-key="<?php echo $mapping_enabled_field_key;?>"></div>
|
272 |
+
</div>
|
273 |
+
<div style="clear:both;"></div>
|
274 |
+
<?php
|
275 |
+
}
|
276 |
+
}
|
277 |
+
?>
|
278 |
+
</div>
|
279 |
+
<script type="text/javascript">
|
280 |
+
var wt_iew_file_head_remaining_meta=<?php echo json_encode($file_heading_meta_fields);?>;
|
281 |
+
</script>
|
admin/modules/import/views/_import_mapping_tr_html.php
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
?>
|
6 |
+
<tr id="columns_<?php echo $key;?>">
|
7 |
+
<td>
|
8 |
+
<div class="wt_iew_sort_handle" title="<?php echo $draggable_tooltip;?>">
|
9 |
+
<img src="<?php echo WT_O_IEW_PLUGIN_URL.'assets/images/drag_icon.png'; ?>"/>
|
10 |
+
</div>
|
11 |
+
<input type="checkbox" name="columns_key[]" class="columns_key wt_iew_mapping_checkbox_sub" value="<?php echo $key;?>" <?php echo ($checked==1 ? 'checked' : ''); ?>>
|
12 |
+
</td>
|
13 |
+
<td>
|
14 |
+
<label class="wt_iew_mapping_column_label"><?php echo $label;?></label>
|
15 |
+
</td>
|
16 |
+
<td>
|
17 |
+
<input type="hidden" name="columns_val[]" class="columns_val" value="<?php echo $val;?>" data-type="<?php echo $type;?>">
|
18 |
+
<span data-wt_iew_popover="1" data-title="" data-content-container=".wt_iew_mapping_field_editor_container" class="wt_iew_mapping_field_val"><?php echo $val;?></span>
|
19 |
+
</td>
|
20 |
+
</tr>
|
admin/modules/import/views/_import_meta_step_page.php
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
?>
|
6 |
+
<table class="wt-iew-mapping-tb wt-iew-importer-meta-mapping-tb" data-field-type="<?php echo $meta_mapping_screen_field_key; ?>">
|
7 |
+
<thead>
|
8 |
+
<tr>
|
9 |
+
<th>
|
10 |
+
<?php
|
11 |
+
$is_checked=$meta_mapping_screen_field_val['checked'];
|
12 |
+
$checked_attr=($is_checked==1 ? ' checked="checked"' : '');
|
13 |
+
?>
|
14 |
+
<input type="checkbox" name="" class="wt_iew_mapping_checkbox_main" <?php echo $checked_attr; ?>>
|
15 |
+
</th>
|
16 |
+
<th width="35%"><?php _e('Column');?></th>
|
17 |
+
<th><?php _e('Column name');?></th>
|
18 |
+
</tr>
|
19 |
+
</thead>
|
20 |
+
<tbody>
|
21 |
+
<?php
|
22 |
+
$tr_count=0;
|
23 |
+
|
24 |
+
foreach($meta_mapping_screen_field_val['fields'] as $key=>$val_arr)
|
25 |
+
{
|
26 |
+
extract($val_arr);
|
27 |
+
include "_import_mapping_tr_html.php";
|
28 |
+
$tr_count++;
|
29 |
+
}
|
30 |
+
|
31 |
+
if($tr_count==0)
|
32 |
+
{
|
33 |
+
?>
|
34 |
+
<tr>
|
35 |
+
<td colspan="3" style="text-align:center;">
|
36 |
+
<?php _e('No fields found.'); ?>
|
37 |
+
</td>
|
38 |
+
</tr>
|
39 |
+
<?php
|
40 |
+
}
|
41 |
+
?>
|
42 |
+
</tbody>
|
43 |
+
</table>
|
admin/modules/import/views/_import_method_import_page.php
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
?>
|
6 |
+
<div class="wt_iew_import_main">
|
7 |
+
<p><?php //echo $this->step_description;?></p>
|
8 |
+
<div class="wt_iew_warn wt_iew_method_import_wrn" style="display:none;">
|
9 |
+
<?php _e('Please select an import template.');?>
|
10 |
+
</div>
|
11 |
+
<table class="form-table wt-iew-form-table">
|
12 |
+
<tr>
|
13 |
+
<th><label><?php _e('Import method');?></label></th>
|
14 |
+
<td colspan="2" style="width:75%;">
|
15 |
+
<div class="wt_iew_radio_block">
|
16 |
+
<?php
|
17 |
+
foreach($this->import_obj->import_methods as $key => $value)
|
18 |
+
{
|
19 |
+
?>
|
20 |
+
<p>
|
21 |
+
<input type="radio" value="<?php echo $key;?>" id="wt_iew_import_<?php echo $key;?>_import" name="wt_iew_import_method_import" <?php echo ($this->import_method==$key ? 'checked="checked"' : '');?>><b><label for="wt_iew_import_<?php echo $key;?>_import"><?php echo $value['title']; ?></label></b> <br />
|
22 |
+
<span><label for="wt_iew_import_<?php echo $key;?>_import"><?php echo $value['description']; ?></label></span>
|
23 |
+
</p>
|
24 |
+
<?php
|
25 |
+
}
|
26 |
+
?>
|
27 |
+
</div>
|
28 |
+
</td>
|
29 |
+
</tr>
|
30 |
+
<tr><div id="user-required-field-message" class="updated" style="margin-left:0px;display: none;background: #dceff4;"><p><?php _e('For a successful import, the uploading file must contain data for <b>at least 1 column: user_email</b>.'); ?></p></div></tr>
|
31 |
+
<tr class="wt-iew-import-method-options wt-iew-import-method-options-template" style="display:none;">
|
32 |
+
<th><label><?php _e('Import template');?></label></th>
|
33 |
+
<td>
|
34 |
+
<select class="wt-iew-import-template-sele">
|
35 |
+
<option value="0">-- <?php _e('Select a template'); ?> --</option>
|
36 |
+
<?php
|
37 |
+
foreach($this->mapping_templates as $mapping_template)
|
38 |
+
{
|
39 |
+
?>
|
40 |
+
<option value="<?php echo $mapping_template['id'];?>" <?php echo ($form_data_import_template==$mapping_template['id'] ? ' selected="selected"' : ''); ?>>
|
41 |
+
<?php echo $mapping_template['name'];?>
|
42 |
+
</option>
|
43 |
+
<?php
|
44 |
+
}
|
45 |
+
?>
|
46 |
+
</select>
|
47 |
+
</td>
|
48 |
+
<td>
|
49 |
+
</td>
|
50 |
+
</tr>
|
51 |
+
</table>
|
52 |
+
<form class="wt_iew_import_method_import_form">
|
53 |
+
<table class="form-table wt-iew-form-table">
|
54 |
+
<?php
|
55 |
+
Wt_Import_Export_For_Woo_Basic_Common_Helper::field_generator($method_import_screen_fields, $method_import_form_data);
|
56 |
+
?>
|
57 |
+
</table>
|
58 |
+
</form>
|
59 |
+
</div>
|
60 |
+
<script type="text/javascript">
|
61 |
+
/* remote file modules can hook */
|
62 |
+
function wt_iew_set_file_from_fields(file_from)
|
63 |
+
{
|
64 |
+
<?php
|
65 |
+
do_action('wt_iew_importer_file_from_js_fn');
|
66 |
+
?>
|
67 |
+
}
|
68 |
+
|
69 |
+
function wt_iew_set_validate_file_info(file_from)
|
70 |
+
{
|
71 |
+
<?php
|
72 |
+
do_action('wt_iew_importer_set_validate_file_info');
|
73 |
+
?>
|
74 |
+
}
|
75 |
+
</script>
|
admin/modules/import/views/_import_post_type_page.php
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
?>
|
6 |
+
<div class="wt_iew_import_main">
|
7 |
+
<p><?php echo $this->step_description;?></p>
|
8 |
+
<div class="wt_iew_warn wt_iew_post_type_wrn" style="display:none;">
|
9 |
+
<?php _e('Please select a post type');?>
|
10 |
+
</div>
|
11 |
+
<table class="form-table wt-iew-form-table">
|
12 |
+
<tr>
|
13 |
+
<th><label><?php _e('What do you want to import'); ?></label></th>
|
14 |
+
<td>
|
15 |
+
<select name="wt_iew_import_post_type">
|
16 |
+
<option value="">-- <?php _e('Select post type'); ?> --</option>
|
17 |
+
<?php
|
18 |
+
$item_type = isset($item_type) ? $item_type : '';
|
19 |
+
foreach($post_types as $key=>$value)
|
20 |
+
{
|
21 |
+
?>
|
22 |
+
<option value="<?php echo $key;?>" <?php echo ($item_type==$key ? 'selected' : '');?>><?php echo $value;?></option>
|
23 |
+
<?php
|
24 |
+
}
|
25 |
+
?>
|
26 |
+
</select>
|
27 |
+
</td>
|
28 |
+
<td></td>
|
29 |
+
</tr>
|
30 |
+
</table>
|
31 |
+
</div>
|
admin/modules/import/views/main.php
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Main view file of import section
|
4 |
+
*
|
5 |
+
* @link
|
6 |
+
*
|
7 |
+
* @package Wt_Import_Export_For_Woo
|
8 |
+
*/
|
9 |
+
if (!defined('ABSPATH')) {
|
10 |
+
exit;
|
11 |
+
}
|
12 |
+
?>
|
13 |
+
<?php
|
14 |
+
do_action('wt_iew_importer_before_head');
|
15 |
+
?>
|
16 |
+
<style type="text/css">
|
17 |
+
.wt_iew_import_step{ display:none; }
|
18 |
+
.wt_iew_import_step_loader{ width:100%; height:400px; text-align:center; line-height:400px; font-size:14px; }
|
19 |
+
.wt_iew_import_step_main{ float:left; box-sizing:border-box; padding:15px; padding-bottom:0px; width:95%; margin:30px 2.5%; background:#fff; box-shadow:0px 2px 2px #ccc; border:solid 1px #efefef; }
|
20 |
+
.wt_iew_import_main{ padding:20px 0px; }
|
21 |
+
select[name=wt_iew_file_from]{visibility: hidden;}
|
22 |
+
</style>
|
23 |
+
<?php
|
24 |
+
Wt_Iew_IE_Basic_Helper::debug_panel($this->module_base);
|
25 |
+
?>
|
26 |
+
<?php include WT_O_IEW_PLUGIN_PATH."/admin/views/_save_template_popup.php"; ?>
|
27 |
+
|
28 |
+
<h2 class="wt_iew_page_hd"><?php _e('Import'); ?><span class="wt_iew_post_type_name"></span></h2>
|
29 |
+
|
30 |
+
<?php
|
31 |
+
if($requested_rerun_id>0 && $this->rerun_id==0)
|
32 |
+
{
|
33 |
+
?>
|
34 |
+
<div class="wt_iew_warn wt_iew_rerun_warn">
|
35 |
+
<?php _e('Unable to handle Re-Run request.');?>
|
36 |
+
</div>
|
37 |
+
<?php
|
38 |
+
}
|
39 |
+
?>
|
40 |
+
|
41 |
+
<div class="wt_iew_loader_info_box"></div>
|
42 |
+
<div class="wt_iew_overlayed_loader"></div>
|
43 |
+
|
44 |
+
<div class="wt_iew_import_step_main">
|
45 |
+
<?php
|
46 |
+
foreach($this->steps as $stepk=>$stepv)
|
47 |
+
{
|
48 |
+
?>
|
49 |
+
<div class="wt_iew_import_step wt_iew_import_step_<?php echo $stepk;?>" data-loaded="0"></div>
|
50 |
+
<?php
|
51 |
+
}
|
52 |
+
?>
|
53 |
+
</div>
|
54 |
+
<script type="text/javascript">
|
55 |
+
/* external modules can hook */
|
56 |
+
function wt_iew_importer_validate_basic(action, action_type, is_previous_step)
|
57 |
+
{
|
58 |
+
var is_continue=true;
|
59 |
+
<?php
|
60 |
+
do_action('wt_iew_importer_validate_basic');
|
61 |
+
?>
|
62 |
+
return is_continue;
|
63 |
+
}
|
64 |
+
function wt_iew_importer_reset_form_data_basic()
|
65 |
+
{
|
66 |
+
<?php
|
67 |
+
do_action('wt_iew_importer_reset_form_data_basic');
|
68 |
+
?>
|
69 |
+
}
|
70 |
+
</script>
|
includes/exporter/data/data-wf-post-columns.php → admin/modules/order/data/data-order-post-columns.php
RENAMED
@@ -4,7 +4,7 @@ if (!defined('ABSPATH')) {
|
|
4 |
exit;
|
5 |
}
|
6 |
|
7 |
-
return apply_filters('
|
8 |
'order_id' => 'order_id',
|
9 |
'order_number' => 'order_number',
|
10 |
'order_date' => 'order_date',
|
@@ -18,7 +18,7 @@ return apply_filters('woocommerce_csv_order_post_columns', array(
|
|
18 |
'order_discount' => 'order_discount',
|
19 |
'discount_total' => 'discount_total',
|
20 |
'order_total' => 'order_total',
|
21 |
-
//
|
22 |
'order_currency' => 'order_currency',
|
23 |
'payment_method' => 'payment_method',
|
24 |
'shipping_method' => 'shipping_method',
|
@@ -46,14 +46,12 @@ return apply_filters('woocommerce_csv_order_post_columns', array(
|
|
46 |
'shipping_state' => 'shipping_state',
|
47 |
'shipping_country' => 'shipping_country',
|
48 |
'customer_note' => 'customer_note',
|
|
|
49 |
'shipping_items' => 'shipping_items',
|
50 |
'fee_items' => 'fee_items',
|
51 |
'tax_items' => 'tax_items',
|
52 |
'coupon_items' => 'coupon_items',
|
53 |
'refund_items' => 'refund_items',
|
54 |
'order_notes' => 'order_notes',
|
55 |
-
'download_permissions' => 'download_permissions'
|
56 |
-
'customer_ip_address' => 'customer_ip_address',
|
57 |
-
'paid_date' => 'paid_date',
|
58 |
-
'completed_date'=>'completed_date'
|
59 |
));
|
4 |
exit;
|
5 |
}
|
6 |
|
7 |
+
return apply_filters('hf_csv_order_post_columns', array(
|
8 |
'order_id' => 'order_id',
|
9 |
'order_number' => 'order_number',
|
10 |
'order_date' => 'order_date',
|
18 |
'order_discount' => 'order_discount',
|
19 |
'discount_total' => 'discount_total',
|
20 |
'order_total' => 'order_total',
|
21 |
+
//'refunded_total' => 'refunded_total',
|
22 |
'order_currency' => 'order_currency',
|
23 |
'payment_method' => 'payment_method',
|
24 |
'shipping_method' => 'shipping_method',
|
46 |
'shipping_state' => 'shipping_state',
|
47 |
'shipping_country' => 'shipping_country',
|
48 |
'customer_note' => 'customer_note',
|
49 |
+
'wt_import_key' => 'wt_import_key',
|
50 |
'shipping_items' => 'shipping_items',
|
51 |
'fee_items' => 'fee_items',
|
52 |
'tax_items' => 'tax_items',
|
53 |
'coupon_items' => 'coupon_items',
|
54 |
'refund_items' => 'refund_items',
|
55 |
'order_notes' => 'order_notes',
|
56 |
+
'download_permissions' => 'download_permissions'
|
|
|
|
|
|
|
57 |
));
|
admin/modules/order/data/data-wf-exclude-hidden-meta-columns.php
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Exclude columns handled specifically
|
3 |
+
return apply_filters('hf_csv_order_exclude_meta_columns', array('wf_order_exported_status'));
|
4 |
+
|
5 |
+
|
admin/modules/order/data/data-wf-hidden-meta-columns.php
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Exclude columns handled specifically
|
3 |
+
return apply_filters('hf_csv_order_exclude_meta_columns', array('wf_order_exported_status'));
|
4 |
+
|
5 |
+
|
admin/modules/order/data/data-wf-post-columns-coupon.php
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
|
6 |
+
return apply_filters('coupon_csv_coupon_post_columns', array(
|
7 |
+
'post_title' => 'post_title',
|
8 |
+
'ID' => 'ID',
|
9 |
+
'post_excerpt' => 'post_excerpt',
|
10 |
+
'post_status' => 'post_status',
|
11 |
+
'post_date' => 'post_date',
|
12 |
+
'post_author' => 'post_author',
|
13 |
+
|
14 |
+
// // Meta
|
15 |
+
'discount_type' => 'discount_type',
|
16 |
+
'coupon_amount' => 'coupon_amount',
|
17 |
+
'individual_use' => 'individual_use',
|
18 |
+
'product_ids' => 'product_ids',
|
19 |
+
'product_SKUs' => 'product_SKUs',
|
20 |
+
'exclude_product_ids' => 'exclude_product_ids',
|
21 |
+
'exclude_product_SKUs' => 'exclude_product_SKUs',
|
22 |
+
'usage_count' => 'usage_count',
|
23 |
+
'usage_limit' => 'usage_limit',
|
24 |
+
'usage_limit_per_user' => 'usage_limit_per_user',
|
25 |
+
'limit_usage_to_x_items' => 'limit_usage_to_x_items',
|
26 |
+
'expiry_date' => 'expiry_date',
|
27 |
+
'date_expires' => 'date_expires',
|
28 |
+
'free_shipping' => 'free_shipping',
|
29 |
+
'exclude_sale_items' => 'exclude_sale_items',
|
30 |
+
'product_categories' => 'product_categories',
|
31 |
+
'exclude_product_categories' => 'exclude_product_categories',
|
32 |
+
'minimum_amount' => 'minimum_amount',
|
33 |
+
'maximum_amount' => 'maximum_amount',
|
34 |
+
'customer_email' => 'customer_email',
|
35 |
+
) );
|
admin/modules/order/data/data-wf-post-subscription-columns.php
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if (!defined('ABSPATH')) {
|
4 |
+
exit;
|
5 |
+
}
|
6 |
+
|
7 |
+
$columns = array(
|
8 |
+
'subscription_id' => 'subscription_id',
|
9 |
+
'subscription_status' => 'subscription_status',
|
10 |
+
'customer_id' => 'customer_id',
|
11 |
+
'customer_username' => 'customer_username',
|
12 |
+
'customer_email' => 'customer_email',
|
13 |
+
'date_created' => 'date_created',
|
14 |
+
'trial_end_date' => 'trial_end_date',
|
15 |
+
'next_payment_date' => 'next_payment_date',
|
16 |
+
'last_order_date_created' => 'last_order_date_created',
|
17 |
+
'end_date' => 'end_date',
|
18 |
+
'post_parent' => 'post_parent',
|
19 |
+
'billing_period' => 'billing_period',
|
20 |
+
'billing_interval' => 'billing_interval',
|
21 |
+
'order_shipping' => 'order_shipping',
|
22 |
+
'order_shipping_tax' => 'order_shipping_tax',
|
23 |
+
'fee_total' => 'fee_total',
|
24 |
+
'fee_tax_total' => 'fee_tax_total',
|
25 |
+
'order_tax' => 'order_tax',
|
26 |
+
'cart_discount' => 'cart_discount',
|
27 |
+
'cart_discount_tax' => 'cart_discount_tax',
|
28 |
+
'order_total' => 'order_total',
|
29 |
+
'order_currency' => 'order_currency',
|
30 |
+
'payment_method' => 'payment_method',
|
31 |
+
'payment_method_title' => 'payment_method_title',
|
32 |
+
'shipping_method' => 'shipping_method',
|
33 |
+
'billing_first_name' => 'billing_first_name',
|
34 |
+
'billing_last_name' => 'billing_last_name',
|
35 |
+
'billing_email' => 'billing_email',
|
36 |
+
'billing_phone' => 'billing_phone',
|
37 |
+
'billing_address_1' => 'billing_address_1',
|
38 |
+
'billing_address_2' => 'billing_address_2',
|
39 |
+
'billing_postcode' => 'billing_postcode',
|
40 |
+
'billing_city' => 'billing_city',
|
41 |
+
'billing_state' => 'billing_state',
|
42 |
+
'billing_country' => 'billing_country',
|
43 |
+
'billing_company' => 'billing_company',
|
44 |
+
'shipping_first_name' => 'shipping_first_name',
|
45 |
+
'shipping_last_name' => 'shipping_last_name',
|
46 |
+
'shipping_address_1' => 'shipping_address_1',
|
47 |
+
'shipping_address_2' => 'shipping_address_2',
|
48 |
+
'shipping_postcode' => 'shipping_postcode',
|
49 |
+
'shipping_city' => 'shipping_city',
|
50 |
+
'shipping_state' => 'shipping_state',
|
51 |
+
'shipping_country' => 'shipping_country',
|
52 |
+
'shipping_company' => 'shipping_company',
|
53 |
+
'customer_note' => 'customer_note',
|
54 |
+
'order_items' => 'order_items',
|
55 |
+
'order_notes' => 'order_notes',
|
56 |
+
'renewal_orders' => 'renewal_orders',
|
57 |
+
'shipping_items' => 'shipping_items',
|
58 |
+
'coupon_items' => 'coupon_items',
|
59 |
+
'fee_items' => 'fee_items',
|
60 |
+
'tax_items' => 'tax_items',
|
61 |
+
'download_permissions' => 'download_permissions'
|
62 |
+
);
|
63 |
+
|
64 |
+
global $wpdb;
|
65 |
+
|
66 |
+
if(class_exists('HF_Subscription')){
|
67 |
+
$post_type = 'hf_shop_subscription';
|
68 |
+
} else {
|
69 |
+
$post_type = 'shop_subscription';
|
70 |
+
}
|
71 |
+
$meta_keys = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT pm.meta_key
|
72 |
+
FROM {$wpdb->postmeta} AS pm
|
73 |
+
LEFT JOIN {$wpdb->posts} AS p ON p.ID = pm.post_id
|
74 |
+
WHERE p.post_type = %s
|
75 |
+
AND pm.meta_key NOT IN ('_schedule_next_payment','_schedule_start','_schedule_end','_schedule_trial_end','_download_permissions_granted','_subscription_renewal_order_ids_cache','_subscription_resubscribe_order_ids_cache','_subscription_switch_order_ids_cache','_created_via','_customer_user')
|
76 |
+
ORDER BY pm.meta_key",$post_type));
|
77 |
+
foreach ($meta_keys as $meta_key) {
|
78 |
+
if (empty($columns[$meta_key])) {
|
79 |
+
if($meta_key[0] == '_' && empty($columns[substr($meta_key, 1)])){
|
80 |
+
$columns['meta:'.$meta_key] = 'meta:'.$meta_key; // adding an extra prefix for identifying meta while import process
|
81 |
+
} elseif($meta_key[0] != '_') {
|
82 |
+
$columns['meta:'.$meta_key] = 'meta:'.$meta_key;
|
83 |
+
}
|
84 |
+
}
|
85 |
+
}
|
86 |
+
|
87 |
+
return apply_filters('hf_csv_subscription_order_header_columns',$columns);
|
admin/modules/order/data/data-wf-xml-default-meta.php
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Default meta columns for xml
|
3 |
+
return apply_filters('hf_xml_order_default_meta_columns', array(
|
4 |
+
'_billing_address_1' => '_billing_address_1',
|
5 |
+
'_billing_address_2' => '_billing_address_2',
|
6 |
+
'_billing_city' => '_billing_city',
|
7 |
+
'_billing_company' => '_billing_company',
|
8 |
+
'_billing_country' => '_billing_country',
|
9 |
+
'_billing_email' => '_billing_email',
|
10 |
+
'_billing_first_name' => '_billing_first_name',
|
11 |
+
'_billing_last_name' => '_billing_last_name',
|
12 |
+
'_billing_phone' => '_billing_phone',
|
13 |
+
'_billing_postcode' => '_billing_postcode',
|
14 |
+
'_billing_state' => '_billing_state',
|
15 |
+
'_shipping_address_1' => '_shipping_address_1',
|
16 |
+
'_shipping_address_2' => '_shipping_address_2',
|
17 |
+
'_shipping_city' => '_shipping_city',
|
18 |
+
'_shipping_company' => '_shipping_company',
|
19 |
+
'_shipping_country' => '_shipping_country',
|
20 |
+
'_shipping_first_name' => '_shipping_first_name',
|
21 |
+
'_shipping_last_name' => '_shipping_last_name',
|
22 |
+
'_shipping_method' => '_shipping_method',
|
23 |
+
'_shipping_postcode' => '_shipping_postcode',
|
24 |
+
'_shipping_state' => '_shipping_state',
|
25 |
+
'wf_order_exported_status' => 'wf_order_exported_status',
|
26 |
+
'_payment_method' => '_payment_method',
|
27 |
+
'_payment_method_title' => '_payment_method_title',
|
28 |
+
'_completed_date' => '_completed_date',
|
29 |
+
'_customer_email' => '_customer_email',
|
30 |
+
'_fee_total' => '_fee_total',
|
31 |
+
'_order_currency' => '_order_currency',
|
32 |
+
'_order_total' => '_order_total',
|
33 |
+
'_order_number' => '_order_number',
|
34 |
+
'_cart_discount' => '_cart_discount',
|
35 |
+
'_order_discount' => '_order_discount',
|
36 |
+
'_discount_total' => '_discount_total',
|
37 |
+
'_tax_total' => '_tax_total',
|
38 |
+
'_date_completed' => '_date_completed',
|
39 |
+
'_shipping_tax_total' => '_shipping_tax_total',
|
40 |
+
'_paid_date' => '_paid_date',
|
41 |
+
'_customer_user' => '_customer_user',
|
42 |
+
'_order_shipping' => '_order_shipping',
|
43 |
+
'_order_shipping_tax' => '_order_shipping_tax'));
|
44 |
+
|
admin/modules/order/data/data/data-wf-reserved-fields-pair.php
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
// Reserved column names
|
4 |
+
return apply_filters('woocommerce_csv_order_reserved_fields_pair',array(
|
5 |
+
'order_id' => array('title'=>'Order ID ','description'=>'Order ID '),
|
6 |
+
'order_number' => array('title'=>'Order Number','description'=>'Order Number'),
|
7 |
+
'order_date' => array('title'=>'Order Date','description'=>'Order Date', 'type' => 'date'),
|
8 |
+
'status' => array('title'=>'Order Status','description'=>'Order Status ( processing , pending ...) '),
|
9 |
+
'shipping_total' => array('title'=>'Shipping Total','description'=>'Shipping Total amount'),
|
10 |
+
'shipping_tax_total' => array('title'=>'Shipping Tax Total','description'=>'Shipping Tax Total'),
|
11 |
+
'fee_total' => array('title'=>'Total Fee','description'=>'Total Fee'),
|
12 |
+
'fee_tax_total' => array('title'=>'Total Tax Fee','description'=>'Total Tax Fee'),
|
13 |
+
'tax_total' => array('title'=>'Total Tax','description'=>'Total Tax'),
|
14 |
+
'cart_discount' => array('title'=>'Cart Discount','description'=>'Cart Discount'),
|
15 |
+
'order_discount' => array('title'=>'Order Discount','description'=>'Order Discount'),
|
16 |
+
'discount_total' => array('title'=>'Discount Total','description'=>'Discount Total'),
|
17 |
+
'order_total' => array('title'=>'Order Total','description'=>'Order Total'),
|
18 |
+
//'refunded_total' => array('title'=>'refunded_total','description'=>'refunded_total'),
|
19 |
+
'order_currency' => array('title'=>'order_currency','description'=>'Order Currency'),
|
20 |
+
'payment_method' => array('title'=>'payment_method','description'=>'Payment Method'),
|
21 |
+
'shipping_method' => array('title'=>'shipping_method','description'=>'Shipping Method'),
|
22 |
+
'customer_email' => array('title'=>'customer_email','description'=>'Customer Email ( if not provided order will be created as Guest)'),
|
23 |
+
'customer_user' => array('title'=>'customer_user','description'=>'Customer id ( if not provided order will be created as Guest)'),
|
24 |
+
'billing_first_name' => array('title'=>'billing_first_name','description'=>'billing_first_name'),
|
25 |
+
'billing_last_name' => array('title'=>'billing_last_name','description'=>'billing_last_name'),
|
26 |
+
'billing_company' => array('title'=>'billing_company','description'=>'billing_company'),
|
27 |
+
'billing_email' => array('title'=>'billing_email','description'=>'billing_email'),
|
28 |
+
'billing_phone' => array('title'=>'billing_phone','description'=>'billing_phone'),
|
29 |
+
'billing_address_1' => array('title'=>'billing_address_1','description'=>'billing_address_1'),
|
30 |
+
'billing_address_2' => array('title'=>'billing_address_2','description'=>'billing_address_2'),
|
31 |
+
'billing_postcode' => array('title'=>'billing_postcode','description'=>'billing_postcode'),
|
32 |
+
'billing_city' => array('title'=>'billing_city','description'=>'billing_city'),
|
33 |
+
'billing_state' => array('title'=>'billing_state','description'=>'billing_state'),
|
34 |
+
'billing_country' => array('title'=>'billing_country','description'=>'billing_country'),
|
35 |
+
'shipping_first_name' => array('title'=>'shipping_first_name','description'=>'shipping_first_name'),
|
36 |
+
'shipping_last_name' => array('title'=>'shipping_last_name','description'=>'shipping_last_name'),
|
37 |
+
'shipping_company' => array('title'=>'shipping_company','description'=>'shipping_company'),
|
38 |
+
'shipping_address_1' => array('title'=>'shipping_address_1','description'=>'shipping_address_1'),
|
39 |
+
'shipping_address_2' => array('title'=>'shipping_address_2','description'=>'shipping_address_2'),
|
40 |
+
'shipping_postcode' => array('title'=>'shipping_postcode','description'=>'shipping_postcode'),
|
41 |
+
'shipping_city' => array('title'=>'shipping_city','description'=>'shipping_city'),
|
42 |
+
'shipping_state' => array('title'=>'shipping_state','description'=>'shipping_state'),
|
43 |
+
'shipping_country' => array('title'=>'shipping_country','description'=>'shipping_country'),
|
44 |
+
'customer_note' => array('title'=>'customer_note','description'=>'customer_note'),
|
45 |
+
'wt_import_key' => array('title'=>'wt_import_key','description'=>'wt_import_key'),
|
46 |
+
'shipping_items' => array('title'=>'shipping_items','description'=>'shipping_items'),
|
47 |
+
'fee_items' => array('title'=>'fee_items','description'=>'fee_items'),
|
48 |
+
'tax_items' => array('title'=>'tax_items','description'=>'tax_items'),
|
49 |
+
'coupon_items' => array('title'=>'coupon_items','description'=>'coupons'),
|
50 |
+
'refund_items' => array('title'=>'refund_items','description'=>'refund_items'),
|
51 |
+
'order_notes' => array('title'=>'order_notes','description'=>'Order notes'),
|
52 |
+
'line_item_' => array('title'=>'line_item_','description'=>'Line Items','field_type'=>'start_with'),
|
53 |
+
'download_permissions' => array('title'=>'Downloadable Product Permissions ','description'=>'Permissions for order items will automatically be granted when the order status changes to processing or completed.'),
|
54 |
+
));
|
admin/modules/order/export/export.php
ADDED
@@ -0,0 +1,911 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if (!defined('WPINC')) {
|
4 |
+
exit;
|
5 |
+
}
|
6 |
+
|
7 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Basic_Order_Export')){
|
8 |
+
class Wt_Import_Export_For_Woo_Basic_Order_Export {
|
9 |
+
|
10 |
+
public $parent_module = null;
|
11 |
+
private $line_items_max_count = 0;
|
12 |
+
private $export_to_separate_columns = false;
|
13 |
+
private $line_item_meta;
|
14 |
+
|
15 |
+
public function __construct($parent_object) {
|
16 |
+
|
17 |
+
$this->parent_module = $parent_object;
|
18 |
+
}
|
19 |
+
|
20 |
+
public function prepare_header() {
|
21 |
+
|
22 |
+
$export_columns = $this->parent_module->get_selected_column_names();
|
23 |
+
|
24 |
+
$this->line_item_meta = self::get_all_line_item_metakeys();
|
25 |
+
|
26 |
+
$max_line_items = $this->line_items_max_count;
|
27 |
+
|
28 |
+
for ($i = 1; $i <= $max_line_items; $i++) {
|
29 |
+
$export_columns["line_item_{$i}"] = "line_item_{$i}";
|
30 |
+
}
|
31 |
+
|
32 |
+
if ($this->export_to_separate_columns) {
|
33 |
+
for ($i = 1; $i <= $max_line_items; $i++) {
|
34 |
+
foreach ($this->line_item_meta as $meta_value) {
|
35 |
+
$new_val = str_replace("_", " ", $meta_value);
|
36 |
+
$export_columns["line_item_{$i}_name"] = "Product Item {$i} Name";
|
37 |
+
$export_columns["line_item_{$i}_product_id"] = "Product Item {$i} id";
|
38 |
+
$export_columns["line_item_{$i}_sku"] = "Product Item {$i} SKU";
|
39 |
+
$export_columns["line_item_{$i}_quantity"] = "Product Item {$i} Quantity";
|
40 |
+
$export_columns["line_item_{$i}_total"] = "Product Item {$i} Total";
|
41 |
+
$export_columns["line_item_{$i}_subtotal"] = "Product Item {$i} Subtotal";
|
42 |
+
if (in_array($meta_value, array("_product_id", "_qty", "_variation_id", "_line_total", "_line_subtotal", "_tax_class", "_line_tax", "_line_tax_data", "_line_subtotal_tax"))) {
|
43 |
+
continue;
|
44 |
+
} else {
|
45 |
+
$export_columns["line_item_{$i}_$meta_value"] = "Product Item {$i} $new_val";
|
46 |
+
}
|
47 |
+
}
|
48 |
+
}
|
49 |
+
}
|
50 |
+
return apply_filters('hf_alter_csv_header', $export_columns);
|
51 |
+
}
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Prepare data that will be exported.
|
55 |
+
*/
|
56 |
+
public function prepare_data_to_export($form_data, $batch_offset) {
|
57 |
+
|
58 |
+
$export_order_statuses = !empty($form_data['filter_form_data']['wt_iew_order_status']) ? $form_data['filter_form_data']['wt_iew_order_status'] : 'any';
|
59 |
+
$products = !empty($form_data['filter_form_data']['wt_iew_products']) ? $form_data['filter_form_data']['wt_iew_products'] : '';
|
60 |
+
$email = !empty($form_data['filter_form_data']['wt_iew_email']) ? $form_data['filter_form_data']['wt_iew_email'] : array(); // user email fields return user ids
|
61 |
+
$start_date = !empty($form_data['filter_form_data']['wt_iew_date_from']) ? $form_data['filter_form_data']['wt_iew_date_from'] . ' 00:00:00' : date('Y-m-d 00:00:00', 0);
|
62 |
+
$end_date = !empty($form_data['filter_form_data']['wt_iew_date_to']) ? $form_data['filter_form_data']['wt_iew_date_to'] . ' 23:59:59.99' : date('Y-m-d 23:59:59.99', current_time('timestamp'));
|
63 |
+
$coupons = !empty($form_data['filter_form_data']['wt_iew_coupons']) ? array_filter(explode(',', strtolower($form_data['filter_form_data']['wt_iew_coupons'])),'trim') : array();
|
64 |
+
|
65 |
+
$export_limit = !empty($form_data['filter_form_data']['wt_iew_limit']) ? intval($form_data['filter_form_data']['wt_iew_limit']) : 999999999; //user limit
|
66 |
+
$current_offset = !empty($form_data['filter_form_data']['wt_iew_offset']) ? intval($form_data['filter_form_data']['wt_iew_offset']) : 0; //user offset
|
67 |
+
$export_offset = $current_offset;
|
68 |
+
$batch_count = !empty($form_data['advanced_form_data']['wt_iew_batch_count']) ? $form_data['advanced_form_data']['wt_iew_batch_count'] : Wt_Import_Export_For_Woo_Basic_Common_Helper::get_advanced_settings('default_export_batch');
|
69 |
+
|
70 |
+
$exclude_already_exported = (!empty($form_data['advanced_form_data']['wt_iew_exclude_already_exported']) && $form_data['advanced_form_data']['wt_iew_exclude_already_exported'] == 'Yes') ? true : false;
|
71 |
+
|
72 |
+
$this->export_to_separate_columns = (!empty($form_data['advanced_form_data']['wt_iew_export_to_separate_columns']) && $form_data['advanced_form_data']['wt_iew_export_to_separate_columns'] == 'Yes') ? true : false;
|
73 |
+
|
74 |
+
$real_offset = ($current_offset + $batch_offset);
|
75 |
+
|
76 |
+
if($batch_count<=$export_limit)
|
77 |
+
{
|
78 |
+
if(($batch_offset+$batch_count)>$export_limit) //last offset
|
79 |
+
{
|
80 |
+
$limit=$export_limit-$batch_offset;
|
81 |
+
}else
|
82 |
+
{
|
83 |
+
$limit=$batch_count;
|
84 |
+
}
|
85 |
+
}else
|
86 |
+
{
|
87 |
+
$limit=$export_limit;
|
88 |
+
}
|
89 |
+
|
90 |
+
$data_array = array();
|
91 |
+
if ($batch_offset < $export_limit)
|
92 |
+
{
|
93 |
+
|
94 |
+
/**
|
95 |
+
* taking total records
|
96 |
+
*/
|
97 |
+
$order_ids =0;
|
98 |
+
$total_records=0;
|
99 |
+
if($batch_offset==0) //first batch
|
100 |
+
{
|
101 |
+
if (!empty($email) && empty($products) && empty($coupons)) {
|
102 |
+
|
103 |
+
$args = array(
|
104 |
+
'customer_id' => $email,
|
105 |
+
'paginate' => true,
|
106 |
+
'return' => 'ids',
|
107 |
+
'limit' => $export_limit, //user given limi,
|
108 |
+
'offset' => $current_offset, //user given offset,
|
109 |
+
);
|
110 |
+
|
111 |
+
if ($exclude_already_exported) {
|
112 |
+
$args['wt_meta_query'][] = (array(
|
113 |
+
'key' => 'wf_order_exported_status',
|
114 |
+
'value' => FALSE,
|
115 |
+
'compare' => 'NOT EXISTS',
|
116 |
+
));
|
117 |
+
}
|
118 |
+
|
119 |
+
$ord_email = wc_get_orders($args);
|
120 |
+
|
121 |
+
$order_ids = $ord_email->orders;
|
122 |
+
} elseif (!empty($products) && empty($coupons) && empty($email)) {
|
123 |
+
$order_ids = self::hf_get_orders_of_products($products, $export_order_statuses, $export_limit, $current_offset, $end_date, $start_date, $exclude_already_exported);
|
124 |
+
} elseif (!empty($coupons) && empty($products) && empty($email)) {
|
125 |
+
$order_ids = self::hf_get_orders_of_coupons($coupons, $export_order_statuses, $export_limit, $current_offset, $end_date, $start_date, $exclude_already_exported);
|
126 |
+
} elseif (!empty($coupons) && !empty($products) && empty($email)) {
|
127 |
+
$ord_prods = self::hf_get_orders_of_products($products, $export_order_statuses, $export_limit, $current_offset, $end_date, $start_date, $exclude_already_exported);
|
128 |
+
$ord_coups = self::hf_get_orders_of_coupons($coupons, $export_order_statuses, $export_limit, $current_offset, $end_date, $start_date, $exclude_already_exported);
|
129 |
+
$order_ids = array_intersect($ord_prods, $ord_coups);
|
130 |
+
} elseif (!empty($coupons) && empty($products) && !empty($email)) {
|
131 |
+
$ord_coups = self::hf_get_orders_of_coupons($coupons, $export_order_statuses, $export_limit, $current_offset, $end_date, $start_date, $exclude_already_exported);
|
132 |
+
$args = array(
|
133 |
+
'customer_id' => $email,
|
134 |
+
);
|
135 |
+
|
136 |
+
if ($exclude_already_exported) {
|
137 |
+
$args['wt_meta_query'][] = (array(
|
138 |
+
'key' => 'wf_order_exported_status',
|
139 |
+
'value' => FALSE,
|
140 |
+
'compare' => 'NOT EXISTS',
|
141 |
+
));
|
142 |
+
}
|
143 |
+
|
144 |
+
$ord_email = wc_get_orders($args);
|
145 |
+
foreach ($ord_email as $id) {
|
146 |
+
$order_id[] = $id->get_id();
|
147 |
+
}
|
148 |
+
$order_ids = array_intersect($order_id, $ord_coups);
|
149 |
+
} elseif (empty($coupons) && !empty($products) && !empty($email)) {
|
150 |
+
$ord_prods = self::hf_get_orders_of_products($products, $export_order_statuses, $export_limit, $current_offset, $end_date, $start_date, $exclude_already_exported);
|
151 |
+
|
152 |
+
$args = array(
|
153 |
+
'customer_id' => $email,
|
154 |
+
);
|
155 |
+
|
156 |
+
$ord_email = wc_get_orders($args);
|
157 |
+
foreach ($ord_email as $id) {
|
158 |
+
$order_id[] = $id->get_id();
|
159 |
+
}
|
160 |
+
|
161 |
+
$order_ids = array_intersect($ord_prods, $order_id);
|
162 |
+
} elseif (!empty($coupons) && !empty($products) && !empty($email)) {
|
163 |
+
$ord_prods = self::hf_get_orders_of_products($products, $export_order_statuses, $export_limit, $current_offset, $end_date, $start_date, $exclude_already_exported);
|
164 |
+
$ord_coups = self::hf_get_orders_of_coupons($coupons, $export_order_statuses, $export_limit, $current_offset, $end_date, $start_date, $exclude_already_exported);
|
165 |
+
|
166 |
+
$args = array(
|
167 |
+
'customer_id' => $email,
|
168 |
+
);
|
169 |
+
|
170 |
+
if ($exclude_already_exported) {
|
171 |
+
$args['wt_meta_query'][] = (array(
|
172 |
+
'key' => 'wf_order_exported_status',
|
173 |
+
'value' => FALSE,
|
174 |
+
'compare' => 'NOT EXISTS',
|
175 |
+
));
|
176 |
+
}
|
177 |
+
|
178 |
+
$ord_email = wc_get_orders($args);
|
179 |
+
foreach ($ord_email as $id) {
|
180 |
+
$order_id[] = $id->get_id();
|
181 |
+
}
|
182 |
+
$order_ids = array_intersect($ord_prods, $ord_coups, $order_id);
|
183 |
+
} else {
|
184 |
+
$query_args = array(
|
185 |
+
'fields' => 'ids',
|
186 |
+
'post_type' => 'shop_order',
|
187 |
+
'order' => 'DESC',
|
188 |
+
'orderby' => 'ID',
|
189 |
+
'post_status' => $export_order_statuses,
|
190 |
+
'date_query' => array(
|
191 |
+
array(
|
192 |
+
'before' => $end_date,
|
193 |
+
'after' => $start_date,
|
194 |
+
'inclusive' => true,
|
195 |
+
),
|
196 |
+
),
|
197 |
+
);
|
198 |
+
|
199 |
+
if ($exclude_already_exported) {
|
200 |
+
$query_args['meta_query'][] = (array(
|
201 |
+
'key' => 'wf_order_exported_status',
|
202 |
+
'value' => FALSE,
|
203 |
+
'compare' => 'NOT EXISTS',
|
204 |
+
));
|
205 |
+
}
|
206 |
+
$query_args = apply_filters('wt_orderimpexpcsv_export_query_args', $query_args);
|
207 |
+
$query_args['offset'] = $current_offset; //user given offset
|
208 |
+
$query_args['posts_per_page'] = $export_limit; //user given limit
|
209 |
+
|
210 |
+
$query = new WP_Query($query_args);
|
211 |
+
|
212 |
+
$order_ids = $query->posts;
|
213 |
+
}
|
214 |
+
|
215 |
+
$total_records = count($order_ids);
|
216 |
+
|
217 |
+
$this->line_items_max_count = $this->get_max_line_items($order_ids);
|
218 |
+
add_option('wt_order_line_items_max_count',$this->line_items_max_count);
|
219 |
+
}
|
220 |
+
|
221 |
+
if(empty($this->line_items_max_count)){
|
222 |
+
$this->line_items_max_count = get_option('wt_order_line_items_max_count');
|
223 |
+
}
|
224 |
+
|
225 |
+
$order_ids =0;
|
226 |
+
if (!empty($email) && empty($products) && empty($coupons)) {
|
227 |
+
|
228 |
+
$args = array(
|
229 |
+
'customer_id' => $email,
|
230 |
+
'paginate' => true,
|
231 |
+
'return' => 'ids',
|
232 |
+
'order' => 'DESC',
|
233 |
+
'orderby' => 'ID',
|
234 |
+
'limit' => $limit,
|
235 |
+
'offset' => $real_offset,
|
236 |
+
);
|
237 |
+
|
238 |
+
if ($exclude_already_exported) {
|
239 |
+
$args['wt_meta_query'][] = (array(
|
240 |
+
'key' => 'wf_order_exported_status',
|
241 |
+
'value' => FALSE,
|
242 |
+
'compare' => 'NOT EXISTS',
|
243 |
+
));
|
244 |
+
}
|
245 |
+
|
246 |
+
$ord_email = wc_get_orders($args);
|
247 |
+
|
248 |
+
$order_ids = $ord_email->orders;
|
249 |
+
} elseif (!empty($products) && empty($coupons) && empty($email)) {
|
250 |
+
$order_ids = self::hf_get_orders_of_products($products, $export_order_statuses, $limit, $real_offset, $end_date, $start_date, $exclude_already_exported);
|
251 |
+
} elseif (!empty($coupons) && empty($products) && empty($email)) {
|
252 |
+
$order_ids = self::hf_get_orders_of_coupons($coupons, $export_order_statuses, $limit, $real_offset, $end_date, $start_date, $exclude_already_exported);
|
253 |
+
} elseif (!empty($coupons) && !empty($products) && empty($email)) {
|
254 |
+
$ord_prods = self::hf_get_orders_of_products($products, $export_order_statuses, $limit, $real_offset, $end_date, $start_date, $exclude_already_exported);
|
255 |
+
$ord_coups = self::hf_get_orders_of_coupons($coupons, $export_order_statuses, $limit, $real_offset, $end_date, $start_date, $exclude_already_exported);
|
256 |
+
$order_ids = array_intersect($ord_prods, $ord_coups);
|
257 |
+
} elseif (!empty($coupons) && empty($products) && !empty($email)) {
|
258 |
+
$ord_coups = self::hf_get_orders_of_coupons($coupons, $export_order_statuses, $limit, $real_offset, $end_date, $start_date, $exclude_already_exported);
|
259 |
+
|
260 |
+
$args = array(
|
261 |
+
'customer_id' => $email,
|
262 |
+
);
|
263 |
+
|
264 |
+
if ($exclude_already_exported) {
|
265 |
+
$args['wt_meta_query'][] = (array(
|
266 |
+
'key' => 'wf_order_exported_status',
|
267 |
+
'value' => FALSE,
|
268 |
+
'compare' => 'NOT EXISTS',
|
269 |
+
));
|
270 |
+
}
|
271 |
+
|
272 |
+
$ord_email = wc_get_orders($args);
|
273 |
+
foreach ($ord_email as $id) {
|
274 |
+
$order_id[] = $id->get_id();
|
275 |
+
}
|
276 |
+
$order_ids = array_intersect($order_id, $ord_coups);
|
277 |
+
} elseif (empty($coupons) && !empty($products) && !empty($email)) {
|
278 |
+
$ord_prods = self::hf_get_orders_of_products($products, $export_order_statuses, $limit, $real_offset, $end_date, $start_date, $exclude_already_exported);
|
279 |
+
|
280 |
+
$args = array(
|
281 |
+
'customer_id' => $email,
|
282 |
+
);
|
283 |
+
|
284 |
+
$ord_email = wc_get_orders($args);
|
285 |
+
foreach ($ord_email as $id) {
|
286 |
+
$order_id[] = $id->get_id();
|
287 |
+
}
|
288 |
+
|
289 |
+
$order_ids = array_intersect($ord_prods, $order_id);
|
290 |
+
} elseif (!empty($coupons) && !empty($products) && !empty($email)) {
|
291 |
+
$ord_prods = self::hf_get_orders_of_products($products, $export_order_statuses, $limit, $real_offset, $end_date, $start_date, $exclude_already_exported);
|
292 |
+
$ord_coups = self::hf_get_orders_of_coupons($coupons, $export_order_statuses, $limit, $real_offset, $end_date, $start_date, $exclude_already_exported);
|
293 |
+
|
294 |
+
$args = array(
|
295 |
+
'customer_id' => $email,
|
296 |
+
);
|
297 |
+
|
298 |
+
if ($exclude_already_exported) {
|
299 |
+
$args['wt_meta_query'][] = (array(
|
300 |
+
'key' => 'wf_order_exported_status',
|
301 |
+
'value' => FALSE,
|
302 |
+
'compare' => 'NOT EXISTS',
|
303 |
+
));
|
304 |
+
}
|
305 |
+
|
306 |
+
$ord_email = wc_get_orders($args);
|
307 |
+
foreach ($ord_email as $id) {
|
308 |
+
$order_id[] = $id->get_id();
|
309 |
+
}
|
310 |
+
$order_ids = array_intersect($ord_prods, $ord_coups, $order_id);
|
311 |
+
} else {
|
312 |
+
$query_args = array(
|
313 |
+
'fields' => 'ids',
|
314 |
+
'post_type' => 'shop_order',
|
315 |
+
'order' => 'DESC',
|
316 |
+
'orderby' => 'ID',
|
317 |
+
'post_status' => $export_order_statuses,
|
318 |
+
'date_query' => array(
|
319 |
+
array(
|
320 |
+
'before' => $end_date,
|
321 |
+
'after' => $start_date,
|
322 |
+
'inclusive' => true,
|
323 |
+
),
|
324 |
+
),
|
325 |
+
);
|
326 |
+
|
327 |
+
if ($exclude_already_exported) {
|
328 |
+
$query_args['meta_query'][] = (array(
|
329 |
+
'key' => 'wf_order_exported_status',
|
330 |
+
'value' => FALSE,
|
331 |
+
'compare' => 'NOT EXISTS',
|
332 |
+
));
|
333 |
+
}
|
334 |
+
$query_args = apply_filters('wt_orderimpexpcsv_export_query_args', $query_args);
|
335 |
+
$query_args['offset'] = $real_offset;
|
336 |
+
$query_args['posts_per_page'] = $limit;
|
337 |
+
|
338 |
+
$query = new WP_Query($query_args);
|
339 |
+
|
340 |
+
$order_ids = $query->posts;
|
341 |
+
}
|
342 |
+
|
343 |
+
$order_ids = apply_filters('wt_orderimpexpcsv_alter_order_ids', $order_ids);
|
344 |
+
|
345 |
+
foreach ($order_ids as $order_id) {
|
346 |
+
$data_array[] = $this->generate_row_data($order_id);
|
347 |
+
// updating records with expoted status
|
348 |
+
update_post_meta($order_id, 'wf_order_exported_status', TRUE);
|
349 |
+
}
|
350 |
+
|
351 |
+
$return['total'] = $total_records;
|
352 |
+
$return['data'] = $data_array;
|
353 |
+
return $return;
|
354 |
+
}
|
355 |
+
|
356 |
+
|
357 |
+
}
|
358 |
+
|
359 |
+
public function generate_row_data($order_id) {
|
360 |
+
|
361 |
+
$csv_columns = $this->prepare_header();
|
362 |
+
|
363 |
+
$row = array();
|
364 |
+
// Get an instance of the WC_Order object
|
365 |
+
$order = wc_get_order($order_id);
|
366 |
+
$line_items = $shipping_items = $fee_items = $tax_items = $coupon_items = $refund_items = array();
|
367 |
+
|
368 |
+
// get line items
|
369 |
+
foreach ($order->get_items() as $item_id => $item) {
|
370 |
+
/* WC_Abstract_Legacy_Order::get_product_from_item() deprecated since version 4.4.0*/
|
371 |
+
$product = (WC()->version < '4.4.0') ? $order->get_product_from_item($item) : $item->get_product();
|
372 |
+
if (!is_object($product)) {
|
373 |
+
$product = new WC_Product(0);
|
374 |
+
}
|
375 |
+
$item_meta = self::get_order_line_item_meta($item_id);
|
376 |
+
$prod_type = (WC()->version < '3.0.0') ? $product->product_type : $product->get_type();
|
377 |
+
$line_item = array(
|
378 |
+
'name' => html_entity_decode(!empty($item['name']) ? $item['name'] : $product->get_title(), ENT_NOQUOTES, 'UTF-8'),
|
379 |
+
'product_id' => (WC()->version < '2.7.0') ? $product->id : (($prod_type == 'variable' || $prod_type == 'variation' || $prod_type == 'subscription_variation') ? $product->get_parent_id() : $product->get_id()),
|
380 |
+
'sku' => $product->get_sku(),
|
381 |
+
'quantity' => $item['qty'],
|
382 |
+
'total' => wc_format_decimal($order->get_line_total($item), 2),
|
383 |
+
'sub_total' => wc_format_decimal($order->get_line_subtotal($item), 2),
|
384 |
+
);
|
385 |
+
|
386 |
+
//add line item tax
|
387 |
+
$line_tax_data = isset($item['line_tax_data']) ? $item['line_tax_data'] : array();
|
388 |
+
$tax_data = maybe_unserialize($line_tax_data);
|
389 |
+
$tax_detail = isset($tax_data['total']) ? wc_format_decimal(wc_round_tax_total(array_sum((array) $tax_data['total'])), 2) : '';
|
390 |
+
if ($tax_detail != '0.00' && !empty($tax_detail)) {
|
391 |
+
$line_item['tax'] = $tax_detail;
|
392 |
+
$line_tax_ser = maybe_serialize($line_tax_data);
|
393 |
+
$line_item['tax_data'] = $line_tax_ser;
|
394 |
+
}
|
395 |
+
|
396 |
+
foreach ($item_meta as $key => $value) {
|
397 |
+
switch ($key) {
|
398 |
+
case '_qty':
|
399 |
+
case '_variation_id':
|
400 |
+
case '_product_id':
|
401 |
+
case '_line_total':
|
402 |
+
case '_line_subtotal':
|
403 |
+
case '_tax_class':
|
404 |
+
case '_line_tax':
|
405 |
+
case '_line_tax_data':
|
406 |
+
case '_line_subtotal_tax':
|
407 |
+
break;
|
408 |
+
|
409 |
+
default:
|
410 |
+
if (is_object($value))
|
411 |
+
$value = $value->meta_value;
|
412 |
+
if (is_array($value))
|
413 |
+
$value = implode(',', $value);
|
414 |
+
$line_item[$key] = $value;
|
415 |
+
break;
|
416 |
+
}
|
417 |
+
}
|
418 |
+
|
419 |
+
$refunded = wc_format_decimal($order->get_total_refunded_for_item($item_id), 2);
|
420 |
+
if ($refunded != '0.00') {
|
421 |
+
$line_item['refunded'] = $refunded;
|
422 |
+
}
|
423 |
+
|
424 |
+
if ($prod_type === 'variable' || $prod_type === 'variation' || $prod_type === 'subscription_variation') {
|
425 |
+
$line_item['_variation_id'] = (WC()->version > '2.7') ? $product->get_id() : $product->variation_id;
|
426 |
+
}
|
427 |
+
$line_items[] = $line_item;
|
428 |
+
}
|
429 |
+
|
430 |
+
|
431 |
+
//shipping items is just product x qty under shipping method
|
432 |
+
$line_items_shipping = $order->get_items('shipping');
|
433 |
+
|
434 |
+
foreach ($line_items_shipping as $item_id => $item) {
|
435 |
+
$item_meta = self::get_order_line_item_meta($item_id);
|
436 |
+
foreach ($item_meta as $key => $value) {
|
437 |
+
switch ($key) {
|
438 |
+
case 'Items':
|
439 |
+
case 'method_id':
|
440 |
+
case 'taxes':
|
441 |
+
if (is_object($value))
|
442 |
+
$value = $value->meta_value;
|
443 |
+
if (is_array($value))
|
444 |
+
$value = implode(',', $value);
|
445 |
+
$meta[$key] = $value;
|
446 |
+
break;
|
447 |
+
}
|
448 |
+
}
|
449 |
+
foreach (array('Items', 'method_id', 'taxes') as $value) {
|
450 |
+
if (!isset($meta[$value])) {
|
451 |
+
$meta[$value] = '';
|
452 |
+
}
|
453 |
+
}
|
454 |
+
$shipping_items[] = trim(implode('|', array('items:' . $meta['Items'], 'method_id:' . $meta['method_id'], 'taxes:' . $meta['taxes'])));
|
455 |
+
}
|
456 |
+
|
457 |
+
//get fee and total
|
458 |
+
$fee_total = 0;
|
459 |
+
$fee_tax_total = 0;
|
460 |
+
|
461 |
+
foreach ($order->get_fees() as $fee_id => $fee) {
|
462 |
+
$fee_items[] = implode('|', array(
|
463 |
+
'name:' . html_entity_decode($fee['name'], ENT_NOQUOTES, 'UTF-8'),
|
464 |
+
'total:' . wc_format_decimal($fee['line_total'], 2),
|
465 |
+
'tax:' . wc_format_decimal($fee['line_tax'], 2),
|
466 |
+
'tax_data:' . maybe_serialize($fee['line_tax_data'])
|
467 |
+
));
|
468 |
+
$fee_total += $fee['line_total'];
|
469 |
+
$fee_tax_total += $fee['line_tax'];
|
470 |
+
}
|
471 |
+
|
472 |
+
// get tax items
|
473 |
+
foreach ($order->get_tax_totals() as $tax_code => $tax) {
|
474 |
+
$tax_items[] = implode('|', array(
|
475 |
+
'rate_id:' . $tax->rate_id,
|
476 |
+
'code:' . $tax_code,
|
477 |
+
'total:' . wc_format_decimal($tax->amount, 2),
|
478 |
+
'label:' . $tax->label,
|
479 |
+
'tax_rate_compound:' . $tax->is_compound,
|
480 |
+
));
|
481 |
+
}
|
482 |
+
|
483 |
+
// add coupons
|
484 |
+
if ( (WC()->version < '4.4.0' ) ) {
|
485 |
+
foreach ( $order->get_items('coupon') as $_ => $coupon_item ) {
|
486 |
+
$discount_amount = !empty( $coupon_item[ 'discount_amount' ] ) ? $coupon_item[ 'discount_amount' ] : 0;
|
487 |
+
$coupon_items[] = implode( '|', array(
|
488 |
+
'code:' . $coupon_item[ 'name' ],
|
489 |
+
'amount:' . wc_format_decimal( $discount_amount, 2 ),
|
490 |
+
) );
|
491 |
+
}
|
492 |
+
} else {
|
493 |
+
foreach ( $order->get_coupon_codes() as $_ => $coupon_code ) {
|
494 |
+
$coupon_obj = new WC_Coupon($coupon_code);
|
495 |
+
$discount_amount = !empty( $coupon_obj->get_amount() ) ? $coupon_obj->get_amount() : 0;
|
496 |
+
$coupon_items[] = implode( '|', array(
|
497 |
+
'code:' . $coupon_code,
|
498 |
+
'amount:' . wc_format_decimal( $discount_amount, 2 ),
|
499 |
+
) );
|
500 |
+
}
|
501 |
+
}
|
502 |
+
|
503 |
+
foreach ($order->get_refunds() as $refunded_items) {
|
504 |
+
|
505 |
+
if ((WC()->version < '2.7.0')) {
|
506 |
+
$refund_items[] = implode('|', array(
|
507 |
+
'amount:' . $refunded_items->get_refund_amount(),
|
508 |
+
'reason:' . $refunded_items->reason,
|
509 |
+
'date:' . date('Y-m-d H:i:s', strtotime($refunded_items->date_created)),
|
510 |
+
));
|
511 |
+
} else {
|
512 |
+
$refund_items[] = implode('|', array(
|
513 |
+
'amount:' . $refunded_items->get_amount(),
|
514 |
+
'reason:' . $refunded_items->get_reason(),
|
515 |
+
'date:' . date('Y-m-d H:i:s', strtotime($refunded_items->get_date_created())),
|
516 |
+
));
|
517 |
+
}
|
518 |
+
}
|
519 |
+
|
520 |
+
if (version_compare(WC_VERSION, '2.7', '<')) {
|
521 |
+
$order_data = array(
|
522 |
+
'order_id' => $order->id,
|
523 |
+
'order_number' => $order->get_order_number(),
|
524 |
+
'order_date' => date('Y-m-d H:i:s', strtotime(get_post($order->id)->post_date)),
|
525 |
+
'status' => $order->get_status(),
|
526 |
+
'shipping_total' => $order->get_total_shipping(),
|
527 |
+
'shipping_tax_total' => wc_format_decimal($order->get_shipping_tax(), 2),
|
528 |
+
'fee_total' => wc_format_decimal($fee_total, 2),
|
529 |
+
'fee_tax_total' => wc_format_decimal($fee_tax_total, 2),
|
530 |
+
'tax_total' => wc_format_decimal($order->get_total_tax(), 2),
|
531 |
+
'cart_discount' => (defined('WC_VERSION') && (WC_VERSION >= 2.3)) ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_cart_discount(), 2),
|
532 |
+
'order_discount' => (defined('WC_VERSION') && (WC_VERSION >= 2.3)) ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_order_discount(), 2),
|
533 |
+
'discount_total' => wc_format_decimal($order->get_discount_total(), 2),
|
534 |
+
'order_total' => wc_format_decimal($order->get_total(), 2),
|
535 |
+
'order_currency' => $order->get_order_currency(),
|
536 |
+
'payment_method' => $order->payment_method,
|
537 |
+
'shipping_method' => $order->get_shipping_method(),
|
538 |
+
'customer_id' => $order->get_user_id(),
|
539 |
+
'customer_user' => $order->get_user_id(),
|
540 |
+
'customer_email' => ($a = get_userdata($order->get_user_id())) ? $a->user_email : '',
|
541 |
+
'billing_first_name' => $order->billing_first_name,
|
542 |
+
'billing_last_name' => $order->billing_last_name,
|
543 |
+
'billing_company' => $order->billing_company,
|
544 |
+
'billing_email' => $order->billing_email,
|
545 |
+
'billing_phone' => $order->billing_phone,
|
546 |
+
'billing_address_1' => $order->billing_address_1,
|
547 |
+
'billing_address_2' => $order->billing_address_2,
|
548 |
+
'billing_postcode' => $order->billing_postcode,
|
549 |
+
'billing_city' => $order->billing_city,
|
550 |
+
'billing_state' => $order->billing_state,
|
551 |
+
'billing_country' => $order->billing_country,
|
552 |
+
'shipping_first_name' => $order->shipping_first_name,
|
553 |
+
'shipping_last_name' => $order->shipping_last_name,
|
554 |
+
'shipping_company' => $order->shipping_company,
|
555 |
+
'shipping_address_1' => $order->shipping_address_1,
|
556 |
+
'shipping_address_2' => $order->shipping_address_2,
|
557 |
+
'shipping_postcode' => $order->shipping_postcode,
|
558 |
+
'shipping_city' => $order->shipping_city,
|
559 |
+
'shipping_state' => $order->shipping_state,
|
560 |
+
'shipping_country' => $order->shipping_country,
|
561 |
+
'customer_note' => $order->customer_note,
|
562 |
+
'wt_import_key' => $order->get_order_number(),
|
563 |
+
'shipping_items' => self::format_data(implode(';', $shipping_items)),
|
564 |
+
'fee_items' => implode('||', $fee_items),
|
565 |
+
'tax_items' => implode(';', $tax_items),
|
566 |
+
'coupon_items' => implode(';', $coupon_items),
|
567 |
+
'refund_items' => implode(';', $refund_items),
|
568 |
+
'order_notes' => implode('||', self::get_order_notes($order)),
|
569 |
+
'download_permissions' => $order->download_permissions_granted ? $order->download_permissions_granted : 0,
|
570 |
+
);
|
571 |
+
} else {
|
572 |
+
$order_data = array(
|
573 |
+
'order_id' => $order->get_id(),
|
574 |
+
'order_number' => $order->get_order_number(),
|
575 |
+
'order_date' => date('Y-m-d H:i:s', strtotime(get_post($order->get_id())->post_date)),
|
576 |
+
'status' => $order->get_status(),
|
577 |
+
'shipping_total' => $order->get_total_shipping(),
|
578 |
+
'shipping_tax_total' => wc_format_decimal($order->get_shipping_tax(), 2),
|
579 |
+
'fee_total' => wc_format_decimal($fee_total, 2),
|
580 |
+
'fee_tax_total' => wc_format_decimal($fee_tax_total, 2),
|
581 |
+
'tax_total' => wc_format_decimal($order->get_total_tax(), 2),
|
582 |
+
'cart_discount' => (defined('WC_VERSION') && (WC_VERSION >= 2.3)) ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_cart_discount(), 2),
|
583 |
+
'order_discount' => (defined('WC_VERSION') && (WC_VERSION >= 2.3)) ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_order_discount(), 2),
|
584 |
+
'discount_total' => wc_format_decimal($order->get_total_discount(), 2),
|
585 |
+
'order_total' => wc_format_decimal($order->get_total(), 2),
|
586 |
+
'order_currency' => $order->get_currency(),
|
587 |
+
'payment_method' => $order->get_payment_method(),
|
588 |
+
'shipping_method' => $order->get_shipping_method(),
|
589 |
+
'customer_id' => $order->get_user_id(),
|
590 |
+
'customer_user' => $order->get_user_id(),
|
591 |
+
'customer_email' => ($a = get_userdata($order->get_user_id())) ? $a->user_email : '',
|
592 |
+
'billing_first_name' => $order->get_billing_first_name(),
|
593 |
+
'billing_last_name' => $order->get_billing_last_name(),
|
594 |
+
'billing_company' => $order->get_billing_company(),
|
595 |
+
'billing_email' => $order->get_billing_email(),
|
596 |
+
'billing_phone' => $order->get_billing_phone(),
|
597 |
+
'billing_address_1' => $order->get_billing_address_1(),
|
598 |
+
'billing_address_2' => $order->get_billing_address_2(),
|
599 |
+
'billing_postcode' => $order->get_billing_postcode(),
|
600 |
+
'billing_city' => $order->get_billing_city(),
|
601 |
+
'billing_state' => $order->get_billing_state(),
|
602 |
+
'billing_country' => $order->get_billing_country(),
|
603 |
+
'shipping_first_name' => $order->get_shipping_first_name(),
|
604 |
+
'shipping_last_name' => $order->get_shipping_last_name(),
|
605 |
+
'shipping_company' => $order->get_shipping_company(),
|
606 |
+
'shipping_address_1' => $order->get_shipping_address_1(),
|
607 |
+
'shipping_address_2' => $order->get_shipping_address_2(),
|
608 |
+
'shipping_postcode' => $order->get_shipping_postcode(),
|
609 |
+
'shipping_city' => $order->get_shipping_city(),
|
610 |
+
'shipping_state' => $order->get_shipping_state(),
|
611 |
+
'shipping_country' => $order->get_shipping_country(),
|
612 |
+
'customer_note' => $order->get_customer_note(),
|
613 |
+
'wt_import_key' => $order->get_order_number(),
|
614 |
+
'shipping_items' => self::format_data(implode(';', $shipping_items)),
|
615 |
+
'fee_items' => implode('||', $fee_items),
|
616 |
+
'tax_items' => implode(';', $tax_items),
|
617 |
+
'coupon_items' => implode(';', $coupon_items),
|
618 |
+
'refund_items' => implode(';', $refund_items),
|
619 |
+
'order_notes' => implode('||', (defined('WC_VERSION') && (WC_VERSION >= 3.2)) ? self::get_order_notes_new($order) : self::get_order_notes($order)),
|
620 |
+
'download_permissions' => $order->is_download_permitted() ? $order->is_download_permitted() : 0,
|
621 |
+
);
|
622 |
+
}
|
623 |
+
|
624 |
+
$order_export_data = array();
|
625 |
+
foreach ($csv_columns as $key => $value) {
|
626 |
+
if (!$order_data || array_key_exists($key, $order_data)) {
|
627 |
+
$order_export_data[$key] = $order_data[$key];
|
628 |
+
}
|
629 |
+
}
|
630 |
+
|
631 |
+
$li = 1;
|
632 |
+
foreach ($line_items as $line_item) {
|
633 |
+
foreach ($line_item as $name => $value) {
|
634 |
+
$line_item[$name] = $name . ':' . $value;
|
635 |
+
}
|
636 |
+
$line_item = implode(apply_filters('wt_change_item_separator', '|'), $line_item);
|
637 |
+
$order_export_data["line_item_{$li}"] = $line_item;
|
638 |
+
$li++;
|
639 |
+
}
|
640 |
+
|
641 |
+
$max_line_items = $this->line_items_max_count;
|
642 |
+
for ($i = 1; $i <= $max_line_items; $i++) {
|
643 |
+
$order_export_data["line_item_{$i}"] = !empty($order_export_data["line_item_{$i}"]) ? self::format_data($order_export_data["line_item_{$i}"]) : '';
|
644 |
+
}
|
645 |
+
|
646 |
+
if ($this->export_to_separate_columns) {
|
647 |
+
$line_item_values = self::get_all_metakeys_and_values($order);
|
648 |
+
$this->line_item_meta = self::get_all_line_item_metakeys();
|
649 |
+
$max_line_items = $this->line_items_max_count;
|
650 |
+
for ($i = 1; $i <= $max_line_items; $i++) {
|
651 |
+
$line_item_array = explode('|', $order_export_data["line_item_{$i}"]);
|
652 |
+
foreach ($this->line_item_meta as $meta_val) {
|
653 |
+
$order_export_data["line_item_{$i}_name"] = !empty($line_item_array[0]) ? substr($line_item_array[0], strpos($line_item_array[0], ':') + 1) : '';
|
654 |
+
$order_export_data["line_item_{$i}_product_id"] = !empty($line_item_array[1]) ? substr($line_item_array[1], strpos($line_item_array[1], ':') + 1) : '';
|
655 |
+
$order_export_data["line_item_{$i}_sku"] = !empty($line_item_array[2]) ? substr($line_item_array[2], strpos($line_item_array[2], ':') + 1) : '';
|
656 |
+
$order_export_data["line_item_{$i}_quantity"] = !empty($line_item_array[3]) ? substr($line_item_array[3], strpos($line_item_array[3], ':') + 1) : '';
|
657 |
+
$order_export_data["line_item_{$i}_total"] = !empty($line_item_array[4]) ? substr($line_item_array[4], strpos($line_item_array[4], ':') + 1) : '';
|
658 |
+
$order_export_data["line_item_{$i}_subtotal"] = !empty($line_item_array[5]) ? substr($line_item_array[5], strpos($line_item_array[5], ':') + 1) : '';
|
659 |
+
if (in_array($meta_val, array("_product_id", "_qty", "_variation_id", "_line_total", "_line_subtotal", "_tax_class", "_line_tax", "_line_tax_data", "_line_subtotal_tax"))) {
|
660 |
+
continue;
|
661 |
+
} else {
|
662 |
+
$order_export_data["line_item_{$i}_$meta_val"] = !empty($line_item_values[$i][$meta_val]) ? $line_item_values[$i][$meta_val] : '';
|
663 |
+
}
|
664 |
+
}
|
665 |
+
}
|
666 |
+
}
|
667 |
+
$order_data_filter_args = array('max_line_items' => $max_line_items);
|
668 |
+
|
669 |
+
return apply_filters('hf_alter_csv_order_data', $order_export_data, $order_data_filter_args);
|
670 |
+
}
|
671 |
+
|
672 |
+
public static function hf_get_orders_of_products($products, $export_order_statuses, $export_limit, $export_offset, $end_date, $start_date, $exclude_already_exported, $retun_count = false) {
|
673 |
+
global $wpdb;
|
674 |
+
$query .= "SELECT DISTINCT po.ID FROM {$wpdb->posts} AS po
|
675 |
+
LEFT JOIN {$wpdb->postmeta} AS pm ON pm.post_id = po.ID
|
676 |
+
LEFT JOIN {$wpdb->prefix}woocommerce_order_items AS oi ON oi.order_id = po.ID
|
677 |
+
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS om ON om.order_item_id = oi.order_item_id
|
678 |
+
WHERE po.post_type = 'shop_order'
|
679 |
+
AND oi.order_item_type = 'line_item'
|
680 |
+
AND om.meta_key IN ('_product_id','_variation_id')
|
681 |
+
AND om.meta_value IN ('" . implode("','", $products) . "')
|
682 |
+
AND (po.post_date BETWEEN '$start_date' AND '$end_date')";
|
683 |
+
if ($export_order_statuses != 'any') {
|
684 |
+
$query .= " AND po.post_status IN ( '" . implode("','", $export_order_statuses) . "' )";
|
685 |
+
}
|
686 |
+
|
687 |
+
if ($exclude_already_exported) {
|
688 |
+
$query .= " AND pm.meta_key = 'wf_order_exported_status' AND pm.meta_value=1";
|
689 |
+
}
|
690 |
+
|
691 |
+
if ($retun_count == FALSE) {
|
692 |
+
$query .= " LIMIT " . intval($export_limit) . ' ' . (!empty($export_offset) ? 'OFFSET ' . intval($export_offset) : '');
|
693 |
+
}
|
694 |
+
|
695 |
+
$order_ids = $wpdb->get_col($query);
|
696 |
+
|
697 |
+
if ($retun_count == TRUE) {
|
698 |
+
return count($order_ids);
|
699 |
+
}
|
700 |
+
return $order_ids;
|
701 |
+
}
|
702 |
+
|
703 |
+
public static function hf_get_orders_of_coupons($coupons, $export_order_statuses, $export_limit, $export_offset, $end_date, $start_date, $exclude_already_exported, $retun_count = false) {
|
704 |
+
global $wpdb;
|
705 |
+
$query = "SELECT DISTINCT po.ID FROM {$wpdb->posts} AS po
|
706 |
+
LEFT JOIN {$wpdb->postmeta} AS pm ON pm.post_id = po.ID
|
707 |
+
LEFT JOIN {$wpdb->prefix}woocommerce_order_items AS oi ON oi.order_id = po.ID
|
708 |
+
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS om ON om.order_item_id = oi.order_item_id
|
709 |
+
WHERE po.post_type = 'shop_order'
|
710 |
+
AND oi.order_item_type = 'coupon'
|
711 |
+
AND oi.order_item_name IN ('" . implode("','", $coupons) . "')
|
712 |
+
AND (po.post_date BETWEEN '$start_date' AND '$end_date')";
|
713 |
+
if ($export_order_statuses != 'any') {
|
714 |
+
$query .= " AND po.post_status IN ( '" . implode("','", $export_order_statuses) . "' )";
|
715 |
+
}
|
716 |
+
if ($exclude_already_exported) {
|
717 |
+
$query .= " AND pm.meta_key = 'wf_order_exported_status' AND pm.meta_value=1";
|
718 |
+
}
|
719 |
+
if ($retun_count == FALSE) {
|
720 |
+
$query .= " LIMIT " . intval($export_limit) . ' ' . (!empty($export_offset) ? 'OFFSET ' . intval($export_offset) : '');
|
721 |
+
}
|
722 |
+
$order_ids = $wpdb->get_col($query);
|
723 |
+
if ($retun_count == TRUE) {
|
724 |
+
return count($order_ids);
|
725 |
+
}
|
726 |
+
return $order_ids;
|
727 |
+
}
|
728 |
+
|
729 |
+
public static function get_all_line_item_metakeys() {
|
730 |
+
global $wpdb;
|
731 |
+
$filter_meta = apply_filters('wt_order_export_select_line_item_meta', array());
|
732 |
+
$filter_meta = !empty($filter_meta) ? implode("','", $filter_meta) : '';
|
733 |
+
$query = "SELECT DISTINCT om.meta_key
|
734 |
+
FROM {$wpdb->prefix}woocommerce_order_itemmeta AS om
|
735 |
+
INNER JOIN {$wpdb->prefix}woocommerce_order_items AS oi ON om.order_item_id = oi.order_item_id
|
736 |
+
WHERE oi.order_item_type = 'line_item'";
|
737 |
+
if (!empty($filter_meta)) {
|
738 |
+
$query .= " AND om.meta_key IN ('" . $filter_meta . "')";
|
739 |
+
}
|
740 |
+
$meta_keys = $wpdb->get_col($query);
|
741 |
+
return $meta_keys;
|
742 |
+
}
|
743 |
+
|
744 |
+
public static function get_order_line_item_meta($item_id) {
|
745 |
+
global $wpdb;
|
746 |
+
$filtered_meta = apply_filters('wt_order_export_select_line_item_meta', array());
|
747 |
+
$filtered_meta = !empty($filtered_meta) ? implode("','", $filtered_meta) : '';
|
748 |
+
$query = "SELECT meta_key,meta_value
|
749 |
+
FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE order_item_id = '$item_id'";
|
750 |
+
if (!empty($filtered_meta)) {
|
751 |
+
$query .= " AND meta_key IN ('" . $filtered_meta . "')";
|
752 |
+
}
|
753 |
+
$meta_keys = $wpdb->get_results($query, OBJECT_K);
|
754 |
+
return $meta_keys;
|
755 |
+
}
|
756 |
+
|
757 |
+
public static function get_order_notes($order) {
|
758 |
+
$callback = array('WC_Comments', 'exclude_order_comments');
|
759 |
+
$args = array(
|
760 |
+
'post_id' => (WC()->version < '2.7.0') ? $order->id : $order->get_id(),
|
761 |
+
'approve' => 'approve',
|
762 |
+
'type' => 'order_note'
|
763 |
+
);
|
764 |
+
remove_filter('comments_clauses', $callback);
|
765 |
+
$notes = get_comments($args);
|
766 |
+
add_filter('comments_clauses', $callback);
|
767 |
+
$notes = array_reverse($notes);
|
768 |
+
$order_notes = array();
|
769 |
+
foreach ($notes as $note) {
|
770 |
+
$date = $note->comment_date;
|
771 |
+
$customer_note = 0;
|
772 |
+
if (get_comment_meta($note->comment_ID, 'is_customer_note', '1')) {
|
773 |
+
$customer_note = 1;
|
774 |
+
}
|
775 |
+
$order_notes[] = implode('|', array(
|
776 |
+
'content:' . str_replace(array("\r", "\n"), ' ', $note->comment_content),
|
777 |
+
'date:' . (!empty($date) ? $date : current_time('mysql')),
|
778 |
+
'customer:' . $customer_note,
|
779 |
+
'added_by:' . $note->added_by
|
780 |
+
));
|
781 |
+
}
|
782 |
+
return $order_notes;
|
783 |
+
}
|
784 |
+
|
785 |
+
public static function get_order_notes_new($order) {
|
786 |
+
$notes = wc_get_order_notes(array('order_id' => $order->get_id(), 'order_by' => 'date_created', 'order' => 'ASC'));
|
787 |
+
$order_notes = array();
|
788 |
+
foreach ($notes as $note) {
|
789 |
+
$order_notes[] = implode('|', array(
|
790 |
+
'content:' . str_replace(array("\r", "\n"), ' ', $note->content),
|
791 |
+
'date:' . $note->date_created->date('Y-m-d H:i:s'),
|
792 |
+
'customer:' . $note->customer_note,
|
793 |
+
'added_by:' . $note->added_by
|
794 |
+
));
|
795 |
+
}
|
796 |
+
return $order_notes;
|
797 |
+
}
|
798 |
+
|
799 |
+
public static function get_all_metakeys_and_values($order = null) {
|
800 |
+
$in = 1;
|
801 |
+
foreach ($order->get_items() as $item_id => $item) {
|
802 |
+
//$item_meta = function_exists('wc_get_order_item_meta') ? wc_get_order_item_meta($item_id, '', false) : $order->get_item_meta($item_id);
|
803 |
+
$item_meta = self::get_order_line_item_meta($item_id);
|
804 |
+
foreach ($item_meta as $key => $value) {
|
805 |
+
switch ($key) {
|
806 |
+
case '_qty':
|
807 |
+
case '_product_id':
|
808 |
+
case '_line_total':
|
809 |
+
case '_line_subtotal':
|
810 |
+
case '_tax_class':
|
811 |
+
case '_line_tax':
|
812 |
+
case '_line_tax_data':
|
813 |
+
case '_line_subtotal_tax':
|
814 |
+
break;
|
815 |
+
|
816 |
+
default:
|
817 |
+
if (is_object($value))
|
818 |
+
$value = $value->meta_value;
|
819 |
+
if (is_array($value))
|
820 |
+
$value = implode(',', $value);
|
821 |
+
$line_item_value[$key] = $value;
|
822 |
+
break;
|
823 |
+
}
|
824 |
+
}
|
825 |
+
$line_item_values[$in] = !empty($line_item_value) ? $line_item_value : '';
|
826 |
+
$in++;
|
827 |
+
}
|
828 |
+
return $line_item_values;
|
829 |
+
}
|
830 |
+
|
831 |
+
/**
|
832 |
+
* Format the data if required
|
833 |
+
* @param string $meta_value
|
834 |
+
* @param string $meta name of meta key
|
835 |
+
* @return string
|
836 |
+
*/
|
837 |
+
public static function format_export_meta($meta_value, $meta) {
|
838 |
+
switch ($meta) {
|
839 |
+
case '_sale_price_dates_from' :
|
840 |
+
case '_sale_price_dates_to' :
|
841 |
+
return $meta_value ? date('Y-m-d', $meta_value) : '';
|
842 |
+
break;
|
843 |
+
case '_upsell_ids' :
|
844 |
+
case '_crosssell_ids' :
|
845 |
+
return implode('|', array_filter((array) json_decode($meta_value)));
|
846 |
+
break;
|
847 |
+
default :
|
848 |
+
return $meta_value;
|
849 |
+
break;
|
850 |
+
}
|
851 |
+
}
|
852 |
+
|
853 |
+
public static function format_data($data) {
|
854 |
+
if (!is_array($data))
|
855 |
+
;
|
856 |
+
$data = (string) urldecode($data);
|
857 |
+
// $enc = mb_detect_encoding($data, 'UTF-8, ISO-8859-1', true);
|
858 |
+
$use_mb = function_exists('mb_detect_encoding');
|
859 |
+
$enc = '';
|
860 |
+
if ($use_mb) {
|
861 |
+
$enc = mb_detect_encoding($data, 'UTF-8, ISO-8859-1', true);
|
862 |
+
}
|
863 |
+
$data = ( $enc == 'UTF-8' ) ? $data : utf8_encode($data);
|
864 |
+
|
865 |
+
return $data;
|
866 |
+
}
|
867 |
+
|
868 |
+
/**
|
869 |
+
* Wrap a column in quotes for the CSV
|
870 |
+
* @param string data to wrap
|
871 |
+
* @return string wrapped data
|
872 |
+
*/
|
873 |
+
public static function wrap_column($data) {
|
874 |
+
return '"' . str_replace('"', '""', $data) . '"';
|
875 |
+
}
|
876 |
+
|
877 |
+
public static function get_max_line_items($order_ids) {
|
878 |
+
$max_line_items = 0;
|
879 |
+
foreach ($order_ids as $order_id) {
|
880 |
+
$order = wc_get_order($order_id);
|
881 |
+
$line_items_count = count($order->get_items());
|
882 |
+
if ($line_items_count >= $max_line_items) {
|
883 |
+
$max_line_items = $line_items_count;
|
884 |
+
}
|
885 |
+
}
|
886 |
+
return $max_line_items;
|
887 |
+
}
|
888 |
+
|
889 |
+
}
|
890 |
+
}
|
891 |
+
|
892 |
+
|
893 |
+
/*
|
894 |
+
* https://github.com/woocommerce/woocommerce/wiki/wc_get_orders-and-WC_Order_Query#adding-custom-parameter-support
|
895 |
+
* It is possible to add support for custom query variables in wc_get_orders and WC_Order_Query. To do this you need to filter the generated query.
|
896 |
+
*/
|
897 |
+
add_filter('woocommerce_order_data_store_cpt_get_orders_query', function ($query, $query_vars) {
|
898 |
+
if (!empty($query_vars['wt_meta_query'])) {
|
899 |
+
|
900 |
+
foreach ($query_vars['wt_meta_query'] as $meta_querys) {
|
901 |
+
|
902 |
+
foreach ($meta_querys as $key => $value) {
|
903 |
+
$meta_query[$key] = $value;
|
904 |
+
}
|
905 |
+
if (!empty($meta_query)) {
|
906 |
+
$query['meta_query'][] = $meta_query;
|
907 |
+
}
|
908 |
+
}
|
909 |
+
}
|
910 |
+
return $query;
|
911 |
+
}, 10, 2);
|
admin/modules/order/import/import.php
ADDED
@@ -0,0 +1,2121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if (!defined('WPINC')) {
|
4 |
+
exit;
|
5 |
+
}
|
6 |
+
|
7 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Basic_Order_Import')){
|
8 |
+
class Wt_Import_Export_For_Woo_Basic_Order_Import {
|
9 |
+
|
10 |
+
public $post_type = 'shop_order';
|
11 |
+
public $parent_module = null;
|
12 |
+
public $parsed_data = array();
|
13 |
+
public $import_columns = array();
|
14 |
+
public $merge;
|
15 |
+
public $skip_new;
|
16 |
+
public $merge_empty_cells;
|
17 |
+
public $delete_existing;
|
18 |
+
public $ord_link_using_sku;
|
19 |
+
public $create_user;
|
20 |
+
public $status_mail;
|
21 |
+
public $new_order_status;
|
22 |
+
public $allow_unknown_products = true;
|
23 |
+
public $item_data = array();
|
24 |
+
public $is_order_exist = false;
|
25 |
+
public $found_action = 'skip';
|
26 |
+
public $id_conflict = 'skip';
|
27 |
+
|
28 |
+
// Results
|
29 |
+
var $import_results = array();
|
30 |
+
|
31 |
+
public function __construct($parent_object) {
|
32 |
+
|
33 |
+
$this->parent_module = $parent_object;
|
34 |
+
}
|
35 |
+
|
36 |
+
/* WC object based import */
|
37 |
+
|
38 |
+
public function prepare_data_to_import($import_data, $form_data, $batch_offset, $is_last_batch) {
|
39 |
+
|
40 |
+
$this->found_action = !empty($form_data['advanced_form_data']['wt_iew_found_action']) ? $form_data['advanced_form_data']['wt_iew_found_action'] : 'skip';
|
41 |
+
$this->id_conflict = !empty($form_data['advanced_form_data']['wt_iew_id_conflict']) ? $form_data['advanced_form_data']['wt_iew_id_conflict'] : 'skip';
|
42 |
+
$this->merge_empty_cells = !empty($form_data['advanced_form_data']['wt_iew_merge_empty_cells']) ? 1 : 0;
|
43 |
+
$this->skip_new = !empty($form_data['advanced_form_data']['wt_iew_skip_new']) ? 1 : 0;
|
44 |
+
|
45 |
+
$this->delete_existing = !empty($form_data['advanced_form_data']['wt_iew_delete_existing']) ? 1 : 0;
|
46 |
+
|
47 |
+
$this->ord_link_using_sku = !empty($form_data['advanced_form_data']['wt_iew_ord_link_using_sku']) ? 1 : 0;
|
48 |
+
$this->create_user = !empty($form_data['advanced_form_data']['wt_iew_create_user']) ? 1 : 0;
|
49 |
+
$this->notify_customer = !empty($form_data['advanced_form_data']['wt_iew_notify_customer']) ? 1 : 0;
|
50 |
+
$this->status_mail = !empty($form_data['advanced_form_data']['wt_iew_status_mail']) ? 1 : 0;
|
51 |
+
|
52 |
+
Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Preparing for import.");
|
53 |
+
|
54 |
+
$success = 0;
|
55 |
+
$failed = 0;
|
56 |
+
$msg = 'Order imported successfully.';
|
57 |
+
|
58 |
+
foreach ($import_data as $key => $data) {
|
59 |
+
$row = $batch_offset+$key+1;
|
60 |
+
Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Row :$row - Parsing item.");
|
61 |
+
$parsed_data = $this->parse_data($data);
|
62 |
+
if (!is_wp_error($parsed_data)){
|
63 |
+
Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Row :$row - Processing item.");
|
64 |
+
$result = $this->process_item($parsed_data);
|
65 |
+
if(!is_wp_error($result)){
|
66 |
+
if($this->is_order_exist){
|
67 |
+
$msg = 'Order updated successfully.';
|
68 |
+
}
|
69 |
+
$this->import_results[$row] = array('row'=>$row, 'message'=>$msg, 'status'=>true, 'post_id'=>$result['id']);
|
70 |
+
Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Row :$row - ".$msg);
|
71 |
+
$success++;
|
72 |
+
}else{
|
73 |
+
$this->import_results[$row] = array('row'=>$row, 'message'=>$result->get_error_message(), 'status'=>false, 'post_id'=>'');
|
74 |
+
Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Row :$row - Processing failed. Reason: ".$result->get_error_message());
|
75 |
+
$failed++;
|
76 |
+
}
|
77 |
+
}else{
|
78 |
+
$this->import_results[$row] = array('row'=>$row, 'message'=>$parsed_data->get_error_message(), 'status'=>false, 'post_id'=>'');
|
79 |
+
Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Row :$row - Parsing failed. Reason: ".$parsed_data->get_error_message());
|
80 |
+
$failed++;
|
81 |
+
}
|
82 |
+
}
|
83 |
+
|
84 |
+
if($is_last_batch && $this->delete_existing){
|
85 |
+
$this->delete_existing();
|
86 |
+
}
|
87 |
+
|
88 |
+
$this->clean_after_import();
|
89 |
+
|
90 |
+
$import_response=array(
|
91 |
+
'total_success'=>$success,
|
92 |
+
'total_failed'=>$failed,
|
93 |
+
'log_data'=>$this->import_results,
|
94 |
+
);
|
95 |
+
|
96 |
+
return $import_response;
|
97 |
+
}
|
98 |
+
|
99 |
+
public function clean_after_import() {
|
100 |
+
global $wpdb;
|
101 |
+
$posts = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_status = '%s' AND post_type = '%s' ", 'importing' ,$this->post_type));
|
102 |
+
if($posts){
|
103 |
+
array_map('wp_delete_post',$posts);
|
104 |
+
}
|
105 |
+
}
|
106 |
+
|
107 |
+
public function delete_existing() {
|
108 |
+
|
109 |
+
$posts = new WP_Query([
|
110 |
+
'post_type' => $this->post_type,
|
111 |
+
'fields' => 'ids',
|
112 |
+
'posts_per_page' => -1,
|
113 |
+
'post_status' => array_keys($this->wc_get_order_statuses_neat()),
|
114 |
+
'meta_query' => [
|
115 |
+
[
|
116 |
+
'key' => '_wt_delete_existing',
|
117 |
+
'compare' => 'NOT EXISTS',
|
118 |
+
]
|
119 |
+
]
|
120 |
+
]);
|
121 |
+
|
122 |
+
foreach ($posts->posts as $post) {
|
123 |
+
$this->import_results['detele_results'][$post] = wp_trash_post($post);
|
124 |
+
}
|
125 |
+
|
126 |
+
|
127 |
+
$posts = new WP_Query([
|
128 |
+
'post_type' => $this->post_type,
|
129 |
+
'fields' => 'ids',
|
130 |
+
'posts_per_page' => -1,
|
131 |
+
'post_status' => array_keys($this->wc_get_order_statuses_neat()),
|
132 |
+
'meta_query' => [
|
133 |
+
[
|
134 |
+
'key' => '_wt_delete_existing',
|
135 |
+
'compare' => 'EXISTS',
|
136 |
+
]
|
137 |
+
]
|
138 |
+
]);
|
139 |
+
foreach ($posts->posts as $post) {
|
140 |
+
delete_post_meta($post,'_wt_delete_existing');
|
141 |
+
}
|
142 |
+
|
143 |
+
}
|
144 |
+
|
145 |
+
/**
|
146 |
+
* Parse the data.
|
147 |
+
*
|
148 |
+
*
|
149 |
+
* @param array $data value.
|
150 |
+
*
|
151 |
+
* @return array
|
152 |
+
*/
|
153 |
+
public function parse_data($data) {
|
154 |
+
|
155 |
+
try {
|
156 |
+
$data = apply_filters('wt_woocommerce_order_importer_pre_parse_data', $data);
|
157 |
+
|
158 |
+
$mapping_fields = $data['mapping_fields'];
|
159 |
+
|
160 |
+
$this->item_data = array(); // resetting WC default data before parsing new item to avoid merging last parsed item wp_parse_args
|
161 |
+
|
162 |
+
if(isset($mapping_fields['order_id']) && !empty($mapping_fields['order_id'])){
|
163 |
+
$this->item_data['order_id'] = $this->wt_order_existance_check($mapping_fields['order_id']); // to determine wether merge or import
|
164 |
+
}
|
165 |
+
|
166 |
+
|
167 |
+
if(!$this->merge){
|
168 |
+
$default_data = $this->get_default_data();
|
169 |
+
$this->item_data = wp_parse_args( $this->item_data, $default_data );
|
170 |
+
}
|
171 |
+
|
172 |
+
|
173 |
+
if($this->merge && !$this->merge_empty_cells){
|
174 |
+
$this->item_data = array();
|
175 |
+
$this->item_data['order_id'] = $this->order_id; // $this->order_id set from wt_order_existance_check
|
176 |
+
}
|
177 |
+
|
178 |
+
foreach ($mapping_fields as $column => $value) {
|
179 |
+
if($this->merge && !$this->merge_empty_cells && $value == ''){
|
180 |
+
continue;
|
181 |
+
}
|
182 |
+
|
183 |
+
$column = strtolower($column);
|
184 |
+
|
185 |
+
if ('order_number' == $column) {
|
186 |
+
$this->item_data['order_number'] = ($value);
|
187 |
+
continue;
|
188 |
+
}
|
189 |
+
|
190 |
+
if ('parent_id' == $column || 'post_parent' == $column) {
|
191 |
+
$this->item_data['parent_id'] = $this->wt_parse_int_field($value);
|
192 |
+
continue;
|
193 |
+
}
|
194 |
+
|
195 |
+
|
196 |
+
|
197 |
+
if ( 'date_created' == $column || 'post_date' == $column || '_paid_date' == $column || 'order_date' == $column) {
|
198 |
+
$date = $this->wt_parse_date_field($value,$column);
|
199 |
+
$this->item_data['date_created'] = date('Y-m-d H:i:s', $date);
|
200 |
+
//$this->item_data['date_paid'] = date('Y-m-d H:i:s', $date);
|
201 |
+
continue;
|
202 |
+
}
|
203 |
+
|
204 |
+
if ('post_modified' == $column || 'date_modified' == $column || 'date_completed' == $column || '_completed_date' == $column ) {
|
205 |
+
$date = $this->wt_parse_date_field($value,$column);
|
206 |
+
$this->item_data['date_modified'] = date('Y-m-d H:i:s', $date);
|
207 |
+
$this->item_data['date_completed'] = date('Y-m-d H:i:s', $date);
|
208 |
+
continue;
|
209 |
+
}
|
210 |
+
|
211 |
+
if ('status' == $column || 'post_status' == $column) {
|
212 |
+
$this->item_data['status'] = $this->wt_parse_status_field($value);
|
213 |
+
continue;
|
214 |
+
}
|
215 |
+
|
216 |
+
if ('shipping_tax_total' == $column ) {
|
217 |
+
$this->item_data['shipping_tax_total'] = wc_format_decimal($value);
|
218 |
+
$this->item_data['shipping_tax'] = wc_format_decimal($value);
|
219 |
+
continue;
|
220 |
+
}
|
221 |
+
if ('fee_total' == $column ) {
|
222 |
+
$this->item_data['fee_total'] = wc_format_decimal($value);
|
223 |
+
continue;
|
224 |
+
}
|
225 |
+
if ('fee_tax_total' == $column ) {
|
226 |
+
$this->item_data['fee_tax_total'] = wc_format_decimal($value);
|
227 |
+
continue;
|
228 |
+
}
|
229 |
+
if ('tax_total' == $column ) {
|
230 |
+
$this->item_data['tax_total'] = wc_format_decimal($value);
|
231 |
+
continue;
|
232 |
+
}
|
233 |
+
if ('cart_discount' == $column ) {
|
234 |
+
$this->item_data['cart_discount'] = wc_format_decimal($value);
|
235 |
+
$this->item_data['cart_tax'] = wc_format_decimal($value);
|
236 |
+
continue;
|
237 |
+
}
|
238 |
+
if ('order_discount' == $column ) {
|
239 |
+
$this->item_data['order_discount'] = wc_format_decimal($value);
|
240 |
+
continue;
|
241 |
+
}
|
242 |
+
if ('discount_total' == $column ) {
|
243 |
+
$this->item_data['discount_total'] = wc_format_decimal($value);
|
244 |
+
$this->item_data['discount_tax'] = wc_format_decimal($value);
|
245 |
+
continue;
|
246 |
+
}
|
247 |
+
if ('order_total' == $column ) {
|
248 |
+
$this->item_data['order_total'] = wc_format_decimal($value);
|
249 |
+
$this->item_data['total'] = wc_format_decimal($value);
|
250 |
+
$this->item_data['total_tax'] = wc_format_decimal($value);
|
251 |
+
continue;
|
252 |
+
}
|
253 |
+
if ('order_currency' == $column ) {
|
254 |
+
$this->item_data['currency'] = ($value) ? $value : get_woocommerce_currency();
|
255 |
+
continue;
|
256 |
+
}
|
257 |
+
if ('payment_method' == $column) {
|
258 |
+
$this->item_data['payment_method'] = $this->wt_parse_payment_method_field($value);
|
259 |
+
continue;
|
260 |
+
}
|
261 |
+
if ('shipping_method' == $column ) {
|
262 |
+
$this->item_data['shipping_method'] = $this->wt_parse_shipping_method_field($value);
|
263 |
+
continue;
|
264 |
+
}
|
265 |
+
if ('order_shipping' == $column || 'shipping_total' == $column) {
|
266 |
+
if ('shipping_total' == $column ) {
|
267 |
+
$this->item_data['shipping_total'] = wc_format_decimal($value);
|
268 |
+
}
|
269 |
+
$this->item_data['order_shipping'] = $this->wt_parse_order_shipping_field($value,$column,$mapping_fields); // special case need to rewrite this concept
|
270 |
+
continue;
|
271 |
+
}
|
272 |
+
if ('customer_user' == $column || 'customer_email' == $column || 'customer_id' == $column ) {
|
273 |
+
$this->wt_parse_customer_id_field($value,$column,$mapping_fields);
|
274 |
+
continue;
|
275 |
+
}
|
276 |
+
if ('billing_first_name' == $column ) {
|
277 |
+
$this->item_data['billing']['first_name'] = ($value);
|
278 |
+
continue;
|
279 |
+
}
|
280 |
+
if ('billing_last_name' == $column ) {
|
281 |
+
$this->item_data['billing']['last_name'] = ($value);
|
282 |
+
continue;
|
283 |
+
}
|
284 |
+
if ('billing_company' == $column ) {
|
285 |
+
$this->item_data['billing']['company'] = ($value);
|
286 |
+
continue;
|
287 |
+
}
|
288 |
+
if ('billing_email' == $column ) {
|
289 |
+
$this->item_data['billing']['email'] = $this->wt_parse_email_field($value);
|
290 |
+
continue;
|
291 |
+
}
|
292 |
+
if ('billing_phone' == $column ) {
|
293 |
+
$this->item_data['billing']['phone'] = ($value);
|
294 |
+
continue;
|
295 |
+
}
|
296 |
+
if ('billing_address_1' == $column ) {
|
297 |
+
$this->item_data['billing']['address_1'] = ($value);
|
298 |
+
continue;
|
299 |
+
}
|
300 |
+
if ('billing_address_2' == $column ) {
|
301 |
+
$this->item_data['billing']['address_2'] = ($value);
|
302 |
+
continue;
|
303 |
+
}
|
304 |
+
if ('billing_postcode' == $column ) {
|
305 |
+
$this->item_data['billing']['postcode'] = ($value);
|
306 |
+
continue;
|
307 |
+
}
|
308 |
+
if ('billing_city' == $column ) {
|
309 |
+
$this->item_data['billing']['city'] = ($value);
|
310 |
+
continue;
|
311 |
+
}
|
312 |
+
if ('billing_state' == $column ) {
|
313 |
+
$this->item_data['billing']['state'] = ($value);
|
314 |
+
continue;
|
315 |
+
}
|
316 |
+
if ('billing_country' == $column ) {
|
317 |
+
$this->item_data['billing']['country'] = ($value);
|
318 |
+
continue;
|
319 |
+
}
|
320 |
+
if ('shipping_first_name' == $column ) {
|
321 |
+
$this->item_data['shipping']['first_name'] = ($value);
|
322 |
+
continue;
|
323 |
+
}
|
324 |
+
if ('shipping_last_name' == $column ) {
|
325 |
+
$this->item_data['shipping']['last_name'] = ($value);
|
326 |
+
continue;
|
327 |
+
}
|
328 |
+
if ('shipping_company' == $column ) {
|
329 |
+
$this->item_data['shipping']['company'] = ($value);
|
330 |
+
continue;
|
331 |
+
}
|
332 |
+
if ('shipping_address_1' == $column) {
|
333 |
+
$this->item_data['shipping']['address_1'] = ($value);
|
334 |
+
continue;
|
335 |
+
}
|
336 |
+
if ('shipping_address_2' == $column ) {
|
337 |
+
$this->item_data['shipping']['address_2'] = ($value);
|
338 |
+
continue;
|
339 |
+
}
|
340 |
+
if ('shipping_postcode' == $column ) {
|
341 |
+
$this->item_data['shipping']['postcode'] = ($value);
|
342 |
+
continue;
|
343 |
+
}
|
344 |
+
if ('shipping_city' == $column ) {
|
345 |
+
$this->item_data['shipping']['city'] = ($value);
|
346 |
+
continue;
|
347 |
+
}
|
348 |
+
if ('shipping_state' == $column ) {
|
349 |
+
$this->item_data['shipping']['state'] = ($value);
|
350 |
+
continue;
|
351 |
+
}
|
352 |
+
if ('shipping_country' == $column ) {
|
353 |
+
$this->item_data['shipping']['country'] = ($value);
|
354 |
+
continue;
|
355 |
+
}
|
356 |
+
if ('customer_note' == $column || 'post_excerpt' == $column ) {
|
357 |
+
$this->item_data['customer_note'] = ($value);
|
358 |
+
continue;
|
359 |
+
}
|
360 |
+
|
361 |
+
if ('shipping_items' == $column ) {
|
362 |
+
$this->item_data['shipping_items'] = $this->wt_parse_shipping_items_field($value);
|
363 |
+
continue;
|
364 |
+
}
|
365 |
+
if ('fee_items' == $column) {
|
366 |
+
$this->item_data['fee_items'] = $this->wt_parse_fee_items_field($value);
|
367 |
+
continue;
|
368 |
+
}
|
369 |
+
if ('tax_items' == $column) {
|
370 |
+
$this->item_data['tax_items'] = $this->wt_parse_tax_items_field($value);
|
371 |
+
continue;
|
372 |
+
}
|
373 |
+
if ('coupon_items' == $column) {
|
374 |
+
$this->item_data['coupon_items'] = $this->wt_parse_coupon_items_field($value);
|
375 |
+
continue;
|
376 |
+
}
|
377 |
+
if ('refund_items' == $column) {
|
378 |
+
$this->item_data['refund_items'] = $this->wt_parse_refund_items_field($value);
|
379 |
+
continue;
|
380 |
+
}
|
381 |
+
if ('order_notes' == $column) {
|
382 |
+
$this->item_data['order_notes'] = $this->wt_parse_order_notes_field($value);
|
383 |
+
continue;
|
384 |
+
}
|
385 |
+
if ('download_permissions' == $column) {
|
386 |
+
$this->item_data['meta_data'][] = array('key' => '_download_permissions_granted', 'value' => $value);
|
387 |
+
$this->item_data['meta_data'][] = array('key' => '_download_permissions', 'value' => $value);
|
388 |
+
continue;
|
389 |
+
}
|
390 |
+
if ('wt_import_key' == $column ) {
|
391 |
+
$this->item_data['meta_data'][] = array('key'=>'_wt_import_key','value'=>$value);
|
392 |
+
continue;
|
393 |
+
}
|
394 |
+
if(strstr($column, 'line_item_')){
|
395 |
+
$this->item_data['order_items'][] = $this->wt_parse_line_item_field($value,$column);
|
396 |
+
continue;
|
397 |
+
}
|
398 |
+
|
399 |
+
}
|
400 |
+
|
401 |
+
if(empty($this->item_data['order_id'])){
|
402 |
+
$this->item_data['order_id'] = $this->wt_parse_id_field($mapping_fields,$this->item_data);
|
403 |
+
}
|
404 |
+
|
405 |
+
return $this->item_data;
|
406 |
+
} catch (Exception $e) {
|
407 |
+
return new WP_Error('woocommerce_product_importer_error', $e->getMessage(), array('status' => $e->getCode()));
|
408 |
+
}
|
409 |
+
|
410 |
+
}
|
411 |
+
|
412 |
+
public function wt_order_existance_check($id){
|
413 |
+
global $wpdb;
|
414 |
+
$order_id = 0;
|
415 |
+
$this->merge = false;
|
416 |
+
$this->is_order_exist = false;
|
417 |
+
|
418 |
+
$id = absint($id);
|
419 |
+
$id_found_with_id = '';
|
420 |
+
if($id){
|
421 |
+
$id_found_with_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_status IN ( 'wc-pending', 'wc-processing', 'wc-completed', 'wc-on-hold', 'wc-failed' , 'wc-refunded', 'wc-cancelled') AND ID = %d;", $id)); // WPCS: db call ok, cache ok.
|
422 |
+
if($id_found_with_id){
|
423 |
+
if($this->post_type == get_post_type($id_found_with_id)){
|
424 |
+
$this->is_order_exist = true;
|
425 |
+
$order_id = $id_found_with_id;
|
426 |
+
}
|
427 |
+
}
|
428 |
+
}
|
429 |
+
|
430 |
+
if($this->is_order_exist){
|
431 |
+
if('skip' == $this->found_action){
|
432 |
+
if($id && $id_found_with_id ){
|
433 |
+
throw new Exception(sprintf('Order with same ID already exists. ID: %d',$id ));
|
434 |
+
}
|
435 |
+
}elseif('update' == $this->found_action){
|
436 |
+
$this->merge = true;
|
437 |
+
$this->order_id = $order_id;
|
438 |
+
return $order_id;
|
439 |
+
}
|
440 |
+
}
|
441 |
+
|
442 |
+
if($this->skip_new){
|
443 |
+
throw new Exception('Skipping new item' );
|
444 |
+
}
|
445 |
+
|
446 |
+
if ($id && is_string(get_post_status($id)) && (get_post_type($id) !== $this->post_type ) && !$this->is_order_exist && 'skip' == $this->id_conflict) {
|
447 |
+
throw new Exception(sprintf('Importing Order(ID) conflicts with an existing post. ID: %d',$id ));
|
448 |
+
}
|
449 |
+
|
450 |
+
}
|
451 |
+
|
452 |
+
/**
|
453 |
+
* Explode CSV cell values using commas by default, and handling escaped
|
454 |
+
* separators.
|
455 |
+
*
|
456 |
+
* @since 3.2.0
|
457 |
+
* @param string $value Value to explode.
|
458 |
+
* @param string $separator Separator separating each value. Defaults to comma.
|
459 |
+
* @return array
|
460 |
+
*/
|
461 |
+
protected function wt_explode_values($value, $separator = ',') {
|
462 |
+
$value = str_replace('\\,', '::separator::', $value);
|
463 |
+
$values = explode($separator, $value);
|
464 |
+
$values = array_map(array($this, 'wt_explode_values_formatter'), $values);
|
465 |
+
|
466 |
+
return $values;
|
467 |
+
}
|
468 |
+
|
469 |
+
/**
|
470 |
+
* Remove formatting and trim each value.
|
471 |
+
*
|
472 |
+
* @since 3.2.0
|
473 |
+
* @param string $value Value to format.
|
474 |
+
* @return string
|
475 |
+
*/
|
476 |
+
protected function wt_explode_values_formatter($value) {
|
477 |
+
return trim(str_replace('::separator::', ',', $value));
|
478 |
+
}
|
479 |
+
|
480 |
+
public function wt_parse_order_number_field($value) {
|
481 |
+
$order_number_formatted = $data['order_id'];
|
482 |
+
$order_number = (!empty($data['order_number']) ? $data['order_number'] : ( is_numeric($order_number_formatted) ? $order_number_formatted : 0 ) );
|
483 |
+
if ($order_number_formatted) {
|
484 |
+
// verify that this order number isn't already in use
|
485 |
+
$query_args = array(
|
486 |
+
'numberposts' => 1,
|
487 |
+
'meta_key' => apply_filters('woocommerce_order_number_formatted_meta_name', '_order_number_formatted'),
|
488 |
+
'meta_value' => $order_number_formatted,
|
489 |
+
'post_type' => $this->post_type,
|
490 |
+
'post_status' => array_keys(wc_get_order_statuses()),
|
491 |
+
'fields' => 'ids',
|
492 |
+
);
|
493 |
+
|
494 |
+
$order_id = 0;
|
495 |
+
$orders = get_posts($query_args);
|
496 |
+
if (!empty($orders)) {
|
497 |
+
list( $order_id ) = get_posts($query_args);
|
498 |
+
}
|
499 |
+
|
500 |
+
$order_id = apply_filters('woocommerce_find_order_by_order_number', $order_id, $order_number_formatted);
|
501 |
+
|
502 |
+
if ($order_id) {
|
503 |
+
// skip if order ID already exist.
|
504 |
+
throw new Exception(sprintf('Skipped. %s already exists.', ucfirst($this->parent_module->module_base)) );
|
505 |
+
}
|
506 |
+
}
|
507 |
+
|
508 |
+
}
|
509 |
+
|
510 |
+
public function wt_parse_date_field($value, $column) {
|
511 |
+
|
512 |
+
$date = $value;
|
513 |
+
|
514 |
+
if($value == ''){
|
515 |
+
$date = date('Y-m-d h:i:s');
|
516 |
+
}
|
517 |
+
|
518 |
+
if(false === ( $date = strtotime($date) )) {
|
519 |
+
// invalid date format
|
520 |
+
throw new Exception(sprintf('Skipped. Invalid date format %s in column %s.', $value,$column) );
|
521 |
+
}
|
522 |
+
return $date;
|
523 |
+
}
|
524 |
+
|
525 |
+
public function wt_parse_customer_id_field($value,$column,$data) {
|
526 |
+
if(isset($this->item_data['customer_id']) && !empty($this->item_data['customer_id'])){
|
527 |
+
return $this->item_data['customer_id'];
|
528 |
+
}
|
529 |
+
if (isset($value) && $value) {
|
530 |
+
// attempt to find the customer user
|
531 |
+
|
532 |
+
$found_customer = null;
|
533 |
+
switch ($column) {
|
534 |
+
case 'customer_id':
|
535 |
+
case 'customer_user':
|
536 |
+
$customer = get_user_by('id', $value);
|
537 |
+
if($customer){
|
538 |
+
$this->item_data['customer_id'] = $value;
|
539 |
+
}
|
540 |
+
break;
|
541 |
+
|
542 |
+
case 'customer_email':
|
543 |
+
// check by email
|
544 |
+
if(is_email($value)){
|
545 |
+
$found_customer = email_exists($value);
|
546 |
+
if($found_customer){
|
547 |
+
$this->item_data['customer_id'] = $found_customer;
|
548 |
+
break;
|
549 |
+
}else{
|
550 |
+
if ($this->create_user && is_email($value)) {
|
551 |
+
$customer_email = $value;
|
552 |
+
$username = (!empty($data['_customer_username']) ) ? $data['_customer_username'] : '';
|
553 |
+
// Not in test mode, create a user account for this email
|
554 |
+
if (empty($username)) {
|
555 |
+
$maybe_username = explode('@', $customer_email);
|
556 |
+
$maybe_username = sanitize_user($maybe_username[0]);
|
557 |
+
$counter = 1;
|
558 |
+
$username = $maybe_username;
|
559 |
+
while (username_exists($username)) {
|
560 |
+
$username = $maybe_username . $counter;
|
561 |
+
$counter++;
|
562 |
+
}
|
563 |
+
}
|
564 |
+
if (!empty($data['_customer_password'])) {
|
565 |
+
$password = $data['_customer_password'];
|
566 |
+
} else {
|
567 |
+
$password = wp_generate_password(12, true);
|
568 |
+
}
|
569 |
+
$found_customer = wp_create_user($username, $password, $customer_email);
|
570 |
+
if (!is_wp_error($found_customer)) {
|
571 |
+
$user_meta_fields = array(
|
572 |
+
'billing_first_name', // Billing Address Info
|
573 |
+
'billing_last_name',
|
574 |
+
'billing_company',
|
575 |
+
'billing_address_1',
|
576 |
+
'billing_address_2',
|
577 |
+
'billing_city',
|
578 |
+
'billing_state',
|
579 |
+
'billing_postcode',
|
580 |
+
'billing_country',
|
581 |
+
'billing_email',
|
582 |
+
'billing_phone',
|
583 |
+
'shipping_first_name', // Shipping Address Info
|
584 |
+
'shipping_last_name',
|
585 |
+
'shipping_company',
|
586 |
+
'shipping_address_1',
|
587 |
+
'shipping_address_2',
|
588 |
+
'shipping_city',
|
589 |
+
'shipping_state',
|
590 |
+
'shipping_postcode',
|
591 |
+
'shipping_country',
|
592 |
+
);
|
593 |
+
|
594 |
+
|
595 |
+
// update user meta data
|
596 |
+
foreach ($user_meta_fields as $key) {
|
597 |
+
switch ($key) {
|
598 |
+
case 'billing_email':
|
599 |
+
// user billing email if set in csv otherwise use the user's account email
|
600 |
+
$meta_value = (!empty($data[$key])) ? $data[$key] : $customer_email;
|
601 |
+
$key = substr($key, 1);
|
602 |
+
update_user_meta($found_customer, $key, $meta_value);
|
603 |
+
break;
|
604 |
+
|
605 |
+
case 'billing_first_name':
|
606 |
+
$meta_value = (!empty($data[$key])) ? $data[$key] : $username;
|
607 |
+
$key = substr($key, 1);
|
608 |
+
update_user_meta($found_customer, $key, $meta_value);
|
609 |
+
update_user_meta($found_customer, 'first_name', $meta_value);
|
610 |
+
break;
|
611 |
+
|
612 |
+
case 'billing_last_name':
|
613 |
+
$meta_value = (!empty($data[$key])) ? $data[$key] : '';
|
614 |
+
$key = substr($key, 1);
|
615 |
+
update_user_meta($found_customer, $key, $meta_value);
|
616 |
+
update_user_meta($found_customer, 'last_name', $meta_value);
|
617 |
+
break;
|
618 |
+
|
619 |
+
case 'shipping_first_name':
|
620 |
+
case 'shipping_last_name':
|
621 |
+
case 'shipping_address_1':
|
622 |
+
case 'shipping_address_2':
|
623 |
+
case 'shipping_city':
|
624 |
+
case 'shipping_postcode':
|
625 |
+
case 'shipping_state':
|
626 |
+
case 'shipping_country':
|
627 |
+
// Set the shipping address fields to match the billing fields if not specified in CSV
|
628 |
+
$meta_value = (!empty($data[$key])) ? $data[$key] : '';
|
629 |
+
|
630 |
+
if (empty($meta_value)) {
|
631 |
+
$n_key = str_replace('shipping', 'billing', $key);
|
632 |
+
$meta_value = (!empty($data[$n_key])) ? $data[$n_key] : '';
|
633 |
+
}
|
634 |
+
$key = substr($key, 1);
|
635 |
+
update_user_meta($found_customer, $key, $meta_value);
|
636 |
+
break;
|
637 |
+
|
638 |
+
default:
|
639 |
+
$meta_value = (!empty($data[$key])) ? $data[$key] : '';
|
640 |
+
$key = substr($key, 1);
|
641 |
+
update_user_meta($found_customer, $key, $meta_value);
|
642 |
+
}
|
643 |
+
}
|
644 |
+
$wp_user_object = new WP_User($found_customer);
|
645 |
+
$wp_user_object->set_role('customer');
|
646 |
+
// send user registration email if admin as chosen to do so
|
647 |
+
if ($this->notify_customer && function_exists('wp_new_user_notification')) {
|
648 |
+
$previous_option = get_option('woocommerce_registration_generate_password');
|
649 |
+
// force the option value so that the password will appear in the email
|
650 |
+
update_option('woocommerce_registration_generate_password', 'yes');
|
651 |
+
do_action('woocommerce_created_customer', $found_customer, array('user_pass' => $password), true);
|
652 |
+
update_option('woocommerce_registration_generate_password', $previous_option);
|
653 |
+
}
|
654 |
+
|
655 |
+
$this->item_data['customer_id'] = $found_customer;
|
656 |
+
break;
|
657 |
+
}
|
658 |
+
}
|
659 |
+
}
|
660 |
+
}
|
661 |
+
}
|
662 |
+
}
|
663 |
+
|
664 |
+
}
|
665 |
+
|
666 |
+
public function wt_parse_product_ids_field($value) {
|
667 |
+
return $value;
|
668 |
+
}
|
669 |
+
|
670 |
+
|
671 |
+
public function wt_parse_email_field($value) {
|
672 |
+
return is_email($value) ? $value : '';
|
673 |
+
}
|
674 |
+
|
675 |
+
|
676 |
+
|
677 |
+
public function wt_parse_order_shipping_field($value,$column,$item) {
|
678 |
+
|
679 |
+
$available_methods = WC()->shipping()->load_shipping_methods();
|
680 |
+
|
681 |
+
$order_shipping = $value;
|
682 |
+
|
683 |
+
$order_shipping_methods = array();
|
684 |
+
$_shipping_methods = array();
|
685 |
+
|
686 |
+
// pre WC 2.1 format of a single shipping method, left for backwards compatibility of import files
|
687 |
+
if (isset($item['shipping_method']) && $item['shipping_method']) {
|
688 |
+
// collect the shipping method id/cost
|
689 |
+
$_shipping_methods[] = array(
|
690 |
+
$item['shipping_method'],
|
691 |
+
isset($item['shipping_cost']) ? $item['shipping_cost'] : null
|
692 |
+
);
|
693 |
+
}
|
694 |
+
|
695 |
+
// collect any additional shipping methods
|
696 |
+
$i = null;
|
697 |
+
if (isset($item['shipping_method_1'])) {
|
698 |
+
$i = 1;
|
699 |
+
} elseif (isset($item['shipping_method_2'])) {
|
700 |
+
$i = 2;
|
701 |
+
}
|
702 |
+
|
703 |
+
if (!is_null($i)) {
|
704 |
+
while (!empty($item['shipping_method_' . $i])) {
|
705 |
+
|
706 |
+
$_shipping_methods[] = array(
|
707 |
+
$item['shipping_method_' . $i],
|
708 |
+
isset($item['shipping_cost_' . $i]) ? $item['shipping_cost_' . $i] : null
|
709 |
+
);
|
710 |
+
$i++;
|
711 |
+
}
|
712 |
+
}
|
713 |
+
|
714 |
+
// if the order shipping total wasn't set, calculate it
|
715 |
+
if (!isset($order_shipping)) {
|
716 |
+
|
717 |
+
$order_shipping = 0;
|
718 |
+
foreach ($_shipping_methods as $_shipping_method) {
|
719 |
+
$order_shipping += $_shipping_method[1];
|
720 |
+
}
|
721 |
+
$postmeta[] = array('key' => '_order_shipping' . $column, 'value' => number_format((float) $order_shipping, 2, '.', ''));
|
722 |
+
} elseif (isset($order_shipping) && 1 == count($_shipping_methods) && is_null($_shipping_methods[0][1])) {
|
723 |
+
// special case: if there was a total order shipping but no cost for the single shipping method, use the total shipping for the order shipping line item
|
724 |
+
$_shipping_methods[0][1] = $order_shipping;
|
725 |
+
}
|
726 |
+
|
727 |
+
foreach ($_shipping_methods as $_shipping_method) {
|
728 |
+
|
729 |
+
// look up shipping method by id or title
|
730 |
+
$shipping_method = isset($available_methods[$_shipping_method[0]]) ? $_shipping_method[0] : null;
|
731 |
+
|
732 |
+
if (!$shipping_method) {
|
733 |
+
// try by title
|
734 |
+
foreach ($available_methods as $method) {
|
735 |
+
if (0 === strcasecmp($method->title, $_shipping_method[0])) {
|
736 |
+
$shipping_method = $method->id;
|
737 |
+
break; // go with the first one we find
|
738 |
+
}
|
739 |
+
}
|
740 |
+
}
|
741 |
+
|
742 |
+
if ($shipping_method) {
|
743 |
+
// known shipping method found
|
744 |
+
$order_shipping_methods[] = array('cost' => $_shipping_method[1], 'title' => $available_methods[$shipping_method]->title);
|
745 |
+
} elseif ($_shipping_method[0]) {
|
746 |
+
// Standard format, shipping method but no title
|
747 |
+
$order_shipping_methods[] = array('cost' => $_shipping_method[1], 'title' => '');
|
748 |
+
}
|
749 |
+
}
|
750 |
+
|
751 |
+
return $order_shipping_methods;
|
752 |
+
|
753 |
+
}
|
754 |
+
|
755 |
+
public function wt_parse_shipping_method_field($value){
|
756 |
+
|
757 |
+
|
758 |
+
$order_shipping_methods = array();
|
759 |
+
$_shipping_methods = array();
|
760 |
+
|
761 |
+
$available_methods = WC()->shipping()->load_shipping_methods();
|
762 |
+
// look up shipping method by id or title
|
763 |
+
$shipping_method_obj = isset($available_methods[$value]) ? $available_methods[$value] : $value;
|
764 |
+
|
765 |
+
if (!$shipping_method_obj) {
|
766 |
+
// try by title
|
767 |
+
foreach ($available_methods as $method) {
|
768 |
+
if (0 === strcasecmp($method->title, $value)) {
|
769 |
+
$shipping_method = $method->id;
|
770 |
+
break; // go with the first one we find
|
771 |
+
}
|
772 |
+
}
|
773 |
+
$shipping_method_obj = isset($available_methods[$shipping_method]) ? $available_methods[$shipping_method] : $shipping_method;
|
774 |
+
}
|
775 |
+
return $shipping_method_obj;
|
776 |
+
}
|
777 |
+
|
778 |
+
public function wt_parse_payment_method_field($value) {
|
779 |
+
$available_gateways = WC()->payment_gateways->payment_gateways();
|
780 |
+
// look up shipping method by id or title
|
781 |
+
$payment_method_obj = isset($available_gateways[$value]) ? $available_gateways[$value] : $value;
|
782 |
+
if (!$payment_method_obj) {
|
783 |
+
// try by title
|
784 |
+
foreach ($available_gateways as $method) {
|
785 |
+
if (0 === strcasecmp($method->title, $value)) {
|
786 |
+
$payment_method = $method->id;
|
787 |
+
break; // go with the first one we find
|
788 |
+
}
|
789 |
+
}
|
790 |
+
if(isset($payment_method)){
|
791 |
+
$payment_method_obj = isset($available_gateways[$payment_method]) ? $available_gateways[$payment_method] : $payment_method;
|
792 |
+
}
|
793 |
+
}
|
794 |
+
return $payment_method_obj;
|
795 |
+
}
|
796 |
+
|
797 |
+
public function wt_parse_shipping_items_field($value) {
|
798 |
+
$shipping_items = array();
|
799 |
+
if('' !== $value){
|
800 |
+
$shipping_line_items = explode('|', $value);
|
801 |
+
$items = array_shift($shipping_line_items);
|
802 |
+
$items = substr($items, strpos($items, ":") + 1);
|
803 |
+
$method_id = array_shift($shipping_line_items);
|
804 |
+
$method_id = substr($method_id, strpos($method_id, ":") + 1);
|
805 |
+
$taxes = array_shift($shipping_line_items);
|
806 |
+
$taxes = substr($taxes, strpos($taxes, ":") + 1);
|
807 |
+
|
808 |
+
$shipping_items = array(
|
809 |
+
'Items' => $items,
|
810 |
+
'method_id' => $method_id,
|
811 |
+
'taxes' => $taxes
|
812 |
+
);
|
813 |
+
}
|
814 |
+
|
815 |
+
return $shipping_items;
|
816 |
+
|
817 |
+
}
|
818 |
+
|
819 |
+
public function wt_parse_fee_items_field($value) {
|
820 |
+
$fee_items = array();
|
821 |
+
if( '' !== $value){
|
822 |
+
$fee_line_items = explode('||', $value);
|
823 |
+
foreach ($fee_line_items as $fee_line_item) {
|
824 |
+
$fee_item_meta = explode('|', $fee_line_item);
|
825 |
+
$name = array_shift($fee_item_meta);
|
826 |
+
$name = substr($name, strpos($name, ":") + 1);
|
827 |
+
$total = array_shift($fee_item_meta);
|
828 |
+
$total = substr($total, strpos($total, ":") + 1);
|
829 |
+
$tax = array_shift($fee_item_meta);
|
830 |
+
$tax = substr($tax, strpos($tax, ":") + 1);
|
831 |
+
$tax_data = array_shift($fee_item_meta);
|
832 |
+
$tax_data = substr($tax_data, strpos($tax_data, ":") + 1);
|
833 |
+
|
834 |
+
$fee_items[] = array(
|
835 |
+
'name' => $name,
|
836 |
+
'total' => $total,
|
837 |
+
'tax' => $tax,
|
838 |
+
'tax_data' => $tax_data
|
839 |
+
);
|
840 |
+
}
|
841 |
+
}
|
842 |
+
return $fee_items;
|
843 |
+
}
|
844 |
+
|
845 |
+
public function wt_parse_tax_items_field($value) {
|
846 |
+
global $wpdb;
|
847 |
+
$tax_rates = array();
|
848 |
+
|
849 |
+
foreach ($wpdb->get_results("SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates") as $_row) {
|
850 |
+
$tax_rates[$_row->tax_rate_id] = $_row;
|
851 |
+
}
|
852 |
+
|
853 |
+
$tax_items = array();
|
854 |
+
|
855 |
+
// standard tax item format which supports multiple tax items in numbered columns containing a pipe-delimated, colon-labeled format
|
856 |
+
// if (isset($item['tax_items']) && !empty($item['tax_items'])) {
|
857 |
+
// one or more order tax items
|
858 |
+
// get the first tax item
|
859 |
+
$tax_item = explode(';', $value);
|
860 |
+
// $tax_amount_sum = $shipping_tax_amount_sum = 0;
|
861 |
+
foreach ($tax_item as $tax) {
|
862 |
+
|
863 |
+
$tax_item_data = array();
|
864 |
+
|
865 |
+
// turn "label: Tax | tax_amount: 10" into an associative array
|
866 |
+
foreach (explode('|', $tax) as $piece) {
|
867 |
+
list( $name, $value ) = array_pad(explode(':', $piece), 2, null);
|
868 |
+
if(isset($name)){
|
869 |
+
$tax_item_data[trim($name)] = trim($value);
|
870 |
+
}
|
871 |
+
}
|
872 |
+
|
873 |
+
// default rate id to 0 if not set
|
874 |
+
if (!isset($tax_item_data['rate_id'])) {
|
875 |
+
$tax_item_data['rate_id'] = 0;
|
876 |
+
}
|
877 |
+
|
878 |
+
// have a tax amount or shipping tax amount
|
879 |
+
if (isset($tax_item_data['total']) || isset($tax_item_data['shipping_tax_amount'])) {
|
880 |
+
// try and look up rate id by label if needed
|
881 |
+
if (isset($tax_item_data['label']) && $tax_item_data['label'] && !$tax_item_data['rate_id']) {
|
882 |
+
foreach ($tax_rates as $tax_rate) {
|
883 |
+
|
884 |
+
if (0 === strcasecmp($tax_rate->tax_rate_name, $tax_item_data['label'])) {
|
885 |
+
// found the tax by label
|
886 |
+
$tax_item_data['rate_id'] = $tax_rate->tax_rate_id;
|
887 |
+
break;
|
888 |
+
}
|
889 |
+
}
|
890 |
+
}
|
891 |
+
|
892 |
+
// check for a rate being specified which does not exist, and clear it out (technically an error?)
|
893 |
+
if ($tax_item_data['rate_id'] && !isset($tax_rates[$tax_item_data['rate_id']])) {
|
894 |
+
$tax_item_data['rate_id'] = 0;
|
895 |
+
}
|
896 |
+
|
897 |
+
// default label of 'Tax' if not provided
|
898 |
+
if (!isset($tax_item_data['label']) || !$tax_item_data['label']) {
|
899 |
+
$tax_item_data['label'] = 'Tax';
|
900 |
+
}
|
901 |
+
|
902 |
+
// default tax amounts to 0 if not set
|
903 |
+
if (!isset($tax_item_data['total'])) {
|
904 |
+
$tax_item_data['total'] = 0;
|
905 |
+
}
|
906 |
+
if (!isset($tax_item_data['shipping_tax_amount'])) {
|
907 |
+
$tax_item_data['shipping_tax_amount'] = 0;
|
908 |
+
}
|
909 |
+
|
910 |
+
// handle compound flag by using the defined tax rate value (if any)
|
911 |
+
if (!isset($tax_item_data['tax_rate_compound'])) {
|
912 |
+
$tax_item_data['tax_rate_compound'] = '';
|
913 |
+
if ($tax_item_data['rate_id']) {
|
914 |
+
$tax_item_data['tax_rate_compound'] = $tax_rates[$tax_item_data['rate_id']]->tax_rate_compound;
|
915 |
+
}
|
916 |
+
}
|
917 |
+
|
918 |
+
$tax_items[] = array(
|
919 |
+
'title' => $tax_item_data['code'],
|
920 |
+
'rate_id' => $tax_item_data['rate_id'],
|
921 |
+
'label' => $tax_item_data['label'],
|
922 |
+
'compound' => $tax_item_data['tax_rate_compound'],
|
923 |
+
'tax_amount' => $tax_item_data['total'],
|
924 |
+
'shipping_tax_amount' => $tax_item_data['shipping_tax_amount'],
|
925 |
+
);
|
926 |
+
}
|
927 |
+
}
|
928 |
+
// }
|
929 |
+
return $tax_items;
|
930 |
+
}
|
931 |
+
|
932 |
+
public function wt_parse_coupon_items_field($value) {
|
933 |
+
|
934 |
+
|
935 |
+
// standard format
|
936 |
+
$coupon_item = array();
|
937 |
+
|
938 |
+
if(isset($value) && !empty($value)){
|
939 |
+
$coupon_item = explode(';', $value);
|
940 |
+
}
|
941 |
+
|
942 |
+
return $coupon_item;
|
943 |
+
|
944 |
+
}
|
945 |
+
|
946 |
+
public function wt_parse_refund_items_field($value) {
|
947 |
+
|
948 |
+
//added since refund not importing
|
949 |
+
$refund_item = array();
|
950 |
+
if(isset($value) && !empty($value)){
|
951 |
+
$refund_item = explode(';', $value);
|
952 |
+
}
|
953 |
+
return $refund_item;
|
954 |
+
}
|
955 |
+
|
956 |
+
public function wt_parse_order_notes_field($value) {
|
957 |
+
|
958 |
+
$order_notes = array();
|
959 |
+
if (!empty($value)) {
|
960 |
+
$order_notes = explode("||", $value);
|
961 |
+
}
|
962 |
+
return $order_notes;
|
963 |
+
}
|
964 |
+
|
965 |
+
public function wt_parse_line_item_field($value,$column) {
|
966 |
+
if(empty($value)){
|
967 |
+
return array();
|
968 |
+
}
|
969 |
+
|
970 |
+
global $wpdb;
|
971 |
+
$order_items = array();
|
972 |
+
$variation = FALSE;
|
973 |
+
//$_item_meta = preg_split("~\\\\.(*SKIP)(*FAIL)|\|~s", $item['line_item_' . $i]);
|
974 |
+
$_item_meta = array();
|
975 |
+
if ($value && empty($_item_meta)) {
|
976 |
+
$_item_meta = explode(apply_filters('wt_change_item_separator','|'), $value);
|
977 |
+
}
|
978 |
+
|
979 |
+
// get any additional item meta
|
980 |
+
$item_meta = array();
|
981 |
+
foreach ($_item_meta as $pair) {
|
982 |
+
|
983 |
+
// replace any escaped pipes
|
984 |
+
$pair = str_replace('\|', '|', $pair);
|
985 |
+
|
986 |
+
// find the first ':' and split into name-value
|
987 |
+
$split = strpos($pair, ':');
|
988 |
+
$name = substr($pair, 0, $split);
|
989 |
+
$value = substr($pair, $split + 1);
|
990 |
+
switch ($name) {
|
991 |
+
case 'name':
|
992 |
+
$unknown_product_name = $value;
|
993 |
+
break;
|
994 |
+
case 'product_id':
|
995 |
+
$product_identifier_by_id = $value;
|
996 |
+
break;
|
997 |
+
case 'sku':
|
998 |
+
$product_identifier_by_sku = $value;
|
999 |
+
break;
|
1000 |
+
case 'quantity':
|
1001 |
+
$qty = $value;
|
1002 |
+
break;
|
1003 |
+
case 'total':
|
1004 |
+
$total = $value;
|
1005 |
+
break;
|
1006 |
+
case 'sub_total':
|
1007 |
+
$sub_total = $value;
|
1008 |
+
break;
|
1009 |
+
case 'tax':
|
1010 |
+
$tax = $value;
|
1011 |
+
break;
|
1012 |
+
case 'tax_data':
|
1013 |
+
$tax_data = $value;
|
1014 |
+
break;
|
1015 |
+
default :
|
1016 |
+
$item_meta[$name] = $value;
|
1017 |
+
}
|
1018 |
+
|
1019 |
+
}
|
1020 |
+
|
1021 |
+
if($this->ord_link_using_sku || (empty($product_identifier_by_id))){
|
1022 |
+
$product_sku = !empty($product_identifier_by_sku) ? $product_identifier_by_sku : '';
|
1023 |
+
if ($product_sku){
|
1024 |
+
$product_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value=%s LIMIT 1", $product_sku));
|
1025 |
+
if(!empty($product_id)){
|
1026 |
+
if(get_post_type($product_id) == 'product_variation'){
|
1027 |
+
$variation = TRUE;
|
1028 |
+
$variation_id = $product_id;
|
1029 |
+
$product_id = wp_get_post_parent_id($variation_id);
|
1030 |
+
$item_meta['_variation_id'] = $variation_id;
|
1031 |
+
}
|
1032 |
+
}
|
1033 |
+
} else {
|
1034 |
+
$product_id = '';
|
1035 |
+
}
|
1036 |
+
} else {
|
1037 |
+
if (!empty($product_identifier_by_id)) {
|
1038 |
+
// product by product_id
|
1039 |
+
$product_id = $product_identifier_by_id;
|
1040 |
+
|
1041 |
+
// not a product
|
1042 |
+
if (!in_array(get_post_type($product_id), array('product', 'product_variation'))) {
|
1043 |
+
$product_id = '';
|
1044 |
+
}
|
1045 |
+
} else {
|
1046 |
+
$product_id = '';
|
1047 |
+
}
|
1048 |
+
}
|
1049 |
+
|
1050 |
+
if (!$this->allow_unknown_products && !$product_id) {
|
1051 |
+
// unknown product
|
1052 |
+
// $this->hf_order_log_data_change('hf-order-csv-import', sprintf(__('> > Skipped. Unknown order item: %s.'), $product_identifier));
|
1053 |
+
return ;
|
1054 |
+
|
1055 |
+
}
|
1056 |
+
|
1057 |
+
|
1058 |
+
$order_items = array(
|
1059 |
+
'product_id' => !empty($product_id) ? $product_id : 0,
|
1060 |
+
'qty' => !empty($qty) ? $qty : 0,
|
1061 |
+
'total' => !empty($total) ? $total : 0,
|
1062 |
+
'sub_total' => !empty($sub_total) ? $sub_total : 0,
|
1063 |
+
'tax' => !empty($tax) ? $tax : 0,
|
1064 |
+
'meta' => $item_meta,
|
1065 |
+
'product_name' => !empty($unknown_product_name) ? $unknown_product_name : ''
|
1066 |
+
);
|
1067 |
+
if(!empty($tax_data)){
|
1068 |
+
$order_items['tax_data'] = $tax_data;
|
1069 |
+
}
|
1070 |
+
|
1071 |
+
return $order_items;
|
1072 |
+
}
|
1073 |
+
|
1074 |
+
|
1075 |
+
|
1076 |
+
/**
|
1077 |
+
* Parse relative field and return product ID.
|
1078 |
+
*
|
1079 |
+
* Handles `id:xx` and SKUs.
|
1080 |
+
*
|
1081 |
+
* If mapping to an id: and the product ID does not exist, this link is not
|
1082 |
+
* valid.
|
1083 |
+
*
|
1084 |
+
* If mapping to a SKU and the product ID does not exist, a temporary object
|
1085 |
+
* will be created so it can be updated later.
|
1086 |
+
*
|
1087 |
+
* @param string $value Field value.
|
1088 |
+
*
|
1089 |
+
* @return int|string
|
1090 |
+
*/
|
1091 |
+
public function wt_parse_relative_field($value) {
|
1092 |
+
global $wpdb;
|
1093 |
+
|
1094 |
+
if (empty($value)) {
|
1095 |
+
return '';
|
1096 |
+
}
|
1097 |
+
|
1098 |
+
// IDs are prefixed with id:.
|
1099 |
+
if (preg_match('/^id:(\d+)$/', $value, $matches)) {
|
1100 |
+
$id = intval($matches[1]);
|
1101 |
+
|
1102 |
+
// If original_id is found, use that instead of the given ID since a new placeholder must have been created already.
|
1103 |
+
$original_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_original_id' AND meta_value = %s;", $id)); // WPCS: db call ok, cache ok.
|
1104 |
+
|
1105 |
+
if ($original_id) {
|
1106 |
+
return absint($original_id);
|
1107 |
+
}
|
1108 |
+
|
1109 |
+
// See if the given ID maps to a valid product allready.
|
1110 |
+
$existing_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type IN ( 'product', 'product_variation' ) AND ID = %d;", $id)); // WPCS: db call ok, cache ok.
|
1111 |
+
|
1112 |
+
if ($existing_id) {
|
1113 |
+
return absint($existing_id);
|
1114 |
+
}
|
1115 |
+
|
1116 |
+
// If we're not updating existing posts, we may need a placeholder product to map to.
|
1117 |
+
if (!$this->params['update_existing']) {
|
1118 |
+
$product = wc_get_product_object('simple');
|
1119 |
+
$product->set_name('Import placeholder for ' . $id);
|
1120 |
+
$product->set_status('importing');
|
1121 |
+
$product->add_meta_data('_original_id', $id, true);
|
1122 |
+
$id = $product->save();
|
1123 |
+
}
|
1124 |
+
|
1125 |
+
return $id;
|
1126 |
+
}
|
1127 |
+
|
1128 |
+
$id = wc_get_product_id_by_sku($value);
|
1129 |
+
|
1130 |
+
if ($id) {
|
1131 |
+
return $id;
|
1132 |
+
}
|
1133 |
+
|
1134 |
+
try {
|
1135 |
+
$product = wc_get_product_object('simple');
|
1136 |
+
$product->set_name('Import placeholder for ' . $value);
|
1137 |
+
$product->set_status('importing');
|
1138 |
+
$product->set_sku($value);
|
1139 |
+
$id = $product->save();
|
1140 |
+
|
1141 |
+
if ($id && !is_wp_error($id)) {
|
1142 |
+
return $id;
|
1143 |
+
}
|
1144 |
+
} catch (Exception $e) {
|
1145 |
+
return '';
|
1146 |
+
}
|
1147 |
+
|
1148 |
+
return '';
|
1149 |
+
}
|
1150 |
+
|
1151 |
+
/**
|
1152 |
+
* Parse the ID field.
|
1153 |
+
*
|
1154 |
+
* If we're not doing an update, create a placeholder product so mapping works
|
1155 |
+
* for rows following this one.
|
1156 |
+
*
|
1157 |
+
* @param string $value Field value.
|
1158 |
+
*
|
1159 |
+
* @return int
|
1160 |
+
*/
|
1161 |
+
public function wt_parse_id_field($data, $parsed_data) {
|
1162 |
+
|
1163 |
+
if(!isset($data['order_id'])){
|
1164 |
+
return 0;
|
1165 |
+
}
|
1166 |
+
|
1167 |
+
$id = $this->wt_order_existance_check($data['order_id']);
|
1168 |
+
if($id){
|
1169 |
+
return $id;
|
1170 |
+
}
|
1171 |
+
|
1172 |
+
if(class_exists('HF_Subscription')){
|
1173 |
+
remove_all_actions('save_post');
|
1174 |
+
}
|
1175 |
+
|
1176 |
+
$date = !empty($parsed_data['date_created']) ? $parsed_data['date_created'] : date('Y-m-d H:i:s', time());
|
1177 |
+
$postdata = array( // if not specifiying id (id is empty) or if not found by given id
|
1178 |
+
'post_date' => $date,
|
1179 |
+
'post_date_gmt' => $date,
|
1180 |
+
'post_type' => $this->post_type,
|
1181 |
+
'post_status' => 'importing',
|
1182 |
+
'ping_status' => 'closed',
|
1183 |
+
'post_author' => 1,
|
1184 |
+
'post_title' => sprintf( 'Order – %s', strftime( '%b %d, %Y @ %I:%M %p', strtotime($date)) ),
|
1185 |
+
'post_password' => wc_generate_order_key(),
|
1186 |
+
'post_parent' => !empty($parsed_data['parent_id']) ? $parsed_data['parent_id'] : 0,
|
1187 |
+
'post_excerpt' => !empty($parsed_data['customer_note']) ? $parsed_data['customer_note'] : '',
|
1188 |
+
);
|
1189 |
+
if(isset($data['order_id']) && !empty($data['order_id'])){
|
1190 |
+
$postdata['import_id'] = $data['order_id'];
|
1191 |
+
}
|
1192 |
+
$post_id = wp_insert_post( $postdata, true );
|
1193 |
+
if($post_id && !is_wp_error($post_id)){
|
1194 |
+
Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', sprintf('Importing as new '. ($this->parent_module->module_base).' ID:%d',$post_id ));
|
1195 |
+
return $post_id;
|
1196 |
+
}else{
|
1197 |
+
throw new Exception($post_id->get_error_message());
|
1198 |
+
}
|
1199 |
+
|
1200 |
+
}
|
1201 |
+
|
1202 |
+
public function wt_parse_id_field_old($data, $parsed_data) {
|
1203 |
+
global $wpdb;
|
1204 |
+
|
1205 |
+
$id = isset($data['order_id']) && !empty($data['order_id']) ? absint($data['order_id']) : 0;
|
1206 |
+
$id_found_with_id = '';
|
1207 |
+
if($id){
|
1208 |
+
$id_found_with_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_status IN ( 'wc-pending', 'wc-processing', 'wc-completed', 'wc-on-hold', 'wc-failed' , 'wc-refunded', 'wc-cancelled') AND ID = %d;", $id)); // WPCS: db call ok, cache ok.
|
1209 |
+
if($id_found_with_id){
|
1210 |
+
if($this->post_type == get_post_type($id_found_with_id)){
|
1211 |
+
$this->is_order_exist = true;
|
1212 |
+
}
|
1213 |
+
}
|
1214 |
+
}
|
1215 |
+
|
1216 |
+
if( !$this->merge ){
|
1217 |
+
|
1218 |
+
if('skip' == $this->found_action){ // skip if found
|
1219 |
+
|
1220 |
+
if($id && $id_found_with_id && $this->is_order_exist){
|
1221 |
+
throw new Exception(sprintf('Coupon with same ID already exists. ID: %d',$id ));
|
1222 |
+
}elseif($id && $id_found_with_id && !$this->is_order_exist){
|
1223 |
+
throw new Exception(sprintf('Importing %s(ID) conflicts with an existing post. ID: %d',ucfirst($this->parent_module->module_base),$id ));
|
1224 |
+
}
|
1225 |
+
|
1226 |
+
if(class_exists('HF_Subscription')){
|
1227 |
+
remove_all_actions('save_post');
|
1228 |
+
}
|
1229 |
+
|
1230 |
+
$date = !empty($parsed_data['date_created']) ? $parsed_data['date_created'] : date('Y-m-d H:i:s', time());
|
1231 |
+
$postdata = array( // if not specifiying id (id is empty) or if not found by given id
|
1232 |
+
'post_date' => $date,
|
1233 |
+
'post_date_gmt' => $date,
|
1234 |
+
'post_type' => $this->post_type,
|
1235 |
+
'post_status' => 'importing',
|
1236 |
+
'ping_status' => 'closed',
|
1237 |
+
'post_author' => 1,
|
1238 |
+
'post_title' => sprintf( 'Order – %s', strftime( '%b %d, %Y @ %I:%M %p', strtotime($date)) ),
|
1239 |
+
'post_password' => wc_generate_order_key(),
|
1240 |
+
'post_parent' => !empty($parsed_data['parent_id']) ? $parsed_data['parent_id'] : 0,
|
1241 |
+
'post_excerpt' => !empty($parsed_data['customer_note']) ? $parsed_data['customer_note'] : '',
|
1242 |
+
);
|
1243 |
+
if(isset($id) && !empty($id)){
|
1244 |
+
$postdata['import_id'] = $id;
|
1245 |
+
}
|
1246 |
+
$post_id = wp_insert_post( $postdata, true );
|
1247 |
+
if($post_id && !is_wp_error($post_id)){
|
1248 |
+
$post = get_post($post_id);
|
1249 |
+
return $post_id;
|
1250 |
+
}else{
|
1251 |
+
throw new Exception($post_id->get_error_message());
|
1252 |
+
}
|
1253 |
+
|
1254 |
+
throw new Exception('fasil !merge, found_action skip');
|
1255 |
+
|
1256 |
+
}elseif('import' == $this->found_action){ // import if not found
|
1257 |
+
|
1258 |
+
if($id && $id_found_with_id && $this->is_order_exist){
|
1259 |
+
throw new Exception(sprintf('%s with same ID already exists. ID: %d',ucfirst($this->parent_module->module_base),$id ));
|
1260 |
+
}elseif($id && $id_found_with_id && !$this->is_order_exist && $this->use_same_id ){
|
1261 |
+
throw new Exception(sprintf('Importing %s(ID) conflicts with an existing post. ID: %d',ucfirst($this->parent_module->module_base),$id ));
|
1262 |
+
}
|
1263 |
+
|
1264 |
+
if(class_exists('HF_Subscription')){
|
1265 |
+
remove_all_actions('save_post');
|
1266 |
+
}
|
1267 |
+
$date = !empty($parsed_data['date_created']) ? $parsed_data['date_created'] : date('Y-m-d H:i:s', time());
|
1268 |
+
$postdata = array( // if not specifiying id (id is empty) or if not found by given id
|
1269 |
+
'post_date' => $date,
|
1270 |
+
'post_date_gmt' => $date,
|
1271 |
+
'post_type' => $this->post_type,
|
1272 |
+
'post_status' => 'importing',
|
1273 |
+
'ping_status' => 'closed',
|
1274 |
+
'post_author' => 1,
|
1275 |
+
'post_title' => sprintf( 'Order – %s', strftime( '%b %d, %Y @ %I:%M %p', strtotime($date)) ),
|
1276 |
+
'post_password' => wc_generate_order_key(),
|
1277 |
+
'post_parent' => !empty($parsed_data['parent_id']) ? $parsed_data['parent_id'] : 0,
|
1278 |
+
'post_excerpt' => !empty($parsed_data['customer_note']) ? $parsed_data['customer_note'] : '',
|
1279 |
+
);
|
1280 |
+
if(isset($id) && !empty($id)){
|
1281 |
+
$postdata['import_id'] = $id;
|
1282 |
+
}
|
1283 |
+
$post_id = wp_insert_post( $postdata, true );
|
1284 |
+
if($post_id && !is_wp_error($post_id)){
|
1285 |
+
return $post_id;
|
1286 |
+
}else{
|
1287 |
+
throw new Exception($post_id->get_error_message());
|
1288 |
+
}
|
1289 |
+
}
|
1290 |
+
|
1291 |
+
|
1292 |
+
}elseif($this->merge){
|
1293 |
+
|
1294 |
+
if(empty($id)){
|
1295 |
+
throw new Exception('Cannot update/insert without ID' );
|
1296 |
+
}
|
1297 |
+
|
1298 |
+
if('skip' == $this->found_action){ // skip if not found or update
|
1299 |
+
|
1300 |
+
if($id && $id_found_with_id && $this->is_order_exist){ //found order by id
|
1301 |
+
return $id; // update
|
1302 |
+
}elseif($id && $id_found_with_id && !$this->is_order_exist){ // found an item by id ,but not a order
|
1303 |
+
throw new Exception(sprintf('Importing %s(ID) conflicts with an existing post. ID: %d',ucfirst($this->parent_module->module_base),$id ));
|
1304 |
+
}elseif(($id && !$id_found_with_id) || !$id){
|
1305 |
+
throw new Exception(sprintf('Cannot find %s with given ID %d',ucfirst($this->parent_module->module_base),$id ));
|
1306 |
+
}
|
1307 |
+
|
1308 |
+
if($this->skip_new){
|
1309 |
+
throw new Exception('Skipping new item' );
|
1310 |
+
}
|
1311 |
+
if(class_exists('HF_Subscription')){
|
1312 |
+
remove_all_actions('save_post');
|
1313 |
+
}
|
1314 |
+
$date = !empty($parsed_data['date_created']) ? $parsed_data['date_created'] : date('Y-m-d H:i:s', time());
|
1315 |
+
$postdata = array( // if not specifiying id (id is empty) or if not found by given id
|
1316 |
+
'post_date' => $date,
|
1317 |
+
'post_date_gmt' => $date,
|
1318 |
+
'post_type' => $this->post_type,
|
1319 |
+
'post_status' => 'importing',
|
1320 |
+
'ping_status' => 'closed',
|
1321 |
+
'post_author' => 1,
|
1322 |
+
'post_title' => sprintf( 'Order – %s', strftime( '%b %d, %Y @ %I:%M %p', strtotime($date)) ),
|
1323 |
+
'post_password' => wc_generate_order_key(),
|
1324 |
+
'post_parent' => !empty($parsed_data['parent_id']) ? $parsed_data['parent_id'] : 0,
|
1325 |
+
'post_excerpt' => !empty($parsed_data['customer_note']) ? $parsed_data['customer_note'] : '',
|
1326 |
+
);
|
1327 |
+
if(isset($id) && !empty($id)){
|
1328 |
+
$postdata['import_id'] = $id;
|
1329 |
+
}
|
1330 |
+
$post_id = wp_insert_post( $postdata, true );
|
1331 |
+
if($post_id && !is_wp_error($post_id)){
|
1332 |
+
return $post_id;
|
1333 |
+
}else{
|
1334 |
+
throw new Exception($post_id->get_error_message());
|
1335 |
+
}
|
1336 |
+
|
1337 |
+
|
1338 |
+
}elseif('import' == $this->found_action){ // import if not found
|
1339 |
+
if($id && $id_found_with_id && $this->is_order_exist){ //found order by id
|
1340 |
+
return $id; // update
|
1341 |
+
}elseif($id && $id_found_with_id && !$this->is_order_exist && $this->use_same_id ){ // found an item by id ,but not a order, but should use the same id
|
1342 |
+
throw new Exception(sprintf('Importing %s(ID) conflicts with an existing post. ID: %d',ucfirst($this->parent_module->module_base),$id ));
|
1343 |
+
}
|
1344 |
+
|
1345 |
+
if($this->skip_new){
|
1346 |
+
throw new Exception('Skipping new item' );
|
1347 |
+
}
|
1348 |
+
if(class_exists('HF_Subscription')){
|
1349 |
+
remove_all_actions('save_post');
|
1350 |
+
}
|
1351 |
+
$date = !empty($parsed_data['date_created']) ? $parsed_data['date_created'] : date('Y-m-d H:i:s', time());
|
1352 |
+
$postdata = array( // if not specifiying id (id is empty) or if not found by given id
|
1353 |
+
'post_date' => $date,
|
1354 |
+
'post_date_gmt' => $date,
|
1355 |
+
'post_type' => $this->post_type,
|
1356 |
+
'post_status' => 'importing',
|
1357 |
+
'ping_status' => 'closed',
|
1358 |
+
'post_author' => 1,
|
1359 |
+
'post_title' => sprintf( 'Order – %s', strftime( '%b %d, %Y @ %I:%M %p', strtotime($date)) ),
|
1360 |
+
'post_password' => wc_generate_order_key(),
|
1361 |
+
'post_parent' => !empty($parsed_data['parent_id']) ? $parsed_data['parent_id'] : 0,
|
1362 |
+
'post_excerpt' => !empty($parsed_data['customer_note']) ? $parsed_data['customer_note'] : '',
|
1363 |
+
);
|
1364 |
+
if(isset($id) && !empty($id)){
|
1365 |
+
$postdata['import_id'] = $id;
|
1366 |
+
}
|
1367 |
+
$post_id = wp_insert_post( $postdata, true );
|
1368 |
+
if($post_id && !is_wp_error($post_id)){
|
1369 |
+
return $post_id;
|
1370 |
+
}else{
|
1371 |
+
throw new Exception($post_id->get_error_message());
|
1372 |
+
}
|
1373 |
+
}
|
1374 |
+
|
1375 |
+
}
|
1376 |
+
}
|
1377 |
+
|
1378 |
+
|
1379 |
+
/**
|
1380 |
+
* Parse relative comma-delineated field and return product ID.
|
1381 |
+
*
|
1382 |
+
* @param string $value Field value.
|
1383 |
+
*
|
1384 |
+
* @return array
|
1385 |
+
*/
|
1386 |
+
public function wt_parse_relative_comma_field($value) {
|
1387 |
+
if (empty($value)) {
|
1388 |
+
return array();
|
1389 |
+
}
|
1390 |
+
|
1391 |
+
return array_filter(array_map(array($this, 'wt_parse_relative_field'), $this->wt_explode_values($value)));
|
1392 |
+
}
|
1393 |
+
|
1394 |
+
/**
|
1395 |
+
* Parse a comma-delineated field from a CSV.
|
1396 |
+
*
|
1397 |
+
* @param string $value Field value.
|
1398 |
+
*
|
1399 |
+
* @return array
|
1400 |
+
*/
|
1401 |
+
public function parse_comma_field($value) {
|
1402 |
+
if (empty($value) && '0' !== $value) {
|
1403 |
+
return array();
|
1404 |
+
}
|
1405 |
+
|
1406 |
+
$value = $this->unescape_data($value);
|
1407 |
+
return array_map('wc_clean', $this->wt_explode_values($value));
|
1408 |
+
}
|
1409 |
+
|
1410 |
+
/**
|
1411 |
+
* Parse a field that is generally '1' or '0' but can be something else.
|
1412 |
+
*
|
1413 |
+
* @param string $value Field value.
|
1414 |
+
*
|
1415 |
+
* @return bool|string
|
1416 |
+
*/
|
1417 |
+
public function wt_parse_bool_field($value) {
|
1418 |
+
if ('0' === $value) {
|
1419 |
+
return false;
|
1420 |
+
}
|
1421 |
+
|
1422 |
+
if ('1' === $value) {
|
1423 |
+
return true;
|
1424 |
+
}
|
1425 |
+
|
1426 |
+
// Don't return explicit true or false for empty fields or values like 'notify'.
|
1427 |
+
return wc_clean($value);
|
1428 |
+
}
|
1429 |
+
|
1430 |
+
|
1431 |
+
/**
|
1432 |
+
* Parse an int value field
|
1433 |
+
*
|
1434 |
+
* @param int $value field value.
|
1435 |
+
*
|
1436 |
+
* @return int
|
1437 |
+
*/
|
1438 |
+
public function wt_parse_int_field($value) {
|
1439 |
+
// Remove the ' prepended to fields that start with - if needed.
|
1440 |
+
|
1441 |
+
return intval($value);
|
1442 |
+
}
|
1443 |
+
|
1444 |
+
/**
|
1445 |
+
* Parse the published field. 1 is published, 0 is private, -1 is draft.
|
1446 |
+
* Alternatively, 'true' can be used for published and 'false' for draft.
|
1447 |
+
*
|
1448 |
+
* @param string $value Field value.
|
1449 |
+
*
|
1450 |
+
* @return float|string
|
1451 |
+
*/
|
1452 |
+
public function wt_parse_status_field($value) {
|
1453 |
+
|
1454 |
+
if (!empty($value)) {
|
1455 |
+
|
1456 |
+
$shop_order_status = $this->wc_get_order_statuses_neat();
|
1457 |
+
|
1458 |
+
$found_status = false;
|
1459 |
+
|
1460 |
+
foreach ($shop_order_status as $status_slug => $status_name) {
|
1461 |
+
if (0 == strcasecmp($status_slug, $value))
|
1462 |
+
$found_status = true;
|
1463 |
+
}
|
1464 |
+
|
1465 |
+
if ($found_status) {
|
1466 |
+
return $value;
|
1467 |
+
}else{
|
1468 |
+
throw new Exception(sprintf('Skipped. Unknown order status (%s).', $value));
|
1469 |
+
}
|
1470 |
+
}
|
1471 |
+
|
1472 |
+
}
|
1473 |
+
|
1474 |
+
private function wc_get_order_statuses_neat() {
|
1475 |
+
$order_statuses = array();
|
1476 |
+
foreach (wc_get_order_statuses() as $slug => $name) {
|
1477 |
+
$order_statuses[preg_replace('/^wc-/', '', $slug)] = $name;
|
1478 |
+
}
|
1479 |
+
return $order_statuses;
|
1480 |
+
}
|
1481 |
+
|
1482 |
+
public function get_default_data() {
|
1483 |
+
|
1484 |
+
return array(
|
1485 |
+
// Abstract order props.
|
1486 |
+
'parent_id' => 0,
|
1487 |
+
'status' => '',
|
1488 |
+
'currency' => '',
|
1489 |
+
'version' => '',
|
1490 |
+
'prices_include_tax' => false,
|
1491 |
+
'date_created' => null,
|
1492 |
+
'date_modified' => null,
|
1493 |
+
'discount_total' => 0,
|
1494 |
+
'discount_tax' => 0,
|
1495 |
+
'shipping_total' => 0,
|
1496 |
+
'shipping_tax' => 0,
|
1497 |
+
'cart_tax' => 0,
|
1498 |
+
'total' => 0,
|
1499 |
+
'total_tax' => 0,
|
1500 |
+
// Order props.
|
1501 |
+
'customer_id' => null,
|
1502 |
+
'order_key' => '',
|
1503 |
+
'billing' => array(
|
1504 |
+
'first_name' => '',
|
1505 |
+
'last_name' => '',
|
1506 |
+
'company' => '',
|
1507 |
+
'address_1' => '',
|
1508 |
+
'address_2' => '',
|
1509 |
+
'city' => '',
|
1510 |
+
'state' => '',
|
1511 |
+
'postcode' => '',
|
1512 |
+
'country' => '',
|
1513 |
+
'email' => '',
|
1514 |
+
'phone' => '',
|
1515 |
+
),
|
1516 |
+
'shipping' => array(
|
1517 |
+
'first_name' => '',
|
1518 |
+
'last_name' => '',
|
1519 |
+
'company' => '',
|
1520 |
+
'address_1' => '',
|
1521 |
+
'address_2' => '',
|
1522 |
+
'city' => '',
|
1523 |
+
'state' => '',
|
1524 |
+
'postcode' => '',
|
1525 |
+
'country' => '',
|
1526 |
+
),
|
1527 |
+
'payment_method' => '',
|
1528 |
+
'payment_method_title' => '',
|
1529 |
+
'transaction_id' => '',
|
1530 |
+
'customer_ip_address' => '',
|
1531 |
+
'customer_user_agent' => '',
|
1532 |
+
'created_via' => '',
|
1533 |
+
'customer_note' => '',
|
1534 |
+
'date_completed' => null,
|
1535 |
+
'date_paid' => null,
|
1536 |
+
'cart_hash' => '',
|
1537 |
+
);
|
1538 |
+
}
|
1539 |
+
|
1540 |
+
public function process_item($data) {
|
1541 |
+
try {
|
1542 |
+
global $wpdb;
|
1543 |
+
do_action('wt_woocommerce_order_import_before_process_item', $data);
|
1544 |
+
$data = apply_filters('wt_woocommerce_order_import_process_item', $data);
|
1545 |
+
|
1546 |
+
$post_id = $data['order_id'];
|
1547 |
+
|
1548 |
+
$status = $data['status'];
|
1549 |
+
|
1550 |
+
|
1551 |
+
// wc_create_order(); woocommerce/includes/wc-core-function.php:83 -> $order = new WC_Order(); woocommerce/includes/class-wc-order.php:16 -> $order->save();
|
1552 |
+
// woocommerce/includes/class-wc-order.php:218 -> parent::save(); woocommerce/includes/abstracts/abstract_wc_order.php:168 -> $this->data_store->create( $this ); woocommerce/includes/data-store/abstract-wc-order-data-store-cpt.php:58
|
1553 |
+
|
1554 |
+
add_action( 'woocommerce_email', array($this, 'wt_iew_order_import_unhook_woocommerce_email') ); // disabled all order related email sending. Need to implimet a way to send status change email based on $this->status_mail flag
|
1555 |
+
|
1556 |
+
|
1557 |
+
$order = wc_create_order($data);
|
1558 |
+
if (is_wp_error($order)) {
|
1559 |
+
return $order;
|
1560 |
+
}
|
1561 |
+
|
1562 |
+
Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Found order object. ID:".$order->get_id());
|
1563 |
+
$default_args = array(
|
1564 |
+
'status',
|
1565 |
+
'customer_id',
|
1566 |
+
'customer_note',
|
1567 |
+
'parent',
|
1568 |
+
'created_via',
|
1569 |
+
'cart_hash',
|
1570 |
+
'order_id',
|
1571 |
+
'shipping_items',
|
1572 |
+
'fee_items',
|
1573 |
+
'tax_items',
|
1574 |
+
'coupon_items',
|
1575 |
+
'refund_items',
|
1576 |
+
'order_items',
|
1577 |
+
'meta_data',
|
1578 |
+
);
|
1579 |
+
|
1580 |
+
$order->set_props(array_diff_key($data, array_flip($default_args)));
|
1581 |
+
|
1582 |
+
if ($order->get_id()) {
|
1583 |
+
$order_id = $order->get_id();
|
1584 |
+
}
|
1585 |
+
|
1586 |
+
$order->set_address($data['billing'], 'billing');
|
1587 |
+
$order->set_address($data['shipping'], 'shipping');
|
1588 |
+
|
1589 |
+
$order->set_prices_include_tax( 'yes' === get_option( 'woocommerce_prices_include_tax' ) );
|
1590 |
+
|
1591 |
+
$order->add_meta_data( '_order_key', apply_filters('woocommerce_generate_order_key', uniqid('order_')) );
|
1592 |
+
|
1593 |
+
|
1594 |
+
// handle order items
|
1595 |
+
$order_items = array();
|
1596 |
+
$order_item_meta = null;
|
1597 |
+
if ($this->merge && $this->is_order_exist && !empty($data['order_items'])) {
|
1598 |
+
$wpdb->query($wpdb->prepare("DELETE items,itemmeta FROM {$wpdb->prefix}woocommerce_order_itemmeta itemmeta INNER JOIN {$wpdb->prefix}woocommerce_order_items items ON itemmeta.order_item_id = items.order_item_id WHERE items.order_id = %d and items.order_item_type = 'line_item'", $order_id));
|
1599 |
+
}
|
1600 |
+
if ($this->merge && $this->is_order_exist && !empty($data['order_shipping'])) {
|
1601 |
+
$wpdb->query($wpdb->prepare("DELETE items,itemmeta FROM {$wpdb->prefix}woocommerce_order_itemmeta itemmeta INNER JOIN {$wpdb->prefix}woocommerce_order_items items ON itemmeta.order_item_id = items.order_item_id WHERE items.order_id = %d and items.order_item_type = 'shipping'", $order_id));
|
1602 |
+
}
|
1603 |
+
|
1604 |
+
$_order_item_meta = array();
|
1605 |
+
if(!empty($data['order_items'])){
|
1606 |
+
foreach ($data['order_items'] as $item) {
|
1607 |
+
if(empty($item))
|
1608 |
+
continue; // special case need to rewrite this concept. empty array returning from wt_parse_line_item_field
|
1609 |
+
$product = null;
|
1610 |
+
$variation_item_meta = array();
|
1611 |
+
$product_title = __('Unknown Product');
|
1612 |
+
if ($item['product_id']) {
|
1613 |
+
$product = wc_get_product($item['product_id']);
|
1614 |
+
if($product){
|
1615 |
+
$product_title = ($product->get_title()!='') ? $product->get_title() :__('Unknown Product') ;
|
1616 |
+
}
|
1617 |
+
// handle variations
|
1618 |
+
if ($product && ( $product->is_type('variable') || $product->is_type('variation') || $product->is_type('subscription_variation') ) && method_exists($product, 'get_variation_id')) {
|
1619 |
+
foreach ($product->get_variation_attributes() as $key => $value) {
|
1620 |
+
$variation_item_meta[] = array('meta_name' => esc_attr(substr($key, 10)), 'meta_value' => $value); // remove the leading 'attribute_' from the name to get 'pa_color' for instance
|
1621 |
+
}
|
1622 |
+
}
|
1623 |
+
}
|
1624 |
+
// order item
|
1625 |
+
$order_items[] = array(
|
1626 |
+
'order_item_name' => !empty($item['product_name']) ? $item['product_name'] : ($product_title),
|
1627 |
+
'order_item_type' => 'line_item',
|
1628 |
+
);
|
1629 |
+
$var_id = 0;
|
1630 |
+
if ($product) {
|
1631 |
+
if (WC()->version < '2.7.0') {
|
1632 |
+
$var_id = ($product->product_type === 'variation') ? $product->variation_id : 0;
|
1633 |
+
} else {
|
1634 |
+
$var_id = $product->is_type('variation') ? $product->get_id() : 0;
|
1635 |
+
}
|
1636 |
+
}
|
1637 |
+
// standard order item meta
|
1638 |
+
$_order_item_meta = array(
|
1639 |
+
'_qty' => (int) $item['qty'],
|
1640 |
+
'_tax_class' => '', // Tax class (adjusted by filters)
|
1641 |
+
'_product_id' => $item['product_id'],
|
1642 |
+
'_variation_id' => $var_id,
|
1643 |
+
'_line_subtotal' => number_format((float) $item['sub_total'], 2, '.', ''), // Line subtotal (before discounts)
|
1644 |
+
'_line_subtotal_tax' => number_format((float) $item['tax'], 2, '.', ''), // Line tax (before discounts)
|
1645 |
+
'_line_total' => number_format((float) $item['total'], 2, '.', ''), // Line total (after discounts)
|
1646 |
+
'_line_tax' => number_format((float) $item['tax'], 2, '.', ''), // Line Tax (after discounts)
|
1647 |
+
);
|
1648 |
+
if(!empty($item['tax_data'])){
|
1649 |
+
$_order_item_meta['_line_tax_data'] = $item['tax_data'];
|
1650 |
+
}
|
1651 |
+
// add any product variation meta
|
1652 |
+
foreach ($variation_item_meta as $meta) {
|
1653 |
+
$_order_item_meta[$meta['meta_name']] = $meta['meta_value'];
|
1654 |
+
}
|
1655 |
+
// include any arbitrary order item meta
|
1656 |
+
$_order_item_meta = array_merge($_order_item_meta, $item['meta']);
|
1657 |
+
$order_item_meta[] = $_order_item_meta;
|
1658 |
+
}
|
1659 |
+
|
1660 |
+
foreach ($order_items as $key => $order_item) {
|
1661 |
+
$order_item_id = wc_add_order_item($order_id, $order_item);
|
1662 |
+
if ($order_item_id) {
|
1663 |
+
foreach ($order_item_meta[$key] as $meta_key => $meta_value) {
|
1664 |
+
wc_add_order_item_meta($order_item_id, $meta_key, maybe_unserialize($meta_value));
|
1665 |
+
}
|
1666 |
+
}
|
1667 |
+
}
|
1668 |
+
}
|
1669 |
+
|
1670 |
+
$shipping_tax = isset($data['shipping_tax_total'])?$data['shipping_tax_total']:0;
|
1671 |
+
// create the shipping order items
|
1672 |
+
if (!empty($data['order_shipping'])) {
|
1673 |
+
foreach ($data['order_shipping'] as $order_shipping) {
|
1674 |
+
if(empty($order_shipping))
|
1675 |
+
continue; // special case need to rewrite this concept. empty array returning from wt_parse_order_shipping_field
|
1676 |
+
|
1677 |
+
$shipping_order_item = array(
|
1678 |
+
'order_item_name' => ($order_shipping['title']) ? $order_shipping['title'] : $data['shipping_method'],
|
1679 |
+
'order_item_type' => 'shipping',
|
1680 |
+
);
|
1681 |
+
$shipping_order_item_id = wc_add_order_item($order_id, $shipping_order_item);
|
1682 |
+
if ($shipping_order_item_id) {
|
1683 |
+
wc_add_order_item_meta($shipping_order_item_id, 'cost', $order_shipping['cost']);
|
1684 |
+
wc_add_order_item_meta($shipping_order_item_id, 'total_tax', $shipping_tax);
|
1685 |
+
}
|
1686 |
+
}
|
1687 |
+
}
|
1688 |
+
|
1689 |
+
if (!empty($data['shipping_items'])) {
|
1690 |
+
foreach ($data['shipping_items'] as $key => $value) {
|
1691 |
+
if ($shipping_order_item_id) {
|
1692 |
+
wc_add_order_item_meta($shipping_order_item_id, $key, $value);
|
1693 |
+
} else {
|
1694 |
+
$shipping_order_item_id = wc_add_order_item($order_id, $shipping_order_item);
|
1695 |
+
wc_add_order_item_meta($shipping_order_item_id, $key, $value);
|
1696 |
+
}
|
1697 |
+
}
|
1698 |
+
}
|
1699 |
+
|
1700 |
+
// create the fee order items
|
1701 |
+
if (!empty($data['fee_items'])) {
|
1702 |
+
if ($this->merge && $this->is_order_exist) {
|
1703 |
+
$fee_str = 'fee';
|
1704 |
+
$wpdb->query($wpdb->prepare("DELETE items,itemmeta FROM {$wpdb->prefix}woocommerce_order_itemmeta itemmeta INNER JOIN {$wpdb->prefix}woocommerce_order_items items WHERE itemmeta.order_item_id = items.order_item_id and items.order_id = %d and items.order_item_type = %s", $order_id, $fee_str));
|
1705 |
+
}
|
1706 |
+
foreach ($data['fee_items'] as $key => $fee_item) {
|
1707 |
+
$fee_order_item = array(
|
1708 |
+
'order_item_name' => $fee_item['name'],
|
1709 |
+
'order_item_type' => "fee"
|
1710 |
+
);
|
1711 |
+
$fee_order_item_id = wc_add_order_item($order_id, $fee_order_item);
|
1712 |
+
if ($fee_order_item_id) {
|
1713 |
+
wc_add_order_item_meta($fee_order_item_id, '_line_tax', $fee_item['tax']);
|
1714 |
+
wc_add_order_item_meta($fee_order_item_id, '_line_total', $fee_item['total']);
|
1715 |
+
wc_add_order_item_meta($fee_order_item_id, '_fee_amount', $fee_item['total']);
|
1716 |
+
wc_add_order_item_meta($fee_order_item_id, '_line_tax_data', $fee_item['tax_data']);
|
1717 |
+
}
|
1718 |
+
}
|
1719 |
+
}
|
1720 |
+
// create the tax order items
|
1721 |
+
if (!empty($data['tax_items'])) {
|
1722 |
+
if ($this->merge && $this->is_order_exist) {
|
1723 |
+
$tax_str = 'tax';
|
1724 |
+
$wpdb->query($wpdb->prepare("DELETE items,itemmeta FROM {$wpdb->prefix}woocommerce_order_itemmeta itemmeta INNER JOIN {$wpdb->prefix}woocommerce_order_items items WHERE itemmeta.order_item_id = items.order_item_id and items.order_id = %d and items.order_item_type = %s", $order_id, $tax_str));
|
1725 |
+
}
|
1726 |
+
foreach ($data['tax_items'] as $tax_item) {
|
1727 |
+
$tax_order_item = array(
|
1728 |
+
'order_item_name' => $tax_item['title'],
|
1729 |
+
'order_item_type' => "tax",
|
1730 |
+
);
|
1731 |
+
$tax_order_item_id = wc_add_order_item($order_id, $tax_order_item);
|
1732 |
+
if ($tax_order_item_id) {
|
1733 |
+
wc_add_order_item_meta($tax_order_item_id, 'rate_id', $tax_item['rate_id']);
|
1734 |
+
wc_add_order_item_meta($tax_order_item_id, 'label', $tax_item['label']);
|
1735 |
+
wc_add_order_item_meta($tax_order_item_id, 'compound', $tax_item['compound']);
|
1736 |
+
wc_add_order_item_meta($tax_order_item_id, 'tax_amount', $tax_item['tax_amount']);
|
1737 |
+
wc_add_order_item_meta($tax_order_item_id, 'shipping_tax_amount', $tax_item['shipping_tax_amount']);
|
1738 |
+
}
|
1739 |
+
}
|
1740 |
+
}
|
1741 |
+
|
1742 |
+
//importing coupon items
|
1743 |
+
if (!empty($data['coupon_items'])) {
|
1744 |
+
|
1745 |
+
if (is_woocommerce_prior_to_basic('2.7')) {
|
1746 |
+
|
1747 |
+
if ($this->merge && $this->is_order_exist) {
|
1748 |
+
$applied_coupons = $order->get_used_coupons();
|
1749 |
+
if (!empty($applied_coupons)) {
|
1750 |
+
$order->remove_order_items('coupon');
|
1751 |
+
}
|
1752 |
+
}
|
1753 |
+
|
1754 |
+
$coupon_item = array();
|
1755 |
+
foreach ($data['coupon_items'] as $coupon) {
|
1756 |
+
|
1757 |
+
$_citem_meta = explode('|', $coupon);
|
1758 |
+
$coupon_code = array_shift($_citem_meta);
|
1759 |
+
$coupon_code = substr($coupon_code, strpos($coupon_code, ":") + 1);
|
1760 |
+
|
1761 |
+
$discount_amount = array_shift($_citem_meta);
|
1762 |
+
$discount_amount = substr($discount_amount, strpos($discount_amount, ":") + 1);
|
1763 |
+
|
1764 |
+
$mypost = get_page_by_title($coupon_code, '', 'shop_coupon');
|
1765 |
+
$id = (isset($mypost->ID) ? $mypost->ID : '');
|
1766 |
+
|
1767 |
+
if ($id && $this->merge && $this->is_order_exist) {
|
1768 |
+
$order->add_coupon($coupon_code, $discount_amount);
|
1769 |
+
} else {
|
1770 |
+
$coupon_item['order_item_name'] = $coupon_code;
|
1771 |
+
$coupon_item['order_item_type'] = 'coupon';
|
1772 |
+
$order_item_id = wc_add_order_item($order_id, $coupon_item);
|
1773 |
+
wc_add_order_item_meta($order_item_id, 'discount_amount', $discount_amount);
|
1774 |
+
}
|
1775 |
+
}
|
1776 |
+
} else {
|
1777 |
+
|
1778 |
+
if ($this->merge && $this->is_order_exist) {
|
1779 |
+
$applied_coupons = $order->get_used_coupons();
|
1780 |
+
if (!empty($applied_coupons)) {
|
1781 |
+
foreach ($applied_coupons as $coupon) {
|
1782 |
+
$order->remove_coupon($coupon);
|
1783 |
+
}
|
1784 |
+
}
|
1785 |
+
}
|
1786 |
+
$coupon_item = array();
|
1787 |
+
foreach ($data['coupon_items'] as $coupon) {
|
1788 |
+
$_citem_meta = explode('|', $coupon);
|
1789 |
+
$coupon_code = array_shift($_citem_meta);
|
1790 |
+
$coupon_code = substr($coupon_code, strpos($coupon_code, ":") + 1);
|
1791 |
+
$discount_amount = array_shift($_citem_meta);
|
1792 |
+
$discount_amount = substr($discount_amount, strpos($discount_amount, ":") + 1);
|
1793 |
+
|
1794 |
+
$id = wc_get_coupon_id_by_code($coupon_code);
|
1795 |
+
|
1796 |
+
if ($id && $this->merge && $this->is_order_exist) {
|
1797 |
+
$order->apply_coupon($coupon_code);
|
1798 |
+
} else {
|
1799 |
+
$coupon_item['order_item_name'] = $coupon_code;
|
1800 |
+
$coupon_item['order_item_type'] = 'coupon';
|
1801 |
+
$order_item_id = wc_add_order_item($order_id, $coupon_item);
|
1802 |
+
wc_add_order_item_meta($order_item_id, 'discount_amount', $discount_amount);
|
1803 |
+
}
|
1804 |
+
}
|
1805 |
+
}
|
1806 |
+
}
|
1807 |
+
|
1808 |
+
// importing refund items
|
1809 |
+
if (!empty($data['refund_items'])) {
|
1810 |
+
if ($this->merge && $this->is_order_exist) {
|
1811 |
+
$refund = 'shop_order_refund';
|
1812 |
+
$wpdb->query($wpdb->prepare("DELETE po,pm FROM $wpdb->posts AS po INNER JOIN $wpdb->postmeta AS pm ON po.ID = pm.post_id WHERE post_parent = %d and post_type = %s", $order_id, $refund));
|
1813 |
+
}
|
1814 |
+
foreach ($data['refund_items'] as $refund) {
|
1815 |
+
$single_refund = explode('|', $refund);
|
1816 |
+
$amount = array_shift($single_refund);
|
1817 |
+
$amount = substr($amount, strpos($amount, ":") + 1);
|
1818 |
+
$reason = array_shift($single_refund);
|
1819 |
+
$reason = substr($reason, strpos($reason, ":") + 1);
|
1820 |
+
$date = array_shift($single_refund);
|
1821 |
+
$date = substr($date, strpos($date, ":") + 1);
|
1822 |
+
|
1823 |
+
$args = array(
|
1824 |
+
'amount' => $amount,
|
1825 |
+
'reason' => $reason,
|
1826 |
+
'date_created' => $date,
|
1827 |
+
'order_id' => $order_id,
|
1828 |
+
);
|
1829 |
+
$input_currency = isset($data['currency']) ? $data['currency'] : $order->get_currency();
|
1830 |
+
remove_all_actions('woocommerce_order_status_refunded_notification');
|
1831 |
+
remove_all_actions('woocommerce_order_partially_refunded_notification');
|
1832 |
+
remove_action('woocommerce_order_status_refunded', array('WC_Emails', 'send_transactional_email'));
|
1833 |
+
remove_action('woocommerce_order_partially_refunded', array('WC_Emails', 'send_transactional_email'));
|
1834 |
+
remove_action('woocommerce_order_fully_refunded', array('WC_Emails', 'send_transactional_email'));
|
1835 |
+
$this->wt_create_refund($args, $input_currency);
|
1836 |
+
}
|
1837 |
+
}
|
1838 |
+
|
1839 |
+
// add order notes
|
1840 |
+
if(!empty($data['order_notes'])){
|
1841 |
+
add_filter('woocommerce_email_enabled_customer_note', '__return_false');
|
1842 |
+
$wpdb->query($wpdb->prepare("DELETE comments,meta FROM {$wpdb->prefix}comments comments LEFT JOIN {$wpdb->prefix}commentmeta meta ON comments.comment_ID = meta.comment_id WHERE comments.comment_post_ID = %d",$order_id));
|
1843 |
+
foreach ($data['order_notes'] as $order_note) {
|
1844 |
+
$note = explode('|', $order_note);
|
1845 |
+
$con = array_shift($note);
|
1846 |
+
$con = substr($con, strpos($con, ":") + 1);
|
1847 |
+
$date = array_shift($note);
|
1848 |
+
$date = substr($date, strpos($date, ":") + 1);
|
1849 |
+
$cus = array_shift($note);
|
1850 |
+
$cus = substr($cus, strpos($cus, ":") + 1);
|
1851 |
+
$system = array_shift($note);
|
1852 |
+
$added_by = substr($system, strpos($system, ":") + 1);
|
1853 |
+
if($added_by == 'system'){
|
1854 |
+
$added_by_user = FALSE;
|
1855 |
+
}else{
|
1856 |
+
$added_by_user = TRUE;
|
1857 |
+
}
|
1858 |
+
if($cus == '1'){
|
1859 |
+
$comment_id = $order->add_order_note($con,1,1);
|
1860 |
+
} else {
|
1861 |
+
$comment_id = $order->add_order_note($con,0,$added_by_user);
|
1862 |
+
}
|
1863 |
+
wp_update_comment(array('comment_ID' => $comment_id,'comment_date' => $date));
|
1864 |
+
}
|
1865 |
+
}
|
1866 |
+
|
1867 |
+
|
1868 |
+
$this->set_meta_data($order, $data);
|
1869 |
+
|
1870 |
+
if($this->status_mail == true){
|
1871 |
+
$order->update_status('wc-' . preg_replace('/^wc-/', '', $status));
|
1872 |
+
} else {
|
1873 |
+
$update_post = array(
|
1874 |
+
'ID' => $order_id,
|
1875 |
+
'post_status' => 'wc-' . preg_replace('/^wc-/', '', $status),
|
1876 |
+
);
|
1877 |
+
wp_update_post($update_post);
|
1878 |
+
}
|
1879 |
+
|
1880 |
+
|
1881 |
+
if($this->delete_existing){
|
1882 |
+
update_post_meta($order_id, '_wt_delete_existing', 1);
|
1883 |
+
}
|
1884 |
+
|
1885 |
+
|
1886 |
+
$order = apply_filters('wt_woocommerce_import_pre_insert_order_object', $order, $data);
|
1887 |
+
|
1888 |
+
|
1889 |
+
|
1890 |
+
$order->save();
|
1891 |
+
|
1892 |
+
do_action('wt_woocommerce_order_import_inserted_object', $order, $data);
|
1893 |
+
|
1894 |
+
$result = array(
|
1895 |
+
'id' => $order->get_id(),
|
1896 |
+
'updated' => $this->merge,
|
1897 |
+
);
|
1898 |
+
return $result;
|
1899 |
+
} catch (Exception $e) {
|
1900 |
+
return new WP_Error('woocommerce_product_importer_error', $e->getMessage(), array('status' => $e->getCode()));
|
1901 |
+
}
|
1902 |
+
}
|
1903 |
+
|
1904 |
+
|
1905 |
+
|
1906 |
+
|
1907 |
+
|
1908 |
+
function wt_create_refund( $args = array(), $input_currency ) {
|
1909 |
+
|
1910 |
+
$default_args = array(
|
1911 |
+
'amount' => 0,
|
1912 |
+
'reason' => null,
|
1913 |
+
'order_id' => 0,
|
1914 |
+
'refund_id' => 0,
|
1915 |
+
'line_items' => array(),
|
1916 |
+
'refund_payment' => false,
|
1917 |
+
'restock_items' => false,
|
1918 |
+
);
|
1919 |
+
|
1920 |
+
try {
|
1921 |
+
$args = wp_parse_args( $args, $default_args );
|
1922 |
+
$order = wc_get_order( $args['order_id'] );
|
1923 |
+
|
1924 |
+
if ( ! $order ) {
|
1925 |
+
throw new Exception( __( 'Invalid order ID.', 'woocommerce' ) );
|
1926 |
+
}
|
1927 |
+
|
1928 |
+
$remaining_refund_amount = $order->get_remaining_refund_amount();
|
1929 |
+
$remaining_refund_items = $order->get_remaining_refund_items();
|
1930 |
+
$refund_item_count = 0;
|
1931 |
+
$refund = new WC_Order_Refund( $args['refund_id'] );
|
1932 |
+
|
1933 |
+
$refund->set_currency( $input_currency );
|
1934 |
+
$refund->set_amount( $args['amount'] );
|
1935 |
+
$refund->set_parent_id( absint( $args['order_id'] ) );
|
1936 |
+
$refund->set_refunded_by( get_current_user_id() ? get_current_user_id() : 1 );
|
1937 |
+
$refund->set_prices_include_tax( $order->get_prices_include_tax() );
|
1938 |
+
|
1939 |
+
if ( ! is_null( $args['reason'] ) ) {
|
1940 |
+
$refund->set_reason( $args['reason'] );
|
1941 |
+
}
|
1942 |
+
|
1943 |
+
|
1944 |
+
// Negative line items.
|
1945 |
+
if ( count( $args['line_items'] ) > 0 ) {
|
1946 |
+
$items = $order->get_items( array( 'line_item', 'fee', 'shipping' ) );
|
1947 |
+
|
1948 |
+
foreach ( $items as $item_id => $item ) {
|
1949 |
+
if ( ! isset( $args['line_items'][ $item_id ] ) ) {
|
1950 |
+
continue;
|
1951 |
+
}
|
1952 |
+
|
1953 |
+
$qty = isset( $args['line_items'][ $item_id ]['qty'] ) ? $args['line_items'][ $item_id ]['qty'] : 0;
|
1954 |
+
$refund_total = $args['line_items'][ $item_id ]['refund_total'];
|
1955 |
+
$refund_tax = isset( $args['line_items'][ $item_id ]['refund_tax'] ) ? array_filter( (array) $args['line_items'][ $item_id ]['refund_tax'] ) : array();
|
1956 |
+
|
1957 |
+
if ( empty( $qty ) && empty( $refund_total ) && empty( $args['line_items'][ $item_id ]['refund_tax'] ) ) {
|
1958 |
+
continue;
|
1959 |
+
}
|
1960 |
+
|
1961 |
+
$class = get_class( $item );
|
1962 |
+
$refunded_item = new $class( $item );
|
1963 |
+
$refunded_item->set_id( 0 );
|
1964 |
+
$refunded_item->add_meta_data( '_refunded_item_id', $item_id, true );
|
1965 |
+
$refunded_item->set_total( wc_format_refund_total( $refund_total ) );
|
1966 |
+
$refunded_item->set_taxes(
|
1967 |
+
array(
|
1968 |
+
'total' => array_map( 'wc_format_refund_total', $refund_tax ),
|
1969 |
+
'subtotal' => array_map( 'wc_format_refund_total', $refund_tax ),
|
1970 |
+
)
|
1971 |
+
);
|
1972 |
+
|
1973 |
+
if ( is_callable( array( $refunded_item, 'set_subtotal' ) ) ) {
|
1974 |
+
$refunded_item->set_subtotal( wc_format_refund_total( $refund_total ) );
|
1975 |
+
}
|
1976 |
+
|
1977 |
+
if ( is_callable( array( $refunded_item, 'set_quantity' ) ) ) {
|
1978 |
+
$refunded_item->set_quantity( $qty * -1 );
|
1979 |
+
}
|
1980 |
+
|
1981 |
+
$refund->add_item( $refunded_item );
|
1982 |
+
$refund_item_count += $qty;
|
1983 |
+
}
|
1984 |
+
}
|
1985 |
+
|
1986 |
+
$refund->update_taxes();
|
1987 |
+
$refund->calculate_totals( false );
|
1988 |
+
$refund->set_total( $args['amount'] * -1 );
|
1989 |
+
|
1990 |
+
// this should remain after update_taxes(), as this will save the order, and write the current date to the db
|
1991 |
+
// so we must wait until the order is persisted to set the date.
|
1992 |
+
if ( isset( $args['date_created'] ) ) {
|
1993 |
+
$refund->set_date_created( $args['date_created'] );
|
1994 |
+
}
|
1995 |
+
|
1996 |
+
/**
|
1997 |
+
* Action hook to adjust refund before save.
|
1998 |
+
*
|
1999 |
+
* @since 3.0.0
|
2000 |
+
*/
|
2001 |
+
do_action( 'woocommerce_create_refund', $refund, $args );
|
2002 |
+
|
2003 |
+
if ( $refund->save() ) {
|
2004 |
+
if ( $args['refund_payment'] ) {
|
2005 |
+
$result = wc_refund_payment( $order, $refund->get_amount(), $refund->get_reason() );
|
2006 |
+
|
2007 |
+
if ( is_wp_error( $result ) ) {
|
2008 |
+
$refund->delete();
|
2009 |
+
return $result;
|
2010 |
+
}
|
2011 |
+
|
2012 |
+
$refund->set_refunded_payment( true );
|
2013 |
+
$refund->save();
|
2014 |
+
}
|
2015 |
+
|
2016 |
+
if ( $args['restock_items'] ) {
|
2017 |
+
wc_restock_refunded_items( $order, $args['line_items'] );
|
2018 |
+
}
|
2019 |
+
|
2020 |
+
// Trigger notification emails.
|
2021 |
+
if ( ( $remaining_refund_amount - $args['amount'] ) > 0 || ( $order->has_free_item() && ( $remaining_refund_items - $refund_item_count ) > 0 ) ) {
|
2022 |
+
//do_action( 'woocommerce_order_partially_refunded', $order->get_id(), $refund->get_id() );
|
2023 |
+
} else {
|
2024 |
+
//do_action( 'woocommerce_order_fully_refunded', $order->get_id(), $refund->get_id() );
|
2025 |
+
|
2026 |
+
$parent_status = apply_filters( 'woocommerce_order_fully_refunded_status', 'refunded', $order->get_id(), $refund->get_id() );
|
2027 |
+
|
2028 |
+
if ( $parent_status ) {
|
2029 |
+
$order->update_status( $parent_status );
|
2030 |
+
}
|
2031 |
+
}
|
2032 |
+
}
|
2033 |
+
|
2034 |
+
do_action( 'woocommerce_refund_created', $refund->get_id(), $args );
|
2035 |
+
do_action( 'woocommerce_order_refunded', $order->get_id(), $refund->get_id() );
|
2036 |
+
|
2037 |
+
} catch ( Exception $e ) {
|
2038 |
+
if ( isset( $refund ) && is_a( $refund, 'WC_Order_Refund' ) ) {
|
2039 |
+
wp_delete_post( $refund->get_id(), true );
|
2040 |
+
}
|
2041 |
+
return new WP_Error( 'error', $e->getMessage() );
|
2042 |
+
}
|
2043 |
+
|
2044 |
+
return $refund;
|
2045 |
+
}
|
2046 |
+
|
2047 |
+
function set_meta_data(&$object, $data) {
|
2048 |
+
if (isset($data['meta_data'])) {
|
2049 |
+
$order_id = $object->get_id();
|
2050 |
+
$add_download_permissions = false;
|
2051 |
+
foreach ($data['meta_data'] as $meta) {
|
2052 |
+
if (( 'Download Permissions Granted' == $meta['key'] || '_download_permissions_granted' == $meta['key'] ) && $meta['value']) {
|
2053 |
+
$add_download_permissions = true;
|
2054 |
+
}
|
2055 |
+
|
2056 |
+
if('_wt_import_key' == $meta['key']){
|
2057 |
+
$object->update_meta_data('_wt_import_key', apply_filters('wt_importing_order_reference_key', $meta['value'], $data)); // for future reference, this holds the order number which in the csv.
|
2058 |
+
continue;
|
2059 |
+
}
|
2060 |
+
|
2061 |
+
if ( is_serialized( $meta['value'] ) ) { // Don't attempt to unserialize data that wasn't serialized going in.
|
2062 |
+
$meta['value'] = maybe_unserialize(maybe_unserialize($meta['value']));
|
2063 |
+
}
|
2064 |
+
|
2065 |
+
$object->update_meta_data($meta['key'], $meta['value']);
|
2066 |
+
}
|
2067 |
+
|
2068 |
+
// Grant downloadalbe product permissions
|
2069 |
+
if ($add_download_permissions) {
|
2070 |
+
wc_downloadable_product_permissions($order_id);
|
2071 |
+
$next_update = get_post_meta( $order_id, '_wt_import_key');
|
2072 |
+
$force_update = isset($next_update) ? FALSE : TRUE;
|
2073 |
+
$force = apply_filters('wt_force_update_downloadalbe_product_permissions', $force_update);
|
2074 |
+
wc_downloadable_product_permissions($order_id, $force);
|
2075 |
+
|
2076 |
+
}
|
2077 |
+
|
2078 |
+
}
|
2079 |
+
|
2080 |
+
}
|
2081 |
+
|
2082 |
+
function wt_iew_order_import_unhook_woocommerce_email( $email_class ) {
|
2083 |
+
|
2084 |
+
// New order emails
|
2085 |
+
remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
|
2086 |
+
remove_action( 'woocommerce_order_status_pending_to_completed_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
|
2087 |
+
remove_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
|
2088 |
+
remove_action( 'woocommerce_order_status_failed_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
|
2089 |
+
remove_action( 'woocommerce_order_status_failed_to_completed_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
|
2090 |
+
remove_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
|
2091 |
+
|
2092 |
+
// Processing order emails
|
2093 |
+
remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
|
2094 |
+
remove_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
|
2095 |
+
|
2096 |
+
// Completed order emails
|
2097 |
+
remove_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) );
|
2098 |
+
|
2099 |
+
}
|
2100 |
+
|
2101 |
+
function wt_iew_order_import_hook_woocommerce_email( $email_class ) {
|
2102 |
+
|
2103 |
+
// New order emails
|
2104 |
+
add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
|
2105 |
+
add_action( 'woocommerce_order_status_pending_to_completed_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
|
2106 |
+
add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
|
2107 |
+
add_action( 'woocommerce_order_status_failed_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
|
2108 |
+
add_action( 'woocommerce_order_status_failed_to_completed_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
|
2109 |
+
add_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
|
2110 |
+
|
2111 |
+
// Processing order emails
|
2112 |
+
add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
|
2113 |
+
add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
|
2114 |
+
|
2115 |
+
// Completed order emails
|
2116 |
+
add_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) );
|
2117 |
+
|
2118 |
+
}
|
2119 |
+
}
|
2120 |
+
}
|
2121 |
+
|
admin/modules/order/order.php
ADDED
@@ -0,0 +1,556 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Order section of the plugin
|
5 |
+
*
|
6 |
+
* @link
|
7 |
+
*
|
8 |
+
* @package Wt_Import_Export_For_Woo_Basic
|
9 |
+
*/
|
10 |
+
if (!defined('ABSPATH')) {
|
11 |
+
exit;
|
12 |
+
}
|
13 |
+
|
14 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Basic_Order')){
|
15 |
+
class Wt_Import_Export_For_Woo_Basic_Order {
|
16 |
+
|
17 |
+
public $module_id = '';
|
18 |
+
public static $module_id_static = '';
|
19 |
+
public $module_base = 'order';
|
20 |
+
public $module_name = 'Order Import Export for WooCommerce';
|
21 |
+
public $min_base_version= '1.0.0'; /* Minimum `Import export plugin` required to run this add on plugin */
|
22 |
+
|
23 |
+
private $importer = null;
|
24 |
+
private $exporter = null;
|
25 |
+
private $all_meta_keys = array();
|
26 |
+
private $exclude_hidden_meta_columns = array();
|
27 |
+
private $found_meta = array();
|
28 |
+
private $found_hidden_meta = array();
|
29 |
+
private $selected_column_names = null;
|
30 |
+
|
31 |
+
public function __construct()
|
32 |
+
{
|
33 |
+
/**
|
34 |
+
* Checking the minimum required version of `Import export plugin` plugin available
|
35 |
+
*/
|
36 |
+
if(!Wt_Import_Export_For_Woo_Basic_Common_Helper::check_base_version($this->module_base, $this->module_name, $this->min_base_version))
|
37 |
+
{
|
38 |
+
return;
|
39 |
+
}
|
40 |
+
if(!function_exists('is_plugin_active'))
|
41 |
+
{
|
42 |
+
include_once(ABSPATH.'wp-admin/includes/plugin.php');
|
43 |
+
}
|
44 |
+
if(!is_plugin_active('woocommerce/woocommerce.php'))
|
45 |
+
{
|
46 |
+
return;
|
47 |
+
}
|
48 |
+
|
49 |
+
$this->module_id = Wt_Import_Export_For_Woo_Basic::get_module_id($this->module_base);
|
50 |
+
self::$module_id_static = $this->module_id;
|
51 |
+
|
52 |
+
add_filter('wt_iew_exporter_post_types_basic', array($this, 'wt_iew_exporter_post_types_basic'), 10, 1);
|
53 |
+
add_filter('wt_iew_importer_post_types_basic', array($this, 'wt_iew_exporter_post_types_basic'), 10, 1);
|
54 |
+
|
55 |
+
|
56 |
+
add_filter('wt_iew_exporter_alter_mapping_fields_basic', array($this, 'exporter_alter_mapping_fields'), 10, 3);
|
57 |
+
add_filter('wt_iew_importer_alter_mapping_fields_basic', array($this, 'get_importer_post_columns'), 10, 3);
|
58 |
+
|
59 |
+
add_filter('wt_iew_exporter_alter_filter_fields_basic', array($this, 'exporter_alter_filter_fields'), 10, 3);
|
60 |
+
|
61 |
+
add_filter('wt_iew_importer_alter_advanced_fields_basic', array($this, 'importer_alter_advanced_fields'), 10, 3);
|
62 |
+
|
63 |
+
add_filter('wt_iew_exporter_alter_meta_mapping_fields_basic', array($this, 'exporter_alter_meta_mapping_fields'), 10, 3);
|
64 |
+
add_filter('wt_iew_importer_alter_meta_mapping_fields_basic', array($this, 'importer_alter_meta_mapping_fields'), 10, 3);
|
65 |
+
|
66 |
+
add_filter('wt_iew_exporter_alter_mapping_enabled_fields_basic', array($this, 'exporter_alter_mapping_enabled_fields'), 10, 3);
|
67 |
+
add_filter('wt_iew_importer_alter_mapping_enabled_fields_basic', array($this, 'exporter_alter_mapping_enabled_fields'), 10, 3);
|
68 |
+
|
69 |
+
add_filter('wt_iew_exporter_do_export_basic', array($this, 'exporter_do_export'), 10, 7);
|
70 |
+
add_filter('wt_iew_importer_do_import_basic', array($this, 'importer_do_import'), 10, 8);
|
71 |
+
|
72 |
+
add_filter('wt_iew_importer_steps_basic', array($this, 'importer_steps'), 10, 2);
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Altering advanced step description
|
77 |
+
*/
|
78 |
+
public function importer_steps($steps, $base)
|
79 |
+
{
|
80 |
+
if($this->module_base==$base)
|
81 |
+
{
|
82 |
+
$steps['advanced']['description']=__('Use advanced options from below to decide updates to existing orders, batch import count. You can also save the template file for future imports.');
|
83 |
+
}
|
84 |
+
return $steps;
|
85 |
+
}
|
86 |
+
|
87 |
+
public function importer_do_import($import_data, $base, $step, $form_data, $selected_template_data, $method_import, $batch_offset, $is_last_batch) {
|
88 |
+
if ($this->module_base != $base) {
|
89 |
+
return $import_data;
|
90 |
+
}
|
91 |
+
|
92 |
+
if(0 == $batch_offset){
|
93 |
+
$memory = size_format(wt_let_to_num_basic(ini_get('memory_limit')));
|
94 |
+
$wp_memory = size_format(wt_let_to_num_basic(WP_MEMORY_LIMIT));
|
95 |
+
Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->module_base, 'import', '---[ New import started at '.date('Y-m-d H:i:s').' ] PHP Memory: ' . $memory . ', WP Memory: ' . $wp_memory);
|
96 |
+
}
|
97 |
+
|
98 |
+
include plugin_dir_path(__FILE__) . 'import/import.php';
|
99 |
+
$import = new Wt_Import_Export_For_Woo_Basic_Order_Import($this);
|
100 |
+
|
101 |
+
$response = $import->prepare_data_to_import($import_data,$form_data,$batch_offset,$is_last_batch);
|
102 |
+
|
103 |
+
if($is_last_batch){
|
104 |
+
Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->module_base, 'import', '---[ Import ended at '.date('Y-m-d H:i:s').']---');
|
105 |
+
}
|
106 |
+
|
107 |
+
return $response;
|
108 |
+
}
|
109 |
+
|
110 |
+
public function exporter_do_export($export_data, $base, $step, $form_data, $selected_template_data, $method_export, $batch_offset) {
|
111 |
+
if ($this->module_base != $base) {
|
112 |
+
return $export_data;
|
113 |
+
}
|
114 |
+
|
115 |
+
switch ($method_export) {
|
116 |
+
case 'quick':
|
117 |
+
$this->set_export_columns_for_quick_export($form_data);
|
118 |
+
break;
|
119 |
+
|
120 |
+
case 'template':
|
121 |
+
case 'new':
|
122 |
+
$this->set_selected_column_names($form_data);
|
123 |
+
break;
|
124 |
+
|
125 |
+
default:
|
126 |
+
break;
|
127 |
+
}
|
128 |
+
|
129 |
+
include plugin_dir_path(__FILE__) . 'export/export.php';
|
130 |
+
$export = new Wt_Import_Export_For_Woo_Basic_Order_Export($this);
|
131 |
+
|
132 |
+
$data_row = $export->prepare_data_to_export($form_data, $batch_offset);
|
133 |
+
|
134 |
+
$header_row = $export->prepare_header();
|
135 |
+
|
136 |
+
$export_data = array(
|
137 |
+
'head_data' => $header_row,
|
138 |
+
'body_data' => $data_row['data'],
|
139 |
+
'total' => $data_row['total'],
|
140 |
+
);
|
141 |
+
|
142 |
+
return $export_data;
|
143 |
+
}
|
144 |
+
|
145 |
+
/**
|
146 |
+
* Adding current post type to export list
|
147 |
+
*
|
148 |
+
*/
|
149 |
+
public function wt_iew_exporter_post_types_basic($arr) {
|
150 |
+
$arr['order'] = __('Order');
|
151 |
+
return $arr;
|
152 |
+
}
|
153 |
+
|
154 |
+
/*
|
155 |
+
* Setting default export columns for quick export
|
156 |
+
*/
|
157 |
+
|
158 |
+
public function set_export_columns_for_quick_export($form_data) {
|
159 |
+
|
160 |
+
$post_columns = self::get_order_post_columns();
|
161 |
+
|
162 |
+
$this->selected_column_names = array_combine(array_keys($post_columns), array_keys($post_columns));
|
163 |
+
|
164 |
+
if (isset($form_data['method_export_form_data']['mapping_enabled_fields']) && !empty($form_data['method_export_form_data']['mapping_enabled_fields'])) {
|
165 |
+
foreach ($form_data['method_export_form_data']['mapping_enabled_fields'] as $value) {
|
166 |
+
$additional_quick_export_fields[$value] = array('fields' => array());
|
167 |
+
}
|
168 |
+
|
169 |
+
$export_additional_columns = $this->exporter_alter_meta_mapping_fields($additional_quick_export_fields, $this->module_base, array());
|
170 |
+
foreach ($export_additional_columns as $value) {
|
171 |
+
$this->selected_column_names = array_merge($this->selected_column_names, $value['fields']);
|
172 |
+
}
|
173 |
+
}
|
174 |
+
}
|
175 |
+
|
176 |
+
public static function get_order_statuses() {
|
177 |
+
$statuses = wc_get_order_statuses();
|
178 |
+
return apply_filters('wt_iew_allowed_order_statuses', $statuses);
|
179 |
+
}
|
180 |
+
|
181 |
+
public static function get_order_sort_columns() {
|
182 |
+
$sort_columns = array('post_parent', 'ID', 'post_author', 'post_date', 'post_title', 'post_name', 'post_modified', 'menu_order', 'post_modified_gmt', 'rand', 'comment_count');
|
183 |
+
return apply_filters('wt_iew_allowed_order_sort_columns', array_combine($sort_columns, $sort_columns));
|
184 |
+
}
|
185 |
+
|
186 |
+
public static function get_order_post_columns() {
|
187 |
+
return include plugin_dir_path(__FILE__) . 'data/data-order-post-columns.php';
|
188 |
+
}
|
189 |
+
|
190 |
+
public function get_importer_post_columns($fields, $base, $step_page_form_data) {
|
191 |
+
if ($base != $this->module_base) {
|
192 |
+
return $fields;
|
193 |
+
}
|
194 |
+
$colunm = include plugin_dir_path(__FILE__) . 'data/data/data-wf-reserved-fields-pair.php';
|
195 |
+
// $colunm = array_map(function($vl){ return array('title'=>$vl, 'description'=>$vl); }, $arr);
|
196 |
+
return $colunm;
|
197 |
+
}
|
198 |
+
|
199 |
+
public function exporter_alter_mapping_enabled_fields($mapping_enabled_fields, $base, $form_data_mapping_enabled_fields) {
|
200 |
+
if ($base == $this->module_base) {
|
201 |
+
$mapping_enabled_fields = array();
|
202 |
+
}
|
203 |
+
return $mapping_enabled_fields;
|
204 |
+
}
|
205 |
+
|
206 |
+
public function exporter_alter_meta_mapping_fields($fields, $base, $step_page_form_data) {
|
207 |
+
if ($base != $this->module_base) {
|
208 |
+
return $fields;
|
209 |
+
}
|
210 |
+
/*
|
211 |
+
foreach ($fields as $key => $value) {
|
212 |
+
switch ($key) {
|
213 |
+
|
214 |
+
|
215 |
+
default:
|
216 |
+
break;
|
217 |
+
}
|
218 |
+
}
|
219 |
+
*
|
220 |
+
*/
|
221 |
+
|
222 |
+
return $fields;
|
223 |
+
}
|
224 |
+
|
225 |
+
|
226 |
+
public function importer_alter_meta_mapping_fields($fields, $base, $step_page_form_data) {
|
227 |
+
if ($base != $this->module_base) {
|
228 |
+
return $fields;
|
229 |
+
}
|
230 |
+
$fields=$this->exporter_alter_meta_mapping_fields($fields, $base, $step_page_form_data);
|
231 |
+
$out=array();
|
232 |
+
foreach ($fields as $key => $value)
|
233 |
+
{
|
234 |
+
$value['fields']=array_map(function($vl){ return array('title'=>$vl, 'description'=>$vl); }, $value['fields']);
|
235 |
+
$out[$key]=$value;
|
236 |
+
}
|
237 |
+
return $out;
|
238 |
+
}
|
239 |
+
|
240 |
+
public function wt_get_found_meta() {
|
241 |
+
|
242 |
+
if (!empty($this->found_meta)) {
|
243 |
+
return $this->found_meta;
|
244 |
+
}
|
245 |
+
|
246 |
+
// Loop products and load meta data
|
247 |
+
$found_meta = array();
|
248 |
+
// Some of the values may not be usable (e.g. arrays of arrays) but the worse
|
249 |
+
// that can happen is we get an empty column.
|
250 |
+
|
251 |
+
$all_meta_keys = $this->wt_get_all_meta_keys();
|
252 |
+
|
253 |
+
$csv_columns = self::get_order_post_columns();
|
254 |
+
|
255 |
+
$exclude_hidden_meta_columns = $this->wt_get_exclude_hidden_meta_columns();
|
256 |
+
|
257 |
+
foreach ($all_meta_keys as $meta) {
|
258 |
+
|
259 |
+
if (!$meta || (substr((string) $meta, 0, 1) == '_') || in_array($meta, $exclude_hidden_meta_columns) || in_array($meta, array_keys($csv_columns)) || in_array('meta:' . $meta, array_keys($csv_columns)))
|
260 |
+
continue;
|
261 |
+
|
262 |
+
$found_meta[] = $meta;
|
263 |
+
}
|
264 |
+
|
265 |
+
$found_meta = array_diff($found_meta, array_keys($csv_columns));
|
266 |
+
$this->found_meta = $found_meta;
|
267 |
+
return $this->found_meta;
|
268 |
+
}
|
269 |
+
|
270 |
+
public function wt_get_found_hidden_meta() {
|
271 |
+
|
272 |
+
if (!empty($this->found_hidden_meta)) {
|
273 |
+
return $this->found_hidden_meta;
|
274 |
+
}
|
275 |
+
|
276 |
+
// Loop products and load meta data
|
277 |
+
$found_hidden_meta = array();
|
278 |
+
// Some of the values may not be usable (e.g. arrays of arrays) but the worse
|
279 |
+
// that can happen is we get an empty column.
|
280 |
+
|
281 |
+
$all_meta_keys = $this->wt_get_all_meta_keys();
|
282 |
+
$csv_columns = self::get_order_post_columns();
|
283 |
+
$exclude_hidden_meta_columns = $this->wt_get_exclude_hidden_meta_columns();
|
284 |
+
foreach ($all_meta_keys as $meta) {
|
285 |
+
|
286 |
+
if (!$meta || (substr((string) $meta, 0, 1) != '_') || ((substr((string) $meta, 0, 1) == '_') && in_array(substr((string) $meta,1), array_keys($csv_columns)) ) || in_array($meta, $exclude_hidden_meta_columns) || in_array($meta, array_keys($csv_columns)) || in_array('meta:' . $meta, array_keys($csv_columns)))
|
287 |
+
continue;
|
288 |
+
|
289 |
+
$found_hidden_meta[] = $meta;
|
290 |
+
}
|
291 |
+
|
292 |
+
$found_hidden_meta = array_diff($found_hidden_meta, array_keys($csv_columns));
|
293 |
+
|
294 |
+
$this->found_hidden_meta = $found_hidden_meta;
|
295 |
+
return $this->found_hidden_meta;
|
296 |
+
}
|
297 |
+
|
298 |
+
public function wt_get_exclude_hidden_meta_columns() {
|
299 |
+
|
300 |
+
if (!empty($this->exclude_hidden_meta_columns)) {
|
301 |
+
return $this->exclude_hidden_meta_columns;
|
302 |
+
}
|
303 |
+
|
304 |
+
$exclude_hidden_meta_columns = include( plugin_dir_path(__FILE__) . 'data/data-wf-exclude-hidden-meta-columns.php' );
|
305 |
+
|
306 |
+
$this->exclude_hidden_meta_columns = $exclude_hidden_meta_columns;
|
307 |
+
return $this->exclude_hidden_meta_columns;
|
308 |
+
}
|
309 |
+
|
310 |
+
public function wt_get_all_meta_keys() {
|
311 |
+
|
312 |
+
if (!empty($this->all_meta_keys)) {
|
313 |
+
return $this->all_meta_keys;
|
314 |
+
}
|
315 |
+
|
316 |
+
$all_meta_keys = self::get_all_metakeys('shop_order');
|
317 |
+
|
318 |
+
$this->all_meta_keys = $all_meta_keys;
|
319 |
+
return $this->all_meta_keys;
|
320 |
+
}
|
321 |
+
|
322 |
+
/**
|
323 |
+
* Get a list of all the meta keys for a post type. This includes all public, private,
|
324 |
+
* used, no-longer used etc. They will be sorted once fetched.
|
325 |
+
*/
|
326 |
+
public static function get_all_metakeys($post_type = 'shop_order') {
|
327 |
+
global $wpdb;
|
328 |
+
$meta = $wpdb->get_col($wpdb->prepare(
|
329 |
+
"SELECT DISTINCT pm.meta_key
|
330 |
+
FROM {$wpdb->postmeta} AS pm
|
331 |
+
LEFT JOIN {$wpdb->posts} AS p ON p.ID = pm.post_id
|
332 |
+
WHERE p.post_type = %s
|
333 |
+
AND p.post_status IN ( 'wc-pending', 'wc-processing', 'wc-on-hold', 'wc-completed', 'wc-cancelled', 'wc-refunded', 'wc-failed' ) ORDER BY pm.meta_key", $post_type
|
334 |
+
));
|
335 |
+
//sort($meta);
|
336 |
+
return $meta;
|
337 |
+
}
|
338 |
+
|
339 |
+
public function set_selected_column_names($full_form_data) {
|
340 |
+
if (is_null($this->selected_column_names)) {
|
341 |
+
if (isset($full_form_data['mapping_form_data']['mapping_selected_fields']) && !empty($full_form_data['mapping_form_data']['mapping_selected_fields'])) {
|
342 |
+
$this->selected_column_names = $full_form_data['mapping_form_data']['mapping_selected_fields'];
|
343 |
+
}
|
344 |
+
if (isset($full_form_data['meta_step_form_data']['mapping_selected_fields']) && !empty($full_form_data['meta_step_form_data']['mapping_selected_fields'])) {
|
345 |
+
$export_additional_columns = $full_form_data['meta_step_form_data']['mapping_selected_fields'];
|
346 |
+
foreach ($export_additional_columns as $value) {
|
347 |
+
$this->selected_column_names = array_merge($this->selected_column_names, $value);
|
348 |
+
}
|
349 |
+
}
|
350 |
+
}
|
351 |
+
|
352 |
+
return $full_form_data;
|
353 |
+
}
|
354 |
+
|
355 |
+
public function get_selected_column_names() {
|
356 |
+
|
357 |
+
return $this->selected_column_names;
|
358 |
+
}
|
359 |
+
|
360 |
+
public function exporter_alter_mapping_fields($fields, $base, $mapping_form_data) {
|
361 |
+
if ($base == $this->module_base) {
|
362 |
+
$fields = self::get_order_post_columns();
|
363 |
+
}
|
364 |
+
return $fields;
|
365 |
+
}
|
366 |
+
|
367 |
+
public function exporter_alter_advanced_fields($fields, $base, $advanced_form_data) {
|
368 |
+
if ($this->module_base != $base) {
|
369 |
+
return $fields;
|
370 |
+
}
|
371 |
+
|
372 |
+
unset($fields['export_shortcode_tohtml']);
|
373 |
+
|
374 |
+
$out = array();
|
375 |
+
$out['exclude_already_exported'] = array(
|
376 |
+
'label' => __("Exclude already exported"),
|
377 |
+
'type' => 'radio',
|
378 |
+
'radio_fields' => array(
|
379 |
+
'Yes' => __('Yes'),
|
380 |
+
'No' => __('No')
|
381 |
+
),
|
382 |
+
'value' => 'No',
|
383 |
+
'field_name' => 'exclude_already_exported',
|
384 |
+
'help_text' => __("Option 'Yes' excludes the previously exported orders."),
|
385 |
+
);
|
386 |
+
|
387 |
+
$out['export_to_separate_columns'] = array(
|
388 |
+
'label' => __("Export line items into separate columns"),
|
389 |
+
'type' => 'radio',
|
390 |
+
'radio_fields' => array(
|
391 |
+
'Yes' => __('Yes'),
|
392 |
+
'No' => __('No')
|
393 |
+
),
|
394 |
+
'value' => 'No',
|
395 |
+
'field_name' => 'export_to_separate_columns',
|
396 |
+
'help_text' => __("Option 'Yes' exports the line items within the order into separate columns in the exported file."),
|
397 |
+
);
|
398 |
+
foreach ($fields as $fieldk => $fieldv) {
|
399 |
+
$out[$fieldk] = $fieldv;
|
400 |
+
}
|
401 |
+
return $out;
|
402 |
+
}
|
403 |
+
|
404 |
+
public function importer_alter_advanced_fields($fields, $base, $advanced_form_data) {
|
405 |
+
if ($this->module_base != $base) {
|
406 |
+
return $fields;
|
407 |
+
}
|
408 |
+
$out = array();
|
409 |
+
|
410 |
+
|
411 |
+
|
412 |
+
$out['found_action_merge'] = array(
|
413 |
+
'label' => __("If order exists in the store"),
|
414 |
+
'type' => 'radio',
|
415 |
+
'radio_fields' => array(
|
416 |
+
'skip' => __('Skip'),
|
417 |
+
'update' => __('Update'),
|
418 |
+
),
|
419 |
+
'value' => 'skip',
|
420 |
+
'field_name' => 'found_action',
|
421 |
+
'help_text' => __('Orders are matched by their order IDs.'),
|
422 |
+
'help_text_conditional'=>array(
|
423 |
+
array(
|
424 |
+
'help_text'=> __('Retains the order in the store as is and skips the matching order from the input file.'),
|
425 |
+
'condition'=>array(
|
426 |
+
array('field'=>'wt_iew_found_action', 'value'=>'skip')
|
427 |
+
)
|
428 |
+
),
|
429 |
+
array(
|
430 |
+
'help_text'=> __('Update order as per data from the input file'),
|
431 |
+
'condition'=>array(
|
432 |
+
array('field'=>'wt_iew_found_action', 'value'=>'update')
|
433 |
+
)
|
434 |
+
)
|
435 |
+
),
|
436 |
+
'form_toggler'=>array(
|
437 |
+
'type'=>'parent',
|
438 |
+
'target'=>'wt_iew_found_action'
|
439 |
+
)
|
440 |
+
);
|
441 |
+
|
442 |
+
|
443 |
+
|
444 |
+
foreach ($fields as $fieldk => $fieldv) {
|
445 |
+
$out[$fieldk] = $fieldv;
|
446 |
+
}
|
447 |
+
return $out;
|
448 |
+
}
|
449 |
+
|
450 |
+
/**
|
451 |
+
* Customize the items in filter export page
|
452 |
+
*/
|
453 |
+
public function exporter_alter_filter_fields($fields, $base, $filter_form_data) {
|
454 |
+
|
455 |
+
if ($base == $this->module_base)
|
456 |
+
{
|
457 |
+
/* altering help text of default fields */
|
458 |
+
/* altering help text of default fields */
|
459 |
+
$fields['limit']['label']=__('Total number of orders to export');
|
460 |
+
$fields['limit']['help_text']=__('Exports specified number of orders. e.g. Entering 500 with a skip count of 10 will export orders from 11th to 510th position.');
|
461 |
+
$fields['offset']['label']=__('Skip first <i>n</i> orders');
|
462 |
+
$fields['offset']['help_text']=__('Skips specified number of orders from the beginning. e.g. Enter 10 to skip first 10 orders from export.');
|
463 |
+
|
464 |
+
$fields['order_status'] = array(
|
465 |
+
'label' => __('Order Statuses'),
|
466 |
+
'placeholder' => __('All Order'),
|
467 |
+
'field_name' => 'order_status',
|
468 |
+
'sele_vals' => self::get_order_statuses(),
|
469 |
+
'help_text' => __(' Filter orders by their status type. You can specify more than one type for export.'),
|
470 |
+
'type' => 'multi_select',
|
471 |
+
'css_class' => 'wc-enhanced-select',
|
472 |
+
'validation_rule' => array('type'=>'text_arr')
|
473 |
+
);
|
474 |
+
$fields['products'] = array(
|
475 |
+
'label' => __('Product'),
|
476 |
+
'placeholder' => __('Search for a product…'),
|
477 |
+
'field_name' => 'products',
|
478 |
+
'sele_vals' => array(),
|
479 |
+
'help_text' => __('Export orders containing specific products. Key-in the specific product names to export orders accordingly.'),
|
480 |
+
'type' => 'multi_select',
|
481 |
+
'css_class' => 'wc-product-search',
|
482 |
+
'validation_rule' => array('type'=>'text_arr')
|
483 |
+
);
|
484 |
+
$fields['email'] = array(
|
485 |
+
'label' => __('Email'),
|
486 |
+
'placeholder' => __('Search for a Customer…'),
|
487 |
+
'field_name' => 'email',
|
488 |
+
'sele_vals' => array(),
|
489 |
+
'help_text' => __('Input the customer email to export orders pertaining to only these customers.'),
|
490 |
+
'type' => 'multi_select',
|
491 |
+
'css_class' => 'wc-customer-search',
|
492 |
+
'validation_rule' => array('type'=>'text_arr')
|
493 |
+
);
|
494 |
+
$fields['coupons'] = array(
|
495 |
+
'label' => __('Coupons'),
|
496 |
+
'placeholder' => __('Enter coupon codes separated by ,'),
|
497 |
+
'field_name' => 'coupons',
|
498 |
+
'sele_vals' => '',
|
499 |
+
'help_text' => __('Enter coupons codes separated by comma to export orders on which these coupons have been applied.'),
|
500 |
+
'type' => 'text',
|
501 |
+
'css_class' => '',
|
502 |
+
);
|
503 |
+
|
504 |
+
$fields['date_from'] = array(
|
505 |
+
'label' => __('Date From'),
|
506 |
+
'placeholder' => __('Date'),
|
507 |
+
'field_name' => 'date_from',
|
508 |
+
'sele_vals' => '',
|
509 |
+
'help_text' => __('Date on which the order was placed. Export orders placed on and after the specified date.'),
|
510 |
+
'type' => 'text',
|
511 |
+
'css_class' => 'wt_iew_datepicker',
|
512 |
+
// 'type' => 'field_html',
|
513 |
+
// 'field_html' => '<input type="text" name="date_from" class="wt_iew_datepicker" placeholder="'.__('From date').'" class="input-text" />',
|
514 |
+
);
|
515 |
+
|
516 |
+
$fields['date_to'] = array(
|
517 |
+
'label' => __('Date To'),
|
518 |
+
'placeholder' => __('Date'),
|
519 |
+
'field_name' => 'date_to',
|
520 |
+
'sele_vals' => '',
|
521 |
+
'help_text' => __('Date on which the order was placed. Export orders placed upto the specified date.'),
|
522 |
+
'type' => 'text',
|
523 |
+
'css_class' => 'wt_iew_datepicker',
|
524 |
+
// 'type' => 'field_html',
|
525 |
+
// 'field_html' => '<input type="text" name="date_to" class="wt_iew_datepicker" placeholder="'.__('To date').'" class="input-text" />',
|
526 |
+
);
|
527 |
+
|
528 |
+
|
529 |
+
}
|
530 |
+
return $fields;
|
531 |
+
}
|
532 |
+
|
533 |
+
public static function wt_get_product_id_by_sku($sku) {
|
534 |
+
global $wpdb;
|
535 |
+
$post_exists_sku = $wpdb->get_var($wpdb->prepare("
|
536 |
+
SELECT $wpdb->posts.ID
|
537 |
+
FROM $wpdb->posts
|
538 |
+
LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )
|
539 |
+
WHERE $wpdb->posts.post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )
|
540 |
+
AND $wpdb->postmeta.meta_key = '_sku' AND $wpdb->postmeta.meta_value = '%s'
|
541 |
+
", $sku));
|
542 |
+
if ($post_exists_sku) {
|
543 |
+
return $post_exists_sku;
|
544 |
+
}
|
545 |
+
return false;
|
546 |
+
}
|
547 |
+
|
548 |
+
public function get_item_by_id($id) {
|
549 |
+
$post['edit_url']=get_edit_post_link($id);
|
550 |
+
$post['title'] = $id;
|
551 |
+
return $post;
|
552 |
+
}
|
553 |
+
}
|
554 |
+
}
|
555 |
+
|
556 |
+
new Wt_Import_Export_For_Woo_Basic_Order();
|
admin/partials/_form_field_generator.php
ADDED
@@ -0,0 +1,378 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
foreach($form_fields as $key=>$value)
|
6 |
+
{
|
7 |
+
/* setting default value form fields list array */
|
8 |
+
$vl=(isset($value['value']) ? $value['value'] : '');
|
9 |
+
$vl=($vl=='' && isset($value['default_value']) ? $value['default_value'] : $vl);
|
10 |
+
|
11 |
+
$type=(isset($value['type']) ? $value['type'] : 'text');
|
12 |
+
$css_class=(isset($value['css_class']) ? $value['css_class'] : '');
|
13 |
+
$html_id=(isset($value['html_id']) ? ' id="'.$value['html_id'].'" ' : '');
|
14 |
+
$tr_id=(isset($value['tr_id']) ? ' id="'.$value['tr_id'].'" ' : '');
|
15 |
+
$tr_class=(isset($value['tr_class']) ? $value['tr_class'] : '');
|
16 |
+
$td_class1=(isset($value['td_class1']) ? $value['td_class1'] : '');
|
17 |
+
$td_class2=(isset($value['td_class2']) ? $value['td_class2'] : '');
|
18 |
+
$td_class3=(isset($value['td_class3']) ? $value['td_class3'] : '');
|
19 |
+
|
20 |
+
$tr_html=(isset($value['tr_html']) ? $value['tr_html'] : '');
|
21 |
+
$field_html=(isset($value['field_html']) ? $value['field_html'] : '');
|
22 |
+
$help_text=(isset($value['help_text']) ? $value['help_text'] : '');
|
23 |
+
$placeholder=(isset($value['placeholder']) ? $value['placeholder'] : '');
|
24 |
+
$attr_arr=(isset($value['attr']) ? $value['attr'] : array());
|
25 |
+
$after_form_field_html=(isset($value['after_form_field_html']) ? $value['after_form_field_html'] : ''); /* after form field `td` */
|
26 |
+
$after_form_field=(isset($value['after_form_field']) ? $value['after_form_field'] : ''); /* after form field */
|
27 |
+
$before_form_field=(isset($value['before_form_field']) ? $value['before_form_field'] : '');
|
28 |
+
$merge_left=(isset($value['merge_left']) ? $value['merge_left'] : false); /* merge field td with left td */
|
29 |
+
$merge_right=(isset($value['merge_right']) ? $value['merge_right'] : false); /* merge field td with right td */
|
30 |
+
$colspan=1;
|
31 |
+
if($merge_left)
|
32 |
+
{
|
33 |
+
$colspan++;
|
34 |
+
}
|
35 |
+
if($merge_right)
|
36 |
+
{
|
37 |
+
$colspan++;
|
38 |
+
}
|
39 |
+
$colspan_attr='';
|
40 |
+
if($colspan>1)
|
41 |
+
{
|
42 |
+
$colspan_attr=' colspan="'.$colspan.'"';
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* conditional help texts
|
47 |
+
* !!Important: Using OR mixed with AND then add OR conditions first.
|
48 |
+
*/
|
49 |
+
$conditional_help_html='';
|
50 |
+
if(isset($value['help_text_conditional']) && is_array($value['help_text_conditional']))
|
51 |
+
{
|
52 |
+
foreach ($value['help_text_conditional'] as $help_text_config)
|
53 |
+
{
|
54 |
+
if(is_array($help_text_config))
|
55 |
+
{
|
56 |
+
$condition_attr='';
|
57 |
+
if(is_array($help_text_config['condition']))
|
58 |
+
{
|
59 |
+
$previous_type=''; /* this for avoiding fields without glue */
|
60 |
+
foreach ($help_text_config['condition'] as $condition)
|
61 |
+
{
|
62 |
+
if(is_array($condition))
|
63 |
+
{
|
64 |
+
if($previous_type!='field')
|
65 |
+
{
|
66 |
+
$condition_attr.='['.$condition['field'].'='.$condition['value'].']';
|
67 |
+
$previous_type='field';
|
68 |
+
}
|
69 |
+
}else
|
70 |
+
{
|
71 |
+
if(is_string($condition))
|
72 |
+
{
|
73 |
+
$condition=strtoupper($condition);
|
74 |
+
if(($condition=='AND' || $condition=='OR') && $previous_type!='glue')
|
75 |
+
{
|
76 |
+
$condition_attr.='['.$condition.']';
|
77 |
+
$previous_type='glue';
|
78 |
+
}
|
79 |
+
}
|
80 |
+
}
|
81 |
+
}
|
82 |
+
}
|
83 |
+
$conditional_help_html.='<span class="wt-iew_form_help wt-iew_conditional_help_text" data-iew-help-condition="'.esc_attr($condition_attr).'">'.$help_text_config['help_text'].'</span>';
|
84 |
+
}
|
85 |
+
}
|
86 |
+
}
|
87 |
+
|
88 |
+
$form_toggler_p_class="";
|
89 |
+
$form_toggler_register="";
|
90 |
+
$form_toggler_child="";
|
91 |
+
if(isset($value['form_toggler']))
|
92 |
+
{
|
93 |
+
if($value['form_toggler']['type']=='parent')
|
94 |
+
{
|
95 |
+
$form_toggler_p_class="wt_iew_form_toggler";
|
96 |
+
$form_toggler_register=' wf_frm_tgl-target="'.$value['form_toggler']['target'].'"';
|
97 |
+
}
|
98 |
+
elseif($value['form_toggler']['type']=='child')
|
99 |
+
{
|
100 |
+
$form_toggler_child=' wf_frm_tgl-id="'.$value['form_toggler']['id'].'" wf_frm_tgl-val="'.$value['form_toggler']['val'].'" '.(isset($value['form_toggler']['chk']) ? 'wf_frm_tgl-chk="'.$value['form_toggler']['chk'].'"' : '').(isset($value['form_toggler']['depth']) ? ' wf_frm_tgl-lvl="'.$value['form_toggler']['depth'].'"' : '');
|
101 |
+
}else
|
102 |
+
{
|
103 |
+
$form_toggler_child=' wf_frm_tgl-id="'.$value['form_toggler']['id'].'" wf_frm_tgl-val="'.$value['form_toggler']['val'].'" '.(isset($value['form_toggler']['chk']) ? 'wf_frm_tgl-chk="'.$value['form_toggler']['chk'].'"' : '').(isset($value['form_toggler']['depth']) ? ' wf_frm_tgl-lvl="'.$value['form_toggler']['depth'].'"' : '');
|
104 |
+
$form_toggler_p_class="wt_iew_form_toggler";
|
105 |
+
$form_toggler_register=' wf_frm_tgl-target="'.$value['form_toggler']['target'].'"';
|
106 |
+
}
|
107 |
+
}
|
108 |
+
|
109 |
+
$field_group_attr=(isset($value['field_group']) ? ' data-field-group="'.$value['field_group'].'" ' : '');
|
110 |
+
$tr_class.=(isset($value['field_group']) ? ' wt_iew_field_group_children ' : ''); //add an extra class to tr when field grouping enabled
|
111 |
+
|
112 |
+
if($type=='image_export')
|
113 |
+
{
|
114 |
+
$css_class.=' wt_iew_separate_image_export';
|
115 |
+
}
|
116 |
+
|
117 |
+
$attr='';
|
118 |
+
$has_class_attr=0;
|
119 |
+
$css_attr_value='';
|
120 |
+
foreach ($attr_arr as $attr_key => $attr_value)
|
121 |
+
{
|
122 |
+
if($attr_key=='class')
|
123 |
+
{
|
124 |
+
$attr_value.=" ".$form_toggler_p_class." ".$css_class;
|
125 |
+
$form_toggler_p_class='';
|
126 |
+
$css_class='';
|
127 |
+
$has_class_attr=1;
|
128 |
+
$css_attr_value=$attr_value;
|
129 |
+
}
|
130 |
+
$attr.=$attr_key.'="'.$attr_value.'" ';
|
131 |
+
}
|
132 |
+
|
133 |
+
$css_class.=($form_toggler_p_class!="" ? ' '.$form_toggler_p_class : '');
|
134 |
+
$css_attr=($css_class!="" ? ' class="'.$css_class.'"' : '');
|
135 |
+
|
136 |
+
|
137 |
+
if($tr_html=="")
|
138 |
+
{
|
139 |
+
$form_field_name = isset($value['field_name']) ? $value['field_name'] : '';
|
140 |
+
$form_data_key=(substr($form_field_name,0,8)!=='wt_iew_' ? 'wt_iew_' : '').$form_field_name;
|
141 |
+
|
142 |
+
/* checking field value exist in form data array */
|
143 |
+
if(isset($form_data[$form_data_key]))
|
144 |
+
{
|
145 |
+
$vl=$form_data[$form_data_key];
|
146 |
+
}
|
147 |
+
if($type=='field_group_head') //heading for field group
|
148 |
+
{
|
149 |
+
$visibility=(isset($value['show_on_default']) ? $value['show_on_default'] : 0);
|
150 |
+
?>
|
151 |
+
<tr <?php echo $tr_id.$field_group_attr;?> class="<?php echo $tr_class;?>">
|
152 |
+
<td colspan="3" class="wt_iew_field_group">
|
153 |
+
<div class="wt_iew_field_group_hd">
|
154 |
+
<?php echo isset($value['head']) ? $value['head'] : ''; ?>
|
155 |
+
<div class="wt_iew_field_group_toggle_btn" data-id="<?php echo isset($value['group_id']) ? $value['group_id'] : ''; ?>" data-visibility="<?php echo $visibility; ?>"><span class="dashicons dashicons-arrow-<?php echo ($visibility==1 ? 'down' : 'right'); ?>"></span></div>
|
156 |
+
</div>
|
157 |
+
<div class="wt_iew_field_group_content">
|
158 |
+
<table></table>
|
159 |
+
</div>
|
160 |
+
</td>
|
161 |
+
</tr>
|
162 |
+
<?php
|
163 |
+
}else
|
164 |
+
{
|
165 |
+
?>
|
166 |
+
<tr <?php echo $tr_id.$field_group_attr;?> class="<?php echo $tr_class;?>" <?php echo $form_toggler_child; ?>>
|
167 |
+
<?php
|
168 |
+
if(!$merge_left) /* if merge left not enabled */
|
169 |
+
{
|
170 |
+
?>
|
171 |
+
<th class="<?php echo $td_class1;?>">
|
172 |
+
<label><?php echo isset($value['label']) ? $value['label'] : ''; ?></label>
|
173 |
+
</th>
|
174 |
+
<?php
|
175 |
+
}
|
176 |
+
?>
|
177 |
+
<td <?php echo $colspan_attr;?> class="<?php echo $td_class2;?>">
|
178 |
+
|
179 |
+
<?php
|
180 |
+
if($field_html=='')
|
181 |
+
{
|
182 |
+
echo $before_form_field;
|
183 |
+
if($type=='text' || $type=='number' || $type=='password')
|
184 |
+
{
|
185 |
+
?>
|
186 |
+
<input placeholder="<?php echo $placeholder;?>" type="<?php echo $type; ?>" <?php echo $html_id;?> <?php echo $css_attr;?> name="<?php echo $form_data_key;?>" value="<?php echo $vl;?>" <?php echo $attr;?> >
|
187 |
+
<?php
|
188 |
+
}
|
189 |
+
if($type=='textarea')
|
190 |
+
{
|
191 |
+
?>
|
192 |
+
<textarea placeholder="<?php echo $placeholder;?>" <?php echo $html_id;?> <?php echo $css_attr;?> name="<?php echo $form_data_key;?>" <?php echo $attr;?> ><?php echo $vl;?></textarea>
|
193 |
+
<?php
|
194 |
+
}
|
195 |
+
elseif($type=='multi_select')
|
196 |
+
{
|
197 |
+
$sele_vals=(isset($value['sele_vals']) && is_array($value['sele_vals']) ? $value['sele_vals'] : array());
|
198 |
+
$vl=(is_array($vl) ? $vl : array($vl));
|
199 |
+
$vl=array_filter($vl);
|
200 |
+
?>
|
201 |
+
<select <?php echo $html_id;?> <?php echo $css_attr;?> data-placeholder="<?php echo $placeholder;?>" name="<?php echo $form_data_key;?>" multiple="multiple" <?php echo $attr;?> >
|
202 |
+
<?php
|
203 |
+
foreach($sele_vals as $sele_val=>$sele_lbl)
|
204 |
+
{
|
205 |
+
?>
|
206 |
+
<option value="<?php echo $sele_val;?>" <?php echo (in_array($sele_val,$vl) ? 'selected' : ''); ?>><?php echo $sele_lbl;?></option>
|
207 |
+
<?php
|
208 |
+
}
|
209 |
+
|
210 |
+
/* in the case of ajax product search selectbox */
|
211 |
+
if($has_class_attr==1)
|
212 |
+
{
|
213 |
+
$css_class_arr=explode(" ", $css_attr_value);
|
214 |
+
}else
|
215 |
+
{
|
216 |
+
$css_class_arr=explode(" ", $css_class);
|
217 |
+
}
|
218 |
+
if(count($sele_vals)==0 && in_array('wc-product-search', $css_class_arr))
|
219 |
+
{
|
220 |
+
foreach($vl as $single_vl)
|
221 |
+
{
|
222 |
+
$single_vl=(int) $single_vl;
|
223 |
+
if($single_vl>0)
|
224 |
+
{
|
225 |
+
$product=wc_get_product($single_vl);
|
226 |
+
?>
|
227 |
+
<option value="<?php echo $single_vl;?>" selected><?php echo $product->get_title();?></option>
|
228 |
+
<?php
|
229 |
+
}
|
230 |
+
}
|
231 |
+
}
|
232 |
+
?>
|
233 |
+
</select>
|
234 |
+
<?php
|
235 |
+
}
|
236 |
+
elseif($type=='select')
|
237 |
+
{
|
238 |
+
$sele_vals=(isset($value['sele_vals']) && is_array($value['sele_vals']) ? $value['sele_vals'] : array());
|
239 |
+
$vl=(is_array($vl) ? $vl : array($vl));
|
240 |
+
?>
|
241 |
+
<select <?php echo $html_id;?> <?php echo $css_attr;?> data-placeholder="<?php echo $placeholder;?>" name="<?php echo $form_data_key;?>" <?php echo $attr;?> <?php echo $form_toggler_register;?> >
|
242 |
+
<?php
|
243 |
+
foreach($sele_vals as $sele_val=>$sele_lbl)
|
244 |
+
{
|
245 |
+
$sele_lbl_txt=(is_array($sele_lbl) ? ( isset($sele_lbl['value']) ? $sele_lbl['value'] : (isset($sele_lbl[0]) ? $sele_lbl[0] : '' ) ) : $sele_lbl);
|
246 |
+
|
247 |
+
/* check any extra data to append */
|
248 |
+
$sele_extra_attr='';
|
249 |
+
if(is_array($sele_lbl))
|
250 |
+
{
|
251 |
+
foreach($sele_lbl as $sele_lblk=>$sele_lblv)
|
252 |
+
{
|
253 |
+
if($sele_lblk=='value')
|
254 |
+
{
|
255 |
+
continue;
|
256 |
+
}
|
257 |
+
$sele_extra_attr.=' data-'.$sele_lblk.'="'.$sele_lblv.'"';
|
258 |
+
}
|
259 |
+
}
|
260 |
+
?>
|
261 |
+
<option value="<?php echo $sele_val;?>" <?php echo (in_array($sele_val,$vl) ? 'selected' : ''); ?> <?php echo $sele_extra_attr; ?> ><?php echo $sele_lbl_txt;?></option>
|
262 |
+
<?php
|
263 |
+
}
|
264 |
+
?>
|
265 |
+
</select>
|
266 |
+
<?php
|
267 |
+
}
|
268 |
+
elseif($type=='radio') //radio button
|
269 |
+
{
|
270 |
+
?>
|
271 |
+
<div class="wt_form_radio_block">
|
272 |
+
<?php
|
273 |
+
$radio_fields=isset($value['radio_fields']) ? $value['radio_fields'] : array();
|
274 |
+
foreach ($radio_fields as $rad_vl=>$rad_label)
|
275 |
+
{
|
276 |
+
?>
|
277 |
+
<input <?php echo $css_attr;?> type="radio" id="<?php echo $form_data_key.'_'.$rad_vl;?>" name="<?php echo $form_data_key;?>" value="<?php echo $rad_vl;?>" <?php echo ($vl==$rad_vl) ? ' checked="checked"' : ''; ?> <?php echo $attr;?> <?php echo $form_toggler_register;?> /> <?php echo $rad_label; ?>
|
278 |
+
|
279 |
+
<?php
|
280 |
+
}
|
281 |
+
?>
|
282 |
+
</div>
|
283 |
+
<?php
|
284 |
+
}
|
285 |
+
elseif($type=='image_export') //image export radio button
|
286 |
+
{
|
287 |
+
?>
|
288 |
+
<div class="wt_form_radio_block">
|
289 |
+
<?php
|
290 |
+
$radio_fields=array(
|
291 |
+
'Yes' => __('Yes'),
|
292 |
+
'No' => __('No')
|
293 |
+
);
|
294 |
+
foreach ($radio_fields as $rad_vl=>$rad_label)
|
295 |
+
{
|
296 |
+
?>
|
297 |
+
<input <?php echo $css_attr;?> type="radio" id="<?php echo $form_data_key.'_'.$rad_vl;?>" name="<?php echo $form_data_key;?>" value="<?php echo $rad_vl;?>" <?php echo ($vl==$rad_vl) ? ' checked="checked"' : ''; ?> <?php echo $attr;?> <?php echo $form_toggler_register;?> /> <?php echo $rad_label; ?>
|
298 |
+
|
299 |
+
<?php
|
300 |
+
}
|
301 |
+
?>
|
302 |
+
</div>
|
303 |
+
<?php
|
304 |
+
}
|
305 |
+
elseif($type=='checkbox') //checkbox
|
306 |
+
{
|
307 |
+
?>
|
308 |
+
<div class="wt_form_checkbox_block">
|
309 |
+
<?php
|
310 |
+
$checkbox_fields=isset($value['checkbox_fields']) ? $value['checkbox_fields'] : array();
|
311 |
+
foreach ($checkbox_fields as $chk_vl=>$chk_label)
|
312 |
+
{
|
313 |
+
?>
|
314 |
+
<input <?php echo $css_attr;?> type="checkbox" id="<?php echo $form_data_key.'_'.$chk_vl;?>" name="<?php echo $form_data_key;?>" value="<?php echo $chk_vl;?>" <?php echo ($vl==$chk_vl) ? ' checked="checked"' : ''; ?> <?php echo $attr;?> <?php echo $form_toggler_register;?> /> <?php echo $chk_label; ?>
|
315 |
+
|
316 |
+
<?php
|
317 |
+
}?>
|
318 |
+
</div>
|
319 |
+
<?php
|
320 |
+
}elseif($type=='uploader')
|
321 |
+
{
|
322 |
+
$field_id=(isset($value['html_id']) ? $value['html_id'] : $form_data_key);
|
323 |
+
?>
|
324 |
+
<div class="wt_iew_file_attacher_dv">
|
325 |
+
<input <?php echo ($html_id!="" ? $html_id : 'id="'.$field_id.'"');?> placeholder="<?php echo $placeholder;?>" <?php echo $css_attr;?> type="text" name="<?php echo $form_data_key; ?>" value="<?php echo $vl; ?>" <?php echo $attr;?>/>
|
326 |
+
<input type="button" name="upload_file" data-wt_iew_file_attacher_title="<?php _e('Choose a file.'); ?>" data-wt_iew_file_attacher_button_text="<?php _e('Select'); ?>" class="wf_button button button-primary wt_iew_file_attacher" wt_iew_file_attacher_target="#<?php echo $field_id; ?>" value="<?php _e('Upload'); ?>" />
|
327 |
+
</div>
|
328 |
+
<?php
|
329 |
+
}elseif($type=='dropzone') /* dropzone file uploader */
|
330 |
+
{
|
331 |
+
$dropzone_id=(isset($value['dropzone']) ? $value['dropzone'] : $form_data_key.'_dropzone');
|
332 |
+
$field_id=(isset($value['html_id']) ? $value['html_id'] : $form_data_key);
|
333 |
+
?>
|
334 |
+
<input <?php echo $css_attr;?> type="hidden" name="<?php echo $form_data_key; ?>" value="<?php echo $vl; ?>" <?php echo $attr;?> <?php echo ($html_id!="" ? $html_id : 'id="'.$field_id.'"');?>/>
|
335 |
+
|
336 |
+
<div id="<?php echo $dropzone_id;?>" class="wt_iew_dropzone" wt_iew_dropzone_target="#<?php echo $field_id; ?>">
|
337 |
+
<div class="dz-message">
|
338 |
+
<?php _e('Drop files here or click to upload');?>
|
339 |
+
<br /><br /><div class="wt_iew_dz_file_success"></div> <br />
|
340 |
+
<div class="wt_iew_dz_file_name"></div> <br />
|
341 |
+
<div class="wt_iew_dz_remove_link"></div> <br />
|
342 |
+
</div>
|
343 |
+
</div>
|
344 |
+
<?php
|
345 |
+
}
|
346 |
+
echo $after_form_field;
|
347 |
+
}else
|
348 |
+
{
|
349 |
+
echo $field_html;
|
350 |
+
}
|
351 |
+
if($help_text!="")
|
352 |
+
{
|
353 |
+
?>
|
354 |
+
<span class="wt-iew_form_help"><?php echo $help_text;?></span>
|
355 |
+
<?php
|
356 |
+
}
|
357 |
+
echo $conditional_help_html;
|
358 |
+
?>
|
359 |
+
</td>
|
360 |
+
<?php
|
361 |
+
if(!$merge_right) /* if merge right not enabled */
|
362 |
+
{
|
363 |
+
?>
|
364 |
+
<td class="<?php echo $td_class3;?>">
|
365 |
+
<?php echo $after_form_field_html; ?>
|
366 |
+
</td>
|
367 |
+
<?php
|
368 |
+
}
|
369 |
+
?>
|
370 |
+
</tr>
|
371 |
+
<?php
|
372 |
+
}
|
373 |
+
}else
|
374 |
+
{
|
375 |
+
echo $tr_html;
|
376 |
+
}
|
377 |
+
}
|
378 |
+
?>
|
admin/partials/wt-import-export-for-woo-admin-display.php
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
$wf_admin_view_path=WT_O_IEW_PLUGIN_PATH.'admin/views/';
|
6 |
+
$wf_img_path=WT_O_IEW_PLUGIN_URL.'images/';
|
7 |
+
?>
|
8 |
+
<div class="wrap" id="<?php echo WT_IEW_PLUGIN_ID_BASIC;?>">
|
9 |
+
<h2 class="wp-heading-inline">
|
10 |
+
<?php _e('Import Export for WooCommerce');?>
|
11 |
+
</h2>
|
12 |
+
<div class="nav-tab-wrapper wp-clearfix wt-iew-tab-head">
|
13 |
+
<?php
|
14 |
+
$tab_head_arr=array(
|
15 |
+
'wt-advanced'=>__('General'),
|
16 |
+
'wt-help'=>__('Help Guide')
|
17 |
+
);
|
18 |
+
if(isset($_GET['debug']))
|
19 |
+
{
|
20 |
+
$tab_head_arr['wt-debug']='Debug';
|
21 |
+
}
|
22 |
+
Wt_Import_Export_For_Woo_Basic::generate_settings_tabhead($tab_head_arr);
|
23 |
+
?>
|
24 |
+
</div>
|
25 |
+
<div class="wt-iew-tab-container">
|
26 |
+
<?php
|
27 |
+
//inside the settings form
|
28 |
+
$setting_views_a=array(
|
29 |
+
'wt-advanced'=>'admin-settings-advanced.php',
|
30 |
+
);
|
31 |
+
|
32 |
+
//outside the settings form
|
33 |
+
$setting_views_b=array(
|
34 |
+
'wt-help'=>'admin-settings-help.php',
|
35 |
+
);
|
36 |
+
if(isset($_GET['debug']))
|
37 |
+
{
|
38 |
+
$setting_views_b['wt-debug']='admin-settings-debug.php';
|
39 |
+
}
|
40 |
+
?>
|
41 |
+
<form method="post" class="wt_iew_settings_form_basic">
|
42 |
+
<?php
|
43 |
+
// Set nonce:
|
44 |
+
if (function_exists('wp_nonce_field'))
|
45 |
+
{
|
46 |
+
wp_nonce_field(WT_IEW_PLUGIN_ID_BASIC);
|
47 |
+
}
|
48 |
+
foreach ($setting_views_a as $target_id=>$value)
|
49 |
+
{
|
50 |
+
$settings_view=$wf_admin_view_path.$value;
|
51 |
+
if(file_exists($settings_view))
|
52 |
+
{
|
53 |
+
include $settings_view;
|
54 |
+
}
|
55 |
+
}
|
56 |
+
?>
|
57 |
+
<?php
|
58 |
+
//settings form fields for module
|
59 |
+
do_action('wt_iew_plugin_settings_form');?>
|
60 |
+
</form>
|
61 |
+
<?php
|
62 |
+
foreach ($setting_views_b as $target_id=>$value)
|
63 |
+
{
|
64 |
+
$settings_view=$wf_admin_view_path.$value;
|
65 |
+
if(file_exists($settings_view))
|
66 |
+
{
|
67 |
+
include $settings_view;
|
68 |
+
}
|
69 |
+
}
|
70 |
+
?>
|
71 |
+
<?php do_action('wt_iew_plugin_out_settings_form');?>
|
72 |
+
</div>
|
73 |
+
</div>
|
admin/views/_save_template_popup.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Template saving popup HTML for Import/Export
|
4 |
+
*
|
5 |
+
* @link
|
6 |
+
*
|
7 |
+
* @package Wt_Import_Export_For_Woo
|
8 |
+
*/
|
9 |
+
if (!defined('ABSPATH')) {
|
10 |
+
exit;
|
11 |
+
}
|
12 |
+
?>
|
13 |
+
<div class="wt_iew_template_name wt_iew_popup" data-save-label="<?php _e('Save');?>" data-saveas-label="<?php _e('Save as');?>">
|
14 |
+
<div class="wt_iew_popup_hd">
|
15 |
+
<span style="line-height:40px;" class="dashicons dashicons-edit"></span>
|
16 |
+
<span class="wt_iew_popup_hd_label"></span>
|
17 |
+
<div class="wt_iew_popup_close">X</div>
|
18 |
+
</div>
|
19 |
+
<div class="wt_iew_warn_box">
|
20 |
+
<div class="wt_iew_warn wt_iew_template_name_wrn">
|
21 |
+
<?php _e('Please enter name');?>
|
22 |
+
</div>
|
23 |
+
</div>
|
24 |
+
<div class="wt_iew_template_name_box">
|
25 |
+
<label class="wt_iew_template_name_label"><?php _e('Template name');?></label>
|
26 |
+
<input type="text" name="wt_iew_template_name_field" class="wt_iew_text_field wt_iew_template_name_field">
|
27 |
+
<div class="wt_iew_popup_footer">
|
28 |
+
<button type="button" name="" class="button-secondary wt_iew_popup_cancel">
|
29 |
+
<?php _e('Cancel');?>
|
30 |
+
</button>
|
31 |
+
<button type="button" name="" class="button-primary wt_iew_template_create_btn"></button>
|
32 |
+
</div>
|
33 |
+
</div>
|
34 |
+
</div>
|
admin/views/admin-settings-advanced.php
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'WPINC' ) ) {
|
3 |
+
die;
|
4 |
+
}
|
5 |
+
?>
|
6 |
+
<div class="wt-iew-tab-content" data-id="<?php echo $target_id;?>">
|
7 |
+
<?php
|
8 |
+
$fields=Wt_Import_Export_For_Woo_Basic_Common_Helper::get_advanced_settings_fields();
|
9 |
+
|
10 |
+
$advanced_settings=Wt_Import_Export_For_Woo_Basic_Common_Helper::get_advanced_settings();
|
11 |
+
?>
|
12 |
+
<table class="form-table wt-iew-form-table">
|
13 |
+
<?php
|
14 |
+
Wt_Import_Export_For_Woo_Basic_Common_Helper::field_generator($fields, $advanced_settings);
|
15 |
+
?>
|
16 |
+
</table>
|
17 |
+
<?php
|
18 |
+
include "admin-settings-save-button.php";
|
19 |
+
?>
|
20 |
+
</div>
|
admin/views/admin-settings-debug.php
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'WPINC' ) ) {
|
3 |
+
die;
|
4 |
+
}
|
5 |
+
?>
|
6 |
+
<div class="wt-iew-tab-content" data-id="<?php echo $target_id;?>">
|
7 |
+
|
8 |
+
</div>
|
admin/views/admin-settings-help.php
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'WPINC' ) ) {
|
3 |
+
die;
|
4 |
+
}
|
5 |
+
?>
|
6 |
+
<div class="wt-iew-tab-content" data-id="<?php echo $target_id;?>">
|
7 |
+
<ul class="wt_iew_sub_tab">
|
8 |
+
<li style="border-left:none; padding-left: 0px;" data-target="help-links"><a><?php _e('Help Links'); ?></a></li>
|
9 |
+
<li data-target="help-doc"><a><?php _e('Sample CSV');?></a></li>
|
10 |
+
</ul>
|
11 |
+
<div class="wt_iew_sub_tab_container">
|
12 |
+
<div class="wt_iew_sub_tab_content" data-id="help-links" style="display:block;">
|
13 |
+
<h3><?php _e('Help Links'); ?></h3>
|
14 |
+
<ul class="wf-help-links">
|
15 |
+
<li>
|
16 |
+
<img src="<?php echo WT_O_IEW_PLUGIN_URL;?>assets/images/documentation.png">
|
17 |
+
<h3><?php _e('Documentation'); ?></h3>
|
18 |
+
<p><?php _e('Refer to our documentation to set up and get started.'); ?></p>
|
19 |
+
<a target="_blank" href="https://www.webtoffee.com/category/documentation/" class="button button-primary">
|
20 |
+
<?php _e('Documentation'); ?>
|
21 |
+
</a>
|
22 |
+
</li>
|
23 |
+
<li>
|
24 |
+
<img src="<?php echo WT_O_IEW_PLUGIN_URL;?>assets/images/support.png">
|
25 |
+
<h3><?php _e('Help and Support'); ?></h3>
|
26 |
+
<p><?php _e('We would love to help you on any queries or issues.'); ?></p>
|
27 |
+
<a target="_blank" href="https://www.webtoffee.com/support/" class="button button-primary">
|
28 |
+
<?php _e('Contact Us'); ?>
|
29 |
+
</a>
|
30 |
+
</li>
|
31 |
+
</ul>
|
32 |
+
</div>
|
33 |
+
<div class="wt_iew_sub_tab_content" data-id="help-doc">
|
34 |
+
<!--<h3><?php //_e( 'Help Docs' ); ?></h3>-->
|
35 |
+
<ul class="wf-help-links">
|
36 |
+
<?php do_action( 'wt_user_addon_basic_help_content' ); ?>
|
37 |
+
<?php do_action( 'wt_order_addon_basic_help_content' ); ?>
|
38 |
+
<?php do_action( 'wt_coupon_addon_basic_help_content' ); ?>
|
39 |
+
</ul>
|
40 |
+
</div>
|
41 |
+
</div>
|
42 |
+
</div>
|
admin/views/admin-settings-save-button.php
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// If this file is called directly, abort.
|
3 |
+
if ( ! defined( 'WPINC' ) ) {
|
4 |
+
die;
|
5 |
+
}
|
6 |
+
$settings_button_title=isset($settings_button_title) ? $settings_button_title : 'Update Settings';
|
7 |
+
$before_button_text=isset($before_button_text) ? $before_button_text : '';
|
8 |
+
$after_button_text=isset($after_button_text) ? $after_button_text : '';
|
9 |
+
?>
|
10 |
+
<div style="clear: both;"></div>
|
11 |
+
<div class="wt-iew-plugin-toolbar bottom">
|
12 |
+
<div class="left">
|
13 |
+
</div>
|
14 |
+
<div class="right">
|
15 |
+
<?php echo $before_button_text; ?>
|
16 |
+
<input type="submit" name="wt_iew_update_admin_settings_form" value="<?php _e($settings_button_title); ?>" class="button button-primary" style="float:right;"/>
|
17 |
+
<?php echo $after_button_text; ?>
|
18 |
+
<span class="spinner" style="margin-top:11px"></span>
|
19 |
+
</div>
|
20 |
+
</div>
|
assets/images/documentation.png
ADDED
Binary file
|
assets/images/drag_icon.png
ADDED
Binary file
|
assets/images/loading.gif
ADDED
Binary file
|
images/csv.png → assets/images/sample-csv.png
RENAMED
File without changes
|
assets/images/support.png
ADDED
Binary file
|
helpers/class-wt-common-helper.php
ADDED
@@ -0,0 +1,287 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Basic_Common_Helper')){
|
3 |
+
class Wt_Import_Export_For_Woo_Basic_Common_Helper
|
4 |
+
{
|
5 |
+
|
6 |
+
public static $min_version_msg='';
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Get File name by url
|
10 |
+
* @param string $file_url URL of the file.
|
11 |
+
* @return string the base name of the given URL (File name).
|
12 |
+
*/
|
13 |
+
public static function wt_wc_get_filename_from_url( $file_url ) {
|
14 |
+
$parts = parse_url( $file_url );
|
15 |
+
if ( isset( $parts['path'] ) ) {
|
16 |
+
return basename( $parts['path'] );
|
17 |
+
}
|
18 |
+
}
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Get info like language code, parent product ID etc by product id.
|
22 |
+
* @param int Product ID.
|
23 |
+
* @return array/false.
|
24 |
+
*/
|
25 |
+
public static function wt_get_wpml_original_post_language_info($element_id){
|
26 |
+
$get_language_args = array('element_id' => $element_id, 'element_type' => 'post_product');
|
27 |
+
$original_post_language_info = apply_filters('wpml_element_language_details', null, $get_language_args);
|
28 |
+
return $original_post_language_info;
|
29 |
+
}
|
30 |
+
|
31 |
+
public static function wt_get_product_id_by_sku($sku){
|
32 |
+
global $wpdb;
|
33 |
+
$post_exists_sku = $wpdb->get_var($wpdb->prepare("
|
34 |
+
SELECT $wpdb->posts.ID
|
35 |
+
FROM $wpdb->posts
|
36 |
+
LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )
|
37 |
+
WHERE $wpdb->posts.post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )
|
38 |
+
AND $wpdb->postmeta.meta_key = '_sku' AND $wpdb->postmeta.meta_value = '%s'
|
39 |
+
", $sku));
|
40 |
+
if ($post_exists_sku) {
|
41 |
+
return $post_exists_sku;
|
42 |
+
}
|
43 |
+
return false;
|
44 |
+
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* To strip the specific string from the array key as well as value.
|
49 |
+
* @param array $array.
|
50 |
+
* @param string $data.
|
51 |
+
* @return array.
|
52 |
+
*/
|
53 |
+
public static function wt_array_walk($array , $data) {
|
54 |
+
$new_array =array();
|
55 |
+
foreach ($array as $key => $value) {
|
56 |
+
$new_array[str_replace($data, '', $key)] = str_replace($data, '', $value);
|
57 |
+
}
|
58 |
+
return $new_array;
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Check the minimum base version required for post type modules
|
63 |
+
*
|
64 |
+
*/
|
65 |
+
public static function check_base_version($post_type, $post_type_title, $min_version)
|
66 |
+
{
|
67 |
+
$warn_icon='<span class="dashicons dashicons-warning"></span> ';
|
68 |
+
if(!version_compare(WT_O_IEW_VERSION, $min_version, '>=')) /* not matching the min version */
|
69 |
+
{
|
70 |
+
self::$min_version_msg.=$warn_icon.sprintf(__("The %s requires a minimum version of %s %s. Please upgrade the %s accordingly."), "<b>$post_type_title</b>", "<b>".WT_O_IEW_PLUGIN_NAME."</b>", "<b>v$min_version</b>", "<b>".WT_O_IEW_PLUGIN_NAME."</b>").'<br />';
|
71 |
+
add_action('admin_notices', array(__CLASS__, 'no_minimum_base_version') );
|
72 |
+
return false;
|
73 |
+
}
|
74 |
+
return true;
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
*
|
79 |
+
* No minimum version error message
|
80 |
+
*/
|
81 |
+
public static function no_minimum_base_version()
|
82 |
+
{
|
83 |
+
?>
|
84 |
+
<div class="notice notice-warning">
|
85 |
+
<p>
|
86 |
+
<?php
|
87 |
+
echo self::$min_version_msg;
|
88 |
+
?>
|
89 |
+
</p>
|
90 |
+
</div>
|
91 |
+
<?php
|
92 |
+
}
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Decode the post data as normal array from json encoded from data.
|
96 |
+
* If step key is specified, then it will return the data corresponds to the form key
|
97 |
+
* @param array $form_data
|
98 |
+
* @param string $key
|
99 |
+
*/
|
100 |
+
public static function process_formdata($form_data, $key='')
|
101 |
+
{
|
102 |
+
if($key!="") /* if key is given then take its data */
|
103 |
+
{
|
104 |
+
if(isset($form_data[$key]))
|
105 |
+
{
|
106 |
+
if(is_array($form_data[$key]))
|
107 |
+
{
|
108 |
+
$form_data_vl=$form_data[$key];
|
109 |
+
}else
|
110 |
+
{
|
111 |
+
$form_data_vl=json_decode(stripslashes($form_data[$key]),true);
|
112 |
+
}
|
113 |
+
}else
|
114 |
+
{
|
115 |
+
$form_data_vl=array();
|
116 |
+
}
|
117 |
+
}else
|
118 |
+
{
|
119 |
+
$form_data_vl=array();
|
120 |
+
foreach($form_data as $form_datak=>$form_datav)
|
121 |
+
{
|
122 |
+
$form_data_vl[$form_datak]=self::process_formdata($form_data, $form_datak);
|
123 |
+
}
|
124 |
+
}
|
125 |
+
return (is_array($form_data_vl) ? $form_data_vl : array());
|
126 |
+
}
|
127 |
+
|
128 |
+
/**
|
129 |
+
* Form field generator
|
130 |
+
*/
|
131 |
+
public static function field_generator($form_fields, $form_data)
|
132 |
+
{
|
133 |
+
include plugin_dir_path( dirname( __FILE__ ) ).'admin/partials/_form_field_generator.php';
|
134 |
+
}
|
135 |
+
|
136 |
+
|
137 |
+
/**
|
138 |
+
* Save advanced settings
|
139 |
+
* @param array $settings array of setting values
|
140 |
+
*/
|
141 |
+
public static function set_advanced_settings($settings)
|
142 |
+
{
|
143 |
+
update_option('wt_iew_advanced_settings', $settings);
|
144 |
+
}
|
145 |
+
|
146 |
+
/**
|
147 |
+
*
|
148 |
+
* Extract validation rule from form field array
|
149 |
+
* @param array $fields form field array
|
150 |
+
*/
|
151 |
+
public static function extract_validation_rules($fields)
|
152 |
+
{
|
153 |
+
$out=array_map(function ($r) { return (isset($r['validation_rule']) ? $r['validation_rule'] : ''); }, $fields);
|
154 |
+
return array_filter($out);
|
155 |
+
}
|
156 |
+
|
157 |
+
/**
|
158 |
+
* Get advanced settings.
|
159 |
+
* @param string $key key for specific setting (optional)
|
160 |
+
* @return mixed if key provided then the value of key otherwise array of values
|
161 |
+
*/
|
162 |
+
public static function get_advanced_settings($key="")
|
163 |
+
{
|
164 |
+
$advanced_settings=get_option('wt_iew_advanced_settings');
|
165 |
+
$advanced_settings=($advanced_settings ? $advanced_settings : array());
|
166 |
+
if($key!="")
|
167 |
+
{
|
168 |
+
$key=(substr($key,0,8)!=='wt_iew_' ? 'wt_iew_' : '').$key;
|
169 |
+
if(isset($advanced_settings[$key]))
|
170 |
+
{
|
171 |
+
return $advanced_settings[$key];
|
172 |
+
}else
|
173 |
+
{
|
174 |
+
$default_settings=self::get_advanced_settings_default();
|
175 |
+
return (isset($default_settings[$key]) ? $default_settings[$key] : '');
|
176 |
+
}
|
177 |
+
}else
|
178 |
+
{
|
179 |
+
$default_settings=self::get_advanced_settings_default();
|
180 |
+
$advanced_settings=wp_parse_args($advanced_settings, $default_settings);
|
181 |
+
return $advanced_settings;
|
182 |
+
}
|
183 |
+
}
|
184 |
+
|
185 |
+
/**
|
186 |
+
* Get default value of advanced settings
|
187 |
+
* @return array array of default values
|
188 |
+
*
|
189 |
+
*/
|
190 |
+
public static function get_advanced_settings_default()
|
191 |
+
{
|
192 |
+
$fields=self::get_advanced_settings_fields();
|
193 |
+
foreach ($fields as $key => $value)
|
194 |
+
{
|
195 |
+
if(isset($value['value']))
|
196 |
+
{
|
197 |
+
$key=(substr($key,0,8)!=='wt_iew_' ? 'wt_iew_' : '').$key;
|
198 |
+
$out[$key]=$value['value'];
|
199 |
+
}
|
200 |
+
}
|
201 |
+
return $out;
|
202 |
+
}
|
203 |
+
|
204 |
+
/**
|
205 |
+
* Get advanced fields
|
206 |
+
* @return array array of fields
|
207 |
+
*
|
208 |
+
*/
|
209 |
+
public static function get_advanced_settings_fields()
|
210 |
+
{
|
211 |
+
$fields=array();
|
212 |
+
return apply_filters('wt_iew_advanced_setting_fields_basic', $fields);
|
213 |
+
}
|
214 |
+
|
215 |
+
|
216 |
+
public static function wt_allowed_screens(){
|
217 |
+
$screens=array('wt_import_export_for_woo_basic','wt_import_export_for_woo_basic_export','wt_import_export_for_woo_basic_import','wt_import_export_for_woo_basic_history','wt_import_export_for_woo_basic_history_log');
|
218 |
+
return apply_filters('wt_iew_allowed_screens_basic', $screens);
|
219 |
+
|
220 |
+
}
|
221 |
+
public static function wt_get_current_page(){
|
222 |
+
if (isset($_GET['page'])) {
|
223 |
+
return $_GET['page'];
|
224 |
+
}
|
225 |
+
return '';
|
226 |
+
}
|
227 |
+
|
228 |
+
public static function wt_is_screen_allowed(){
|
229 |
+
if(in_array(self::wt_get_current_page(), self::wt_allowed_screens())){
|
230 |
+
return true;
|
231 |
+
}else{
|
232 |
+
return false;
|
233 |
+
}
|
234 |
+
}
|
235 |
+
|
236 |
+
}
|
237 |
+
}
|
238 |
+
|
239 |
+
if(!function_exists('is_woocommerce_prior_to_basic')){
|
240 |
+
function is_woocommerce_prior_to_basic($version) {
|
241 |
+
|
242 |
+
$woocommerce_is_pre_version = (!defined('WC_VERSION') || version_compare(WC_VERSION, $version, '<')) ? true : false;
|
243 |
+
return $woocommerce_is_pre_version;
|
244 |
+
|
245 |
+
if (WC()->version < $version) {
|
246 |
+
return TRUE;
|
247 |
+
} else {
|
248 |
+
return FALSE;
|
249 |
+
}
|
250 |
+
}
|
251 |
+
}
|
252 |
+
|
253 |
+
if(!function_exists('wt_let_to_num_basic')){
|
254 |
+
function wt_let_to_num_basic( $size ) {
|
255 |
+
$l = substr( $size, -1 );
|
256 |
+
$ret = (int) substr( $size, 0, -1 );
|
257 |
+
switch ( strtoupper( $l ) ) {
|
258 |
+
case 'P':
|
259 |
+
$ret *= 1024;
|
260 |
+
// No break.
|
261 |
+
case 'T':
|
262 |
+
$ret *= 1024;
|
263 |
+
// No break.
|
264 |
+
case 'G':
|
265 |
+
$ret *= 1024;
|
266 |
+
// No break.
|
267 |
+
case 'M':
|
268 |
+
$ret *= 1024;
|
269 |
+
// No break.
|
270 |
+
case 'K':
|
271 |
+
$ret *= 1024;
|
272 |
+
// No break.
|
273 |
+
}
|
274 |
+
return $ret;
|
275 |
+
}
|
276 |
+
}
|
277 |
+
|
278 |
+
if(!function_exists('wt_removeBomUtf8_basic')){
|
279 |
+
function wt_removeBomUtf8_basic($s) {
|
280 |
+
if (substr($s, 0, 3) == chr(hexdec('EF')) . chr(hexdec('BB')) . chr(hexdec('BF'))) {
|
281 |
+
return substr($s, 3);
|
282 |
+
} else {
|
283 |
+
return $s;
|
284 |
+
}
|
285 |
+
}
|
286 |
+
}
|
287 |
+
|
helpers/class-wt-import-export-helper.php
ADDED
@@ -0,0 +1,223 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Import Export Helper Library
|
5 |
+
*
|
6 |
+
* Includes helper functions for import, export, history modules
|
7 |
+
* @author WebToffee <info@webtoffee.com>
|
8 |
+
*/
|
9 |
+
|
10 |
+
if(!class_exists('Wt_Iew_IE_Basic_Helper'))
|
11 |
+
{
|
12 |
+
/**
|
13 |
+
*
|
14 |
+
*/
|
15 |
+
class Wt_Iew_IE_Basic_Helper
|
16 |
+
{
|
17 |
+
|
18 |
+
public static function _get_csv_delimiters()
|
19 |
+
{
|
20 |
+
return array(
|
21 |
+
'comma'=>array('value'=>__('Comma'), 'val'=>","),
|
22 |
+
'semicolon'=>array('value'=>__('Semicolon'), 'val'=>";"),
|
23 |
+
'tab'=>array('value'=>__('Tab'), 'val'=>"\t"),
|
24 |
+
'space'=>array('value'=>__('Space'), 'val'=>" "),
|
25 |
+
'other'=>array('value'=>__('Other'), 'val'=>""),
|
26 |
+
);
|
27 |
+
}
|
28 |
+
public static function _get_local_file_path($file_url)
|
29 |
+
{
|
30 |
+
$file_path = untrailingslashit(ABSPATH).str_replace(site_url(), '', $file_url);
|
31 |
+
|
32 |
+
if(file_exists($file_path))
|
33 |
+
{
|
34 |
+
return $file_path;
|
35 |
+
}else
|
36 |
+
{
|
37 |
+
/* Retrying if the directory structure is different from wordpress default file structure */
|
38 |
+
$url_parms = explode('/', $file_url);
|
39 |
+
|
40 |
+
$file_name = end($url_parms);
|
41 |
+
|
42 |
+
$file_dir_name = prev($url_parms);
|
43 |
+
|
44 |
+
$file_path = WP_CONTENT_DIR.'/'.$file_dir_name.'/'.$file_name;
|
45 |
+
|
46 |
+
if(file_exists($file_path))
|
47 |
+
{
|
48 |
+
return $file_path;
|
49 |
+
}else
|
50 |
+
{
|
51 |
+
|
52 |
+
return false;
|
53 |
+
}
|
54 |
+
}
|
55 |
+
}
|
56 |
+
public static function get_validation_rules($step, $form_data, $module_obj)
|
57 |
+
{
|
58 |
+
$method_name='get_'.$step.'_screen_fields';
|
59 |
+
$out=array();
|
60 |
+
if(method_exists($module_obj, $method_name))
|
61 |
+
{
|
62 |
+
$fields=$module_obj->{$method_name}($form_data);
|
63 |
+
$out=Wt_Import_Export_For_Woo_Basic_Common_Helper::extract_validation_rules($fields);
|
64 |
+
}
|
65 |
+
$form_data=$module_obj=null;
|
66 |
+
unset($form_data, $module_obj);
|
67 |
+
return $out;
|
68 |
+
}
|
69 |
+
public static function sanitize_formdata($form_data, $module_obj)
|
70 |
+
{
|
71 |
+
$out=array();
|
72 |
+
foreach ($module_obj->steps as $step=>$step_data)
|
73 |
+
{
|
74 |
+
if($step=='mapping') //custom rule needed for mapping fieds
|
75 |
+
{
|
76 |
+
|
77 |
+
/* general mapping fields section */
|
78 |
+
if(isset($form_data['mapping_form_data']) && is_array($form_data['mapping_form_data']))
|
79 |
+
{
|
80 |
+
$mapping_form_data=$form_data['mapping_form_data'];
|
81 |
+
|
82 |
+
/* mapping fields. This is an internal purpose array */
|
83 |
+
if(isset($mapping_form_data['mapping_fields']) && is_array($mapping_form_data['mapping_fields']))
|
84 |
+
{
|
85 |
+
foreach ($mapping_form_data['mapping_fields'] as $key => $value)
|
86 |
+
{
|
87 |
+
$new_key=sanitize_text_field($key);
|
88 |
+
$value=array(sanitize_text_field($value[0]), absint($value[1]));
|
89 |
+
unset($mapping_form_data['mapping_fields'][$key]);
|
90 |
+
$mapping_form_data['mapping_fields'][$new_key]=$value;
|
91 |
+
}
|
92 |
+
}
|
93 |
+
|
94 |
+
/*mapping enabled meta items */
|
95 |
+
if(isset($mapping_form_data['mapping_enabled_fields']) && is_array($mapping_form_data['mapping_enabled_fields']))
|
96 |
+
{
|
97 |
+
$mapping_form_data['mapping_enabled_fields']=Wt_Iew_Sh::sanitize_item($mapping_form_data['mapping_enabled_fields'], 'text_arr');
|
98 |
+
}
|
99 |
+
|
100 |
+
/* mapping fields. Selected fields only */
|
101 |
+
if(isset($mapping_form_data['mapping_selected_fields']) && is_array($mapping_form_data['mapping_selected_fields']))
|
102 |
+
{
|
103 |
+
foreach ($mapping_form_data['mapping_selected_fields'] as $key => $value)
|
104 |
+
{
|
105 |
+
$new_key=sanitize_text_field($key);
|
106 |
+
unset($mapping_form_data['mapping_selected_fields'][$key]);
|
107 |
+
$mapping_form_data['mapping_selected_fields'][$new_key]=sanitize_text_field($value);
|
108 |
+
}
|
109 |
+
}
|
110 |
+
|
111 |
+
$out['mapping_form_data']=$mapping_form_data;
|
112 |
+
}
|
113 |
+
|
114 |
+
|
115 |
+
/* meta mapping fields section */
|
116 |
+
if(isset($form_data['meta_step_form_data']) && is_array($form_data['meta_step_form_data']))
|
117 |
+
{
|
118 |
+
$meta_step_form_data=$form_data['meta_step_form_data'];
|
119 |
+
/* mapping fields. This is an internal purpose array */
|
120 |
+
if(isset($meta_step_form_data['mapping_fields']) && is_array($meta_step_form_data['mapping_fields']))
|
121 |
+
{
|
122 |
+
foreach ($meta_step_form_data['mapping_fields'] as $meta_key => $meta_value)
|
123 |
+
{
|
124 |
+
foreach ($meta_value as $key => $value)
|
125 |
+
{
|
126 |
+
$new_key=sanitize_text_field($key);
|
127 |
+
$value=array(sanitize_text_field($value[0]), absint($value[1]));
|
128 |
+
unset($meta_value[$key]);
|
129 |
+
$meta_value[$new_key]=$value;
|
130 |
+
}
|
131 |
+
$meta_step_form_data['mapping_fields'][$meta_key]=$meta_value;
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
|
136 |
+
/* mapping fields. Selected fields only */
|
137 |
+
if(isset($meta_step_form_data['mapping_selected_fields']) && is_array($meta_step_form_data['mapping_selected_fields']))
|
138 |
+
{
|
139 |
+
foreach ($meta_step_form_data['mapping_selected_fields'] as $meta_key => $meta_value)
|
140 |
+
{
|
141 |
+
foreach ($meta_value as $key => $value)
|
142 |
+
{
|
143 |
+
$new_key=sanitize_text_field($key);
|
144 |
+
unset($meta_value[$key]);
|
145 |
+
$meta_value[$new_key]=sanitize_text_field($value);
|
146 |
+
}
|
147 |
+
$meta_step_form_data['mapping_selected_fields'][$meta_key]=$meta_value;
|
148 |
+
}
|
149 |
+
}
|
150 |
+
|
151 |
+
$out['meta_step_form_data']=$meta_step_form_data;
|
152 |
+
}
|
153 |
+
}else
|
154 |
+
{
|
155 |
+
$current_form_data_key=$step.'_form_data';
|
156 |
+
$current_form_data=(isset($form_data[$current_form_data_key]) ? $form_data[$current_form_data_key] : array());
|
157 |
+
if(in_array($step, $module_obj->step_need_validation_filter))
|
158 |
+
{
|
159 |
+
$validation_rule=self::get_validation_rules($step, $current_form_data, $module_obj);
|
160 |
+
|
161 |
+
foreach($current_form_data as $key => $value)
|
162 |
+
{
|
163 |
+
$no_prefix_key=str_replace('wt_iew_', '', $key);
|
164 |
+
$current_form_data[$key]=Wt_Iew_Sh::sanitize_data($value, $no_prefix_key, $validation_rule);
|
165 |
+
}
|
166 |
+
}else
|
167 |
+
{
|
168 |
+
$validation_rule=(isset($module_obj->validation_rule[$step]) ? $module_obj->validation_rule[$step] : array());
|
169 |
+
foreach($current_form_data as $key => $value)
|
170 |
+
{
|
171 |
+
$current_form_data[$key]=Wt_Iew_Sh::sanitize_data($value, $key, $validation_rule);
|
172 |
+
}
|
173 |
+
}
|
174 |
+
$out[$current_form_data_key]=$current_form_data;
|
175 |
+
}
|
176 |
+
}
|
177 |
+
$form_data=$current_form_data=$mapping_form_data=$meta_step_form_data=$module_obj=null;
|
178 |
+
unset($form_data, $current_form_data, $mapping_form_data, $meta_step_form_data, $module_obj);
|
179 |
+
return $out;
|
180 |
+
}
|
181 |
+
public static function debug_panel($module_base)
|
182 |
+
{
|
183 |
+
if($module_base=='import' || $module_base=='export')
|
184 |
+
{
|
185 |
+
$debug_panel_btns=array(
|
186 |
+
'refresh_step'=>array(
|
187 |
+
'title'=>__('Refresh the step'),
|
188 |
+
'icon'=>'dashicons dashicons-update',
|
189 |
+
'onclick'=>'wt_iew_basic_'.$module_base.'.refresh_step();',
|
190 |
+
),
|
191 |
+
'console_form_data'=>array(
|
192 |
+
'title'=>__('Console form data'),
|
193 |
+
'icon'=>'dashicons dashicons-code-standards',
|
194 |
+
'onclick'=>'wt_iew_basic_'.$module_base.'.console_formdata();',
|
195 |
+
),
|
196 |
+
);
|
197 |
+
}
|
198 |
+
|
199 |
+
$debug_panel_btns=apply_filters('wt_iew_debug_panel_buttons_basic', $debug_panel_btns, $module_base);
|
200 |
+
if(defined('WT_IEW_DEBUG_BASIC') && WT_IEW_DEBUG_BASIC && is_array($debug_panel_btns) && count($debug_panel_btns)>0)
|
201 |
+
{
|
202 |
+
?>
|
203 |
+
<div class="wt_iew_debug_panel" title="<?php _e('For debugging process');?>">
|
204 |
+
<div class="wt_iew_debug_panel_hd"><?php _e('Debug panel');?></div>
|
205 |
+
<div class="wt_iew_debug_panel_con">
|
206 |
+
<?php
|
207 |
+
foreach ($debug_panel_btns as $btn)
|
208 |
+
{
|
209 |
+
?>
|
210 |
+
<a onclick="<?php echo $btn['onclick'];?>" title="<?php echo $btn['title'];?>">
|
211 |
+
<span class="<?php echo $btn['icon'];?>"></span>
|
212 |
+
</a>
|
213 |
+
<?php
|
214 |
+
}
|
215 |
+
?>
|
216 |
+
</div>
|
217 |
+
</div>
|
218 |
+
<?php
|
219 |
+
}
|
220 |
+
}
|
221 |
+
}
|
222 |
+
|
223 |
+
}
|
helpers/class-wt-security-helper.php
ADDED
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Webtoffee Security Library
|
5 |
+
*
|
6 |
+
* Includes Data sanitization, Access checking
|
7 |
+
* @author WebToffee <info@webtoffee.com>
|
8 |
+
*/
|
9 |
+
|
10 |
+
if(!class_exists('Wt_Iew_Sh'))
|
11 |
+
{
|
12 |
+
|
13 |
+
class Wt_Iew_Sh
|
14 |
+
{
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Data sanitization function.
|
18 |
+
*
|
19 |
+
* @param mixed $val value to sanitize
|
20 |
+
* @param string $key array key in the validation rule
|
21 |
+
* @param array $validation_rule array of validation rules. Eg: array('field_key' => array('type' => 'textarea'))
|
22 |
+
* @return mixed sanitized value
|
23 |
+
*/
|
24 |
+
public static function sanitize_data($val, $key, $validation_rule = array())
|
25 |
+
{
|
26 |
+
if(isset($validation_rule[$key]) && is_array($validation_rule[$key])) /* rule declared/exists */
|
27 |
+
{
|
28 |
+
if(isset($validation_rule[$key]['type']))
|
29 |
+
{
|
30 |
+
$val = self::sanitize_item($val, $validation_rule[$key]['type']);
|
31 |
+
}
|
32 |
+
}else //if no rule is specified then it will be treated as text
|
33 |
+
{
|
34 |
+
$val = self::sanitize_item($val, 'text');
|
35 |
+
}
|
36 |
+
return $val;
|
37 |
+
}
|
38 |
+
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Sanitize individual data item
|
42 |
+
*
|
43 |
+
* @param mixed $val value to sanitize
|
44 |
+
* @param string $type value type
|
45 |
+
* @return mixed sanitized value
|
46 |
+
*/
|
47 |
+
public static function sanitize_item($val, $type='')
|
48 |
+
{
|
49 |
+
switch ($type)
|
50 |
+
{
|
51 |
+
case 'text':
|
52 |
+
$val = sanitize_text_field($val);
|
53 |
+
break;
|
54 |
+
case 'text_arr':
|
55 |
+
$val = self::sanitize_arr($val);
|
56 |
+
break;
|
57 |
+
case 'url':
|
58 |
+
$val = esc_url_raw($val);
|
59 |
+
break;
|
60 |
+
case 'url_arr':
|
61 |
+
$val = self::sanitize_arr($val, 'url');
|
62 |
+
break;
|
63 |
+
case 'textarea':
|
64 |
+
$val=sanitize_textarea_field($val);
|
65 |
+
break;
|
66 |
+
case 'int':
|
67 |
+
$val = intval($val);
|
68 |
+
break;
|
69 |
+
case 'int_arr':
|
70 |
+
$val = self::sanitize_arr($val, 'int');
|
71 |
+
break;
|
72 |
+
case 'absint':
|
73 |
+
$val = absint($val);
|
74 |
+
break;
|
75 |
+
case 'absint_arr':
|
76 |
+
$val = self::sanitize_arr($val, 'absint');
|
77 |
+
break;
|
78 |
+
case 'float':
|
79 |
+
$val = floatval($val);
|
80 |
+
break;
|
81 |
+
case 'post_content':
|
82 |
+
$val = wp_kses_post($val);
|
83 |
+
break;
|
84 |
+
case 'hex':
|
85 |
+
$val = sanitize_hex_color($val);
|
86 |
+
break;
|
87 |
+
case 'skip': /* skip the validation */
|
88 |
+
$val = $val;
|
89 |
+
break;
|
90 |
+
case 'file_name':
|
91 |
+
$val = sanitize_file_name($val);
|
92 |
+
break;
|
93 |
+
default:
|
94 |
+
$val = sanitize_text_field($val);
|
95 |
+
}
|
96 |
+
|
97 |
+
return $val;
|
98 |
+
}
|
99 |
+
|
100 |
+
/**
|
101 |
+
* Recursive array sanitization function
|
102 |
+
*
|
103 |
+
* @param mixed $arr value to sanitize
|
104 |
+
* @param string $type value type
|
105 |
+
* @return mixed sanitized value
|
106 |
+
*/
|
107 |
+
public static function sanitize_arr($arr, $type = 'text')
|
108 |
+
{
|
109 |
+
if(is_array($arr))
|
110 |
+
{
|
111 |
+
$out = array();
|
112 |
+
foreach($arr as $k=>$arrv)
|
113 |
+
{
|
114 |
+
if(is_array($arrv))
|
115 |
+
{
|
116 |
+
$out[$k] = self::sanitize_arr($arrv, $type);
|
117 |
+
}else
|
118 |
+
{
|
119 |
+
$out[$k] = self::sanitize_item($arrv, $type);
|
120 |
+
}
|
121 |
+
}
|
122 |
+
return $out;
|
123 |
+
}else
|
124 |
+
{
|
125 |
+
return self::sanitize_item($arr, $type);
|
126 |
+
}
|
127 |
+
}
|
128 |
+
|
129 |
+
/**
|
130 |
+
* User accessibility. Function checks user logged in status, nonce and role access.
|
131 |
+
*
|
132 |
+
* @param string $plugin_id unique plugin id. Note: This id is used as an identifier in filter name so please use characters allowed in filters
|
133 |
+
* @param string $nonce_id Nonce id. If not specified then uses plugin id
|
134 |
+
* @return boolean if user allowed or not
|
135 |
+
*/
|
136 |
+
public static function check_write_access($plugin_id, $nonce_id = '')
|
137 |
+
{
|
138 |
+
$er = true;
|
139 |
+
|
140 |
+
if(!is_user_logged_in()) //checks user is logged in
|
141 |
+
{
|
142 |
+
$er = false;
|
143 |
+
}
|
144 |
+
|
145 |
+
if($er === true) //no error then proceed
|
146 |
+
{
|
147 |
+
if(!(self::verify_nonce($plugin_id, $nonce_id))) //verifying nonce
|
148 |
+
{
|
149 |
+
$er = false;
|
150 |
+
}else
|
151 |
+
{
|
152 |
+
if(!self::check_role_access($plugin_id)) //Check user role
|
153 |
+
{
|
154 |
+
$er = false;
|
155 |
+
}
|
156 |
+
}
|
157 |
+
}
|
158 |
+
return $er;
|
159 |
+
}
|
160 |
+
|
161 |
+
/**
|
162 |
+
* Verifying nonce
|
163 |
+
*
|
164 |
+
* @param string $plugin_id unique plugin id. Note: This id is used as an identifier in filter name so please use characters allowed in filters
|
165 |
+
* @param string $nonce_id Nonce id. If not specified then uses plugin id
|
166 |
+
* @return boolean if user allowed or not
|
167 |
+
*/
|
168 |
+
public static function verify_nonce($plugin_id, $nonce_id = '')
|
169 |
+
{
|
170 |
+
$nonce = (isset($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '');
|
171 |
+
$nonce = (is_array($nonce) ? $nonce[0] : $nonce); //in some cases multiple nonces are declared
|
172 |
+
$nonce_id = ($nonce_id == "" ? $plugin_id : $nonce_id); //if nonce id not provided then uses plugin id as nonce id
|
173 |
+
|
174 |
+
if(!(wp_verify_nonce($nonce, $nonce_id))) //verifying nonce
|
175 |
+
{
|
176 |
+
return false;
|
177 |
+
}else
|
178 |
+
{
|
179 |
+
return true;
|
180 |
+
}
|
181 |
+
}
|
182 |
+
|
183 |
+
|
184 |
+
/**
|
185 |
+
* Checks if user role has access
|
186 |
+
*
|
187 |
+
* @param string $plugin_id unique plugin id. Note: This id is used as an identifier in filter name so please use characters allowed in filters
|
188 |
+
* @return boolean if user allowed or not
|
189 |
+
*/
|
190 |
+
public static function check_role_access($plugin_id)
|
191 |
+
{
|
192 |
+
$roles = array('manage_options');
|
193 |
+
$roles = apply_filters('wt_'.$plugin_id.'_alter_role_access_basic', $roles); //dynamic filter based on plugin id to alter roles
|
194 |
+
$roles = (!is_array($roles) ? array() : $roles);
|
195 |
+
$is_allowed = false;
|
196 |
+
|
197 |
+
foreach($roles as $role) //loop through roles
|
198 |
+
{
|
199 |
+
if(current_user_can($role))
|
200 |
+
{
|
201 |
+
$is_allowed = true;
|
202 |
+
break;
|
203 |
+
}
|
204 |
+
}
|
205 |
+
return $is_allowed;
|
206 |
+
}
|
207 |
+
|
208 |
+
}
|
209 |
+
}
|
images/Order-Import-Export-for-WooCommerce-Image.png
DELETED
Binary file
|
images/calendar.png
DELETED
Binary file
|
images/documentation.png
DELETED
Binary file
|
images/storefrog.png
DELETED
Binary file
|
images/webtoffee-logo_small.png
DELETED
Binary file
|
images/wf-ajax-loader.gif
DELETED
Binary file
|
images/wf-failed.png
DELETED
Binary file
|
images/wf-import.png
DELETED
Binary file
|
images/wf-notice.png
DELETED
Binary file
|
images/wf-success.png
DELETED
Binary file
|
includes/class-wf-cpnimpexpcsv-admin-screen.php
DELETED
@@ -1,94 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
3 |
-
exit;
|
4 |
-
}
|
5 |
-
|
6 |
-
class WF_CpnImpExpCsv_Admin_Screen {
|
7 |
-
|
8 |
-
public function __construct()
|
9 |
-
{
|
10 |
-
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
|
11 |
-
add_action( 'admin_print_styles', array( $this, 'admin_scripts' ) );
|
12 |
-
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
|
13 |
-
|
14 |
-
}
|
15 |
-
|
16 |
-
public function admin_notices()
|
17 |
-
{
|
18 |
-
if ( ! function_exists( 'mb_detect_encoding' ) ) {
|
19 |
-
echo '<div class="error"><p>' . __( 'Coupon CSV Import Export requires the function <code>mb_detect_encoding</code> to import and export CSV files. Please ask your hosting provider to enable this function.', 'order-import-export-for-woocommerce' ) . '</p></div>';
|
20 |
-
}
|
21 |
-
}
|
22 |
-
|
23 |
-
public function admin_menu()
|
24 |
-
{
|
25 |
-
$page = add_submenu_page( 'woocommerce', __( 'Coupon Im-Ex', 'order-import-export-for-woocommerce' ), __( 'Coupon Im-Ex', 'order-import-export-for-woocommerce' ), apply_filters( 'coupon_csv_coupon_role', 'manage_woocommerce' ), 'wf_coupon_csv_im_ex', array( $this, 'output' ) );
|
26 |
-
}
|
27 |
-
|
28 |
-
public static function hf_get_wc_path()
|
29 |
-
{
|
30 |
-
if (function_exists('WC')){
|
31 |
-
$wc_path = WC()->plugin_url();
|
32 |
-
}else{
|
33 |
-
$wc_path = plugins_url() . '/woocommerce';
|
34 |
-
}
|
35 |
-
return $wc_path;
|
36 |
-
}
|
37 |
-
|
38 |
-
public function admin_scripts()
|
39 |
-
{
|
40 |
-
$screen = get_current_screen();
|
41 |
-
$allowed_creen_id = array('admin','woocommerce_page_wf_coupon_csv_im_ex');
|
42 |
-
if (in_array($screen->id, $allowed_creen_id)) {
|
43 |
-
$wc_path = self::hf_get_wc_path();
|
44 |
-
wp_enqueue_style( 'woocommerce_admin_styles', $wc_path. '/assets/css/admin.css' );
|
45 |
-
wp_enqueue_style( 'woocommerce-coupon-csv-importer1', plugins_url( basename( plugin_dir_path( WF_CpnImpExpCsv_FILE ) ) . '/styles/wf-style.css', basename( __FILE__ ) ), '', '1.0.0', 'screen' );
|
46 |
-
}
|
47 |
-
|
48 |
-
}
|
49 |
-
|
50 |
-
public function output()
|
51 |
-
{
|
52 |
-
$tab = 'import';
|
53 |
-
|
54 |
-
|
55 |
-
if(! empty( $_GET['page'] ))
|
56 |
-
{
|
57 |
-
if ( $_GET['page'] == 'wf_coupon_csv_im_ex' ) {
|
58 |
-
$tab = 'coupon';
|
59 |
-
}
|
60 |
-
}
|
61 |
-
if( ! empty( $_GET['tab'] )) {
|
62 |
-
if( $_GET['tab'] == 'export' ) {
|
63 |
-
$tab = 'export';
|
64 |
-
}
|
65 |
-
|
66 |
-
else if ( $_GET['tab'] == 'coupon' ) {
|
67 |
-
$tab = 'coupon';
|
68 |
-
}
|
69 |
-
}
|
70 |
-
include( 'views/html-wf-admin-screen.php' );
|
71 |
-
}
|
72 |
-
|
73 |
-
|
74 |
-
public function admin_import_page() {
|
75 |
-
include( 'views/html-wf-getting-started.php' );
|
76 |
-
include( 'views/import/html-wf-import-coupons.php' );
|
77 |
-
$post_columns = include( 'exporter/data/data-wf-post-columns.php' );
|
78 |
-
include( 'views/export/html-wf-export-coupons.php' );
|
79 |
-
}
|
80 |
-
|
81 |
-
public function admin_export_page() {
|
82 |
-
$post_columns = include( 'exporter/data/data-wf-post-columns.php' );
|
83 |
-
include( 'views/export/html-wf-export-orders.php' );
|
84 |
-
}
|
85 |
-
|
86 |
-
public function admin_coupon_page()
|
87 |
-
{
|
88 |
-
include( 'views/import/html-wf-import-coupons.php' );
|
89 |
-
include( 'views/export/html-wf-export-coupons.php' );
|
90 |
-
}
|
91 |
-
|
92 |
-
}
|
93 |
-
|
94 |
-
new WF_CpnImpExpCsv_Admin_Screen();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/class-wf-cpnimpexpcsv-ajax-handler.php
DELETED
@@ -1,20 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
if (!defined('ABSPATH')) {
|
4 |
-
exit;
|
5 |
-
}
|
6 |
-
|
7 |
-
class WF_CpnImpExpCsv_AJAX_Handler {
|
8 |
-
|
9 |
-
public function __construct() {
|
10 |
-
add_action('wp_ajax_coupon_csv_import_request', array($this, 'csv_import_request'));
|
11 |
-
}
|
12 |
-
|
13 |
-
public function csv_import_request() {
|
14 |
-
define('WP_LOAD_IMPORTERS', true);
|
15 |
-
WF_CpnImpExpCsv_Importer::coupon_importer();
|
16 |
-
}
|
17 |
-
|
18 |
-
}
|
19 |
-
|
20 |
-
new WF_CpnImpExpCsv_AJAX_Handler();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/class-wf-cpnimpexpcsv-system-status-tools.php
DELETED
@@ -1,55 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
3 |
-
exit;
|
4 |
-
}
|
5 |
-
|
6 |
-
class WF_CpnImpExpCsv_System_Status_Tools {
|
7 |
-
|
8 |
-
/**
|
9 |
-
* Constructor
|
10 |
-
*/
|
11 |
-
public function __construct() {
|
12 |
-
add_filter( 'woocommerce_debug_tools', array( $this, 'tools' ) );
|
13 |
-
}
|
14 |
-
|
15 |
-
/**
|
16 |
-
* Tools we add to WC
|
17 |
-
* @param array $tools
|
18 |
-
* @return array
|
19 |
-
*/
|
20 |
-
public function tools( $tools ) {
|
21 |
-
$tools['delete_coupons'] = array(
|
22 |
-
'name' => __( 'Delete Coupons','order-import-export-for-woocommerce'),
|
23 |
-
'button' => __( 'Delete ALL coupons','order-import-export-for-woocommerce' ),
|
24 |
-
'desc' => __( 'This tool will delete all coupons allowing you to start fresh.', 'order-import-export-for-woocommerce' ),
|
25 |
-
'callback' => array( $this, 'delete_coupons' )
|
26 |
-
);
|
27 |
-
|
28 |
-
return $tools;
|
29 |
-
}
|
30 |
-
|
31 |
-
/**
|
32 |
-
* Delete coupons
|
33 |
-
*/
|
34 |
-
public function delete_coupons()
|
35 |
-
{
|
36 |
-
global $wpdb;
|
37 |
-
|
38 |
-
// Delete coupons
|
39 |
-
$result = absint( $wpdb->delete( $wpdb->posts, array( 'post_type' => 'shop_coupon' ) ) );
|
40 |
-
|
41 |
-
|
42 |
-
// Delete meta and term relationships with no post
|
43 |
-
$wpdb->query( "DELETE pm
|
44 |
-
FROM {$wpdb->postmeta} pm
|
45 |
-
LEFT JOIN {$wpdb->posts} wp ON wp.ID = pm.post_id
|
46 |
-
WHERE wp.ID IS NULL" );
|
47 |
-
|
48 |
-
|
49 |
-
echo '<div class="updated"><p>' . sprintf( __( '%d Coupons Deleted', 'order-import-export-for-woocommerce' ), ( $result) ) . '</p></div>';
|
50 |
-
}
|
51 |
-
|
52 |
-
|
53 |
-
}
|
54 |
-
|
55 |
-
new WF_CpnImpExpCsv_System_Status_Tools();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/class-wf-orderimpexp-plugin-review-request.php
DELETED
@@ -1,252 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Review request
|
5 |
-
*
|
6 |
-
*
|
7 |
-
* @package
|
8 |
-
*/
|
9 |
-
if (!defined('ABSPATH')) {
|
10 |
-
exit;
|
11 |
-
}
|
12 |
-
class WT_OrderImpExp_Review_Request
|
13 |
-
{
|
14 |
-
/**
|
15 |
-
* config options
|
16 |
-
*/
|
17 |
-
private $plugin_title = "Order / Coupon / Subscription Export Import Plugin for WooCommerce (BASIC)";
|
18 |
-
private $review_url = "https://wordpress.org/support/plugin/order-import-export-for-woocommerce/reviews/#new-post";
|
19 |
-
private $plugin_prefix = "wforderimpexp"; /* must be unique name */
|
20 |
-
private $activation_hook = "wforderimpexp_activate"; /* hook for activation, to store activated date */
|
21 |
-
private $deactivation_hook = "wforderimpexp_deactivate"; /* hook for deactivation, to delete activated date */
|
22 |
-
private $days_to_show_banner = 4; /* when did the banner to show */
|
23 |
-
private $remind_days = 2; /* remind interval in days */
|
24 |
-
private $webtoffee_logo_url = '/images/webtoffee-logo_small.png';
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
private $start_date = 0; /* banner to show count start date. plugin installed date, remind me later added date */
|
29 |
-
private $current_banner_state = 2; /* 1: active, 2: waiting to show(first after installation), 3: closed by user/not interested to review, 4: user done the review, 5:remind me later */
|
30 |
-
private $banner_state_option_name = ''; /* WP option name to save banner state */
|
31 |
-
private $start_date_option_name = ''; /* WP option name to save start date */
|
32 |
-
private $banner_css_class = ''; /* CSS class name for Banner HTML element. */
|
33 |
-
private $banner_message = ''; /* Banner message. */
|
34 |
-
private $later_btn_text = ''; /* Remind me later button text */
|
35 |
-
private $never_btn_text = ''; /* Never review button text. */
|
36 |
-
private $review_btn_text = ''; /* Review now button text. */
|
37 |
-
private $ajax_action_name = ''; /* Name of ajax action to save banner state. */
|
38 |
-
private $allowed_action_type_arr = array(
|
39 |
-
'later', /* remind me later */
|
40 |
-
'never', /* never */
|
41 |
-
'review', /* review now */
|
42 |
-
'closed', /* not interested */
|
43 |
-
);
|
44 |
-
|
45 |
-
public function __construct()
|
46 |
-
{
|
47 |
-
//Set config vars
|
48 |
-
$this->set_vars();
|
49 |
-
|
50 |
-
add_action($this->activation_hook, array($this, 'on_activate'));
|
51 |
-
add_action($this->deactivation_hook, array($this, 'on_deactivate'));
|
52 |
-
|
53 |
-
if ($this->check_condition()) /* checks the banner is active now */ {
|
54 |
-
$this->banner_message = sprintf(__("Hey, we at %sWebToffee%s would like to thank you for using our plugin. We would really appreciate if you could take a moment to drop a quick review that will inspire us to keep going.", 'order-import-export-for-woocommerce'), '<b>', '</b>');
|
55 |
-
|
56 |
-
/* button texts */
|
57 |
-
$this->later_btn_text = __("Remind me later", 'order-import-export-for-woocommerce');
|
58 |
-
$this->never_btn_text = __("Not interested", 'order-import-export-for-woocommerce');
|
59 |
-
$this->review_btn_text = __("Review now", 'order-import-export-for-woocommerce');
|
60 |
-
|
61 |
-
add_action('admin_notices', array($this, 'show_banner')); /* show banner */
|
62 |
-
add_action('admin_print_footer_scripts', array($this, 'add_banner_scripts')); /* add banner scripts */
|
63 |
-
add_action('wp_ajax_' . $this->ajax_action_name, array($this, 'process_user_action')); /* process banner user action */
|
64 |
-
}
|
65 |
-
}
|
66 |
-
|
67 |
-
/**
|
68 |
-
* Set config vars
|
69 |
-
*/
|
70 |
-
public function set_vars()
|
71 |
-
{
|
72 |
-
$this->ajax_action_name = $this->plugin_prefix . '_process_user_review_action';
|
73 |
-
$this->banner_state_option_name = $this->plugin_prefix . "_review_request";
|
74 |
-
$this->start_date_option_name = $this->plugin_prefix . "_start_date";
|
75 |
-
$this->banner_css_class = $this->plugin_prefix . "_review_request";
|
76 |
-
|
77 |
-
$this->start_date = absint(get_option($this->start_date_option_name));
|
78 |
-
$banner_state = absint(get_option($this->banner_state_option_name));
|
79 |
-
$this->current_banner_state = ($banner_state == 0 ? $this->current_banner_state : $banner_state);
|
80 |
-
}
|
81 |
-
|
82 |
-
/**
|
83 |
-
* Actions on plugin activation
|
84 |
-
* Saves activation date
|
85 |
-
*/
|
86 |
-
public function on_activate()
|
87 |
-
{
|
88 |
-
$this->reset_start_date();
|
89 |
-
}
|
90 |
-
|
91 |
-
/**
|
92 |
-
* Actions on plugin deactivation
|
93 |
-
* Removes activation date
|
94 |
-
*/
|
95 |
-
public function on_deactivate()
|
96 |
-
{
|
97 |
-
delete_option($this->start_date_option_name);
|
98 |
-
}
|
99 |
-
|
100 |
-
/**
|
101 |
-
* Reset the start date.
|
102 |
-
*/
|
103 |
-
private function reset_start_date()
|
104 |
-
{
|
105 |
-
update_option($this->start_date_option_name, time());
|
106 |
-
}
|
107 |
-
|
108 |
-
/**
|
109 |
-
* Update the banner state
|
110 |
-
*/
|
111 |
-
private function update_banner_state($val)
|
112 |
-
{
|
113 |
-
update_option($this->banner_state_option_name, $val);
|
114 |
-
}
|
115 |
-
|
116 |
-
/**
|
117 |
-
* Prints the banner
|
118 |
-
*/
|
119 |
-
public function show_banner()
|
120 |
-
{
|
121 |
-
$this->update_banner_state(1); /* update banner active state */
|
122 |
-
?>
|
123 |
-
<div class="<?php echo $this->banner_css_class; ?> notice-info notice is-dismissible">
|
124 |
-
<?php
|
125 |
-
if ($this->webtoffee_logo_url != "") {
|
126 |
-
?>
|
127 |
-
<h3 style="margin: 10px 0;"><?php echo $this->plugin_title; ?></h3>
|
128 |
-
<?php
|
129 |
-
}
|
130 |
-
?>
|
131 |
-
<p>
|
132 |
-
<?php echo $this->banner_message; ?>
|
133 |
-
</p>
|
134 |
-
<p>
|
135 |
-
<a class="button button-secondary" style="color:#333; border-color:#ccc; background:#efefef;" data-type="later"><?php echo $this->later_btn_text; ?></a>
|
136 |
-
<a class="button button-primary" data-type="review"><?php echo $this->review_btn_text; ?></a>
|
137 |
-
</p>
|
138 |
-
<div class="wt-cli-review-footer" style="position: relative;">
|
139 |
-
<span class="wt-cli-footer-icon" style="position: absolute;right: 0;bottom: 10px;"><img src="<?php echo plugins_url(basename(plugin_dir_path(WF_OrderImpExpCsv_FILE))).$this->webtoffee_logo_url; ?>" style="max-width:100px;"></span>
|
140 |
-
</div>
|
141 |
-
</div>
|
142 |
-
<?php
|
143 |
-
}
|
144 |
-
|
145 |
-
/**
|
146 |
-
* Ajax hook to process user action on the banner
|
147 |
-
*/
|
148 |
-
public function process_user_action()
|
149 |
-
{
|
150 |
-
check_ajax_referer($this->plugin_prefix);
|
151 |
-
if (isset($_POST['wt_review_action_type'])) {
|
152 |
-
$action_type = sanitize_text_field($_POST['wt_review_action_type']);
|
153 |
-
|
154 |
-
/* current action is in allowed action list */
|
155 |
-
if (in_array($action_type, $this->allowed_action_type_arr)) {
|
156 |
-
if ($action_type == 'never' || $action_type == 'closed') {
|
157 |
-
$new_banner_state = 3;
|
158 |
-
} elseif ($action_type == 'review') {
|
159 |
-
$new_banner_state = 4;
|
160 |
-
} else {
|
161 |
-
/* reset start date to current date */
|
162 |
-
$this->reset_start_date();
|
163 |
-
$new_banner_state = 5; /* remind me later */
|
164 |
-
}
|
165 |
-
$this->update_banner_state($new_banner_state);
|
166 |
-
}
|
167 |
-
}
|
168 |
-
exit();
|
169 |
-
}
|
170 |
-
|
171 |
-
/**
|
172 |
-
* Add banner JS to admin footer
|
173 |
-
*/
|
174 |
-
public function add_banner_scripts()
|
175 |
-
{
|
176 |
-
$ajax_url = admin_url('admin-ajax.php');
|
177 |
-
$nonce = wp_create_nonce($this->plugin_prefix);
|
178 |
-
?>
|
179 |
-
<script type="text/javascript">
|
180 |
-
(function($) {
|
181 |
-
"use strict";
|
182 |
-
|
183 |
-
/* prepare data object */
|
184 |
-
var data_obj = {
|
185 |
-
_wpnonce: '<?php echo $nonce; ?>',
|
186 |
-
action: '<?php echo $this->ajax_action_name; ?>',
|
187 |
-
wt_review_action_type: ''
|
188 |
-
};
|
189 |
-
|
190 |
-
$(document).on('click', '.<?php echo $this->banner_css_class; ?> a.button', function(e) {
|
191 |
-
e.preventDefault();
|
192 |
-
var elm = $(this);
|
193 |
-
var btn_type = elm.attr('data-type');
|
194 |
-
if (btn_type == 'review') {
|
195 |
-
window.open('<?php echo $this->review_url; ?>');
|
196 |
-
}
|
197 |
-
elm.parents('.<?php echo $this->banner_css_class; ?>').hide();
|
198 |
-
|
199 |
-
data_obj['wt_review_action_type'] = btn_type;
|
200 |
-
$.ajax({
|
201 |
-
url: '<?php echo $ajax_url; ?>',
|
202 |
-
data: data_obj,
|
203 |
-
type: 'POST'
|
204 |
-
});
|
205 |
-
|
206 |
-
}).on('click', '.<?php echo $this->banner_css_class; ?> .notice-dismiss', function(e) {
|
207 |
-
e.preventDefault();
|
208 |
-
data_obj['wt_review_action_type'] = 'closed';
|
209 |
-
$.ajax({
|
210 |
-
url: '<?php echo $ajax_url; ?>',
|
211 |
-
data: data_obj,
|
212 |
-
type: 'POST',
|
213 |
-
});
|
214 |
-
|
215 |
-
});
|
216 |
-
|
217 |
-
})(jQuery)
|
218 |
-
</script>
|
219 |
-
<?php
|
220 |
-
}
|
221 |
-
|
222 |
-
/**
|
223 |
-
* Checks the condition to show the banner
|
224 |
-
*/
|
225 |
-
private function check_condition()
|
226 |
-
{
|
227 |
-
|
228 |
-
if ($this->current_banner_state == 1) /* currently showing then return true */ {
|
229 |
-
return true;
|
230 |
-
}
|
231 |
-
|
232 |
-
if ($this->current_banner_state == 2 || $this->current_banner_state == 5) /* only waiting/remind later state */ {
|
233 |
-
if ($this->start_date == 0) /* unable to get activated date */ {
|
234 |
-
/* set current date as activation date*/
|
235 |
-
$this->reset_start_date();
|
236 |
-
return false;
|
237 |
-
}
|
238 |
-
|
239 |
-
$days = ($this->current_banner_state == 2 ? $this->days_to_show_banner : $this->remind_days);
|
240 |
-
|
241 |
-
$date_to_check = $this->start_date + (86400 * $days);
|
242 |
-
if ($date_to_check <= time()) /* time reached to show the banner */ {
|
243 |
-
return true;
|
244 |
-
} else {
|
245 |
-
return false;
|
246 |
-
}
|
247 |
-
}
|
248 |
-
|
249 |
-
return false;
|
250 |
-
}
|
251 |
-
}
|
252 |
-
new WT_OrderImpExp_Review_Request();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/class-wf-orderimpexp-plugin-uninstall-feedback.php
CHANGED
@@ -7,7 +7,7 @@ if (!class_exists('WF_OrderImpExp_Uninstall_Feedback')) :
|
|
7 |
class WF_OrderImpExp_Uninstall_Feedback {
|
8 |
|
9 |
protected $api_url='https://feedback.webtoffee.com/wp-json/wforderimpexp/v1/uninstall';
|
10 |
-
protected $current_version=
|
11 |
protected $auth_key='wforderimpexp_uninstall_1234#';
|
12 |
protected $plugin_id='wforderimpexp';
|
13 |
public function __construct() {
|
7 |
class WF_OrderImpExp_Uninstall_Feedback {
|
8 |
|
9 |
protected $api_url='https://feedback.webtoffee.com/wp-json/wforderimpexp/v1/uninstall';
|
10 |
+
protected $current_version=WT_O_IEW_VERSION;
|
11 |
protected $auth_key='wforderimpexp_uninstall_1234#';
|
12 |
protected $plugin_id='wforderimpexp';
|
13 |
public function __construct() {
|
includes/class-wf-orderimpexpcsv-admin-screen.php
DELETED
@@ -1,93 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
if (!defined('ABSPATH')) {
|
3 |
-
exit;
|
4 |
-
}
|
5 |
-
|
6 |
-
class WF_OrderImpExpCsv_Admin_Screen {
|
7 |
-
|
8 |
-
/**
|
9 |
-
* Constructor
|
10 |
-
*/
|
11 |
-
public function __construct() {
|
12 |
-
add_action('admin_menu', array($this, 'admin_menu'));
|
13 |
-
add_action('admin_print_styles', array($this, 'admin_scripts'));
|
14 |
-
add_action('admin_notices', array($this, 'admin_notices'));
|
15 |
-
}
|
16 |
-
|
17 |
-
/**
|
18 |
-
* Notices in admin
|
19 |
-
*/
|
20 |
-
public function admin_notices() {
|
21 |
-
if (!function_exists('mb_detect_encoding')) {
|
22 |
-
echo '<div class="error"><p>' . __('Order CSV Import Export requires the function <code>mb_detect_encoding</code> to import and export CSV files. Please ask your hosting provider to enable this function.', 'order-import-export-for-woocommerce') . '</p></div>';
|
23 |
-
}
|
24 |
-
}
|
25 |
-
|
26 |
-
/**
|
27 |
-
* Admin Menu
|
28 |
-
*/
|
29 |
-
public function admin_menu() {
|
30 |
-
$page = add_submenu_page('woocommerce', __('Order Im-Ex', 'order-import-export-for-woocommerce'), __('Order Im-Ex', 'order-import-export-for-woocommerce'), apply_filters('woocommerce_csv_order_role', 'manage_woocommerce'), 'wf_woocommerce_order_im_ex', array($this, 'output'));
|
31 |
-
}
|
32 |
-
|
33 |
-
/**
|
34 |
-
* Admin Scripts
|
35 |
-
*/
|
36 |
-
public function admin_scripts() {
|
37 |
-
$screen = get_current_screen();
|
38 |
-
$allowed_creen_id = array('admin','woocommerce_page_wf_woocommerce_order_im_ex');
|
39 |
-
if (in_array($screen->id, $allowed_creen_id)) {
|
40 |
-
wp_enqueue_script('wc-enhanced-select');
|
41 |
-
wp_enqueue_script('jquery-ui-datepicker');
|
42 |
-
wp_enqueue_style('woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css');
|
43 |
-
wp_enqueue_style('woocommerce-order-csv-importer', plugins_url(basename(plugin_dir_path(WF_OrderImpExpCsv_FILE)) . '/styles/wf-style.css', basename(__FILE__)), '', '1.0.0', 'screen');
|
44 |
-
wp_enqueue_style('woocommerce-order-csv-importer2', plugins_url(basename(plugin_dir_path(WF_OrderImpExpCsv_FILE)) . '/styles/jquery-ui.css', basename(__FILE__)), '', '1.0.0', 'screen');
|
45 |
-
|
46 |
-
}
|
47 |
-
}
|
48 |
-
|
49 |
-
/**
|
50 |
-
* Admin Screen output
|
51 |
-
*/
|
52 |
-
public function output() {
|
53 |
-
$tab = 'import';
|
54 |
-
if (!empty($_GET['tab'])) {
|
55 |
-
if ($_GET['tab'] == 'export') {
|
56 |
-
$tab = 'export';
|
57 |
-
}elseif($_GET['tab'] == 'subscription' ) {
|
58 |
-
$tab = 'subscription';
|
59 |
-
}elseif ($_GET['tab'] == 'help') {
|
60 |
-
$tab = 'help';
|
61 |
-
}
|
62 |
-
}
|
63 |
-
include( 'views/html-wf-admin-screen.php' );
|
64 |
-
}
|
65 |
-
|
66 |
-
/**
|
67 |
-
* Admin page for importing
|
68 |
-
*/
|
69 |
-
public function admin_import_page() {
|
70 |
-
include( 'views/import/html-wf-import-orders.php' );
|
71 |
-
$post_columns = include( 'exporter/data/data-wf-post-columns.php' );
|
72 |
-
include( 'views/export/html-wf-export-orders.php' );
|
73 |
-
}
|
74 |
-
|
75 |
-
/**
|
76 |
-
* Admin Page for exporting
|
77 |
-
*/
|
78 |
-
public function admin_export_page() {
|
79 |
-
$post_columns = include( 'exporter/data/data-wf-post-columns.php' );
|
80 |
-
include( 'views/export/html-wf-export-orders.php' );
|
81 |
-
}
|
82 |
-
|
83 |
-
public function admin_subscription_page() {
|
84 |
-
include( 'views/html-wf-getting-started-subscription.php' );
|
85 |
-
}
|
86 |
-
|
87 |
-
public function admin_help_page(){
|
88 |
-
include('views/html-wf-help-guide.php');
|
89 |
-
}
|
90 |
-
|
91 |
-
}
|
92 |
-
|
93 |
-
new WF_OrderImpExpCsv_Admin_Screen();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/class-wf-orderimpexpcsv-ajax-handler.php
DELETED
@@ -1,25 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
3 |
-
exit;
|
4 |
-
}
|
5 |
-
|
6 |
-
class WF_OrderImpExpCsv_AJAX_Handler {
|
7 |
-
|
8 |
-
/**
|
9 |
-
* Constructor
|
10 |
-
*/
|
11 |
-
public function __construct() {
|
12 |
-
add_action( 'wp_ajax_woocommerce_csv_order_import_request', array( $this, 'csv_order_import_request' ) );
|
13 |
-
}
|
14 |
-
|
15 |
-
/**
|
16 |
-
* Ajax event for importing a CSV
|
17 |
-
*/
|
18 |
-
public function csv_order_import_request() {
|
19 |
-
define( 'WP_LOAD_IMPORTERS', true );
|
20 |
-
WF_OrderImpExpCsv_Importer::order_importer();
|
21 |
-
}
|
22 |
-
|
23 |
-
}
|
24 |
-
|
25 |
-
new WF_OrderImpExpCsv_AJAX_Handler();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/class-wf-orderimpexpcsv-system-status-tools.php
DELETED
@@ -1,94 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
3 |
-
exit;
|
4 |
-
}
|
5 |
-
|
6 |
-
class WF_OrderImpExpCsv_System_Status_Tools {
|
7 |
-
|
8 |
-
/**
|
9 |
-
* Constructor
|
10 |
-
*/
|
11 |
-
public function __construct() {
|
12 |
-
add_filter( 'woocommerce_debug_tools', array( $this, 'tools' ) );
|
13 |
-
}
|
14 |
-
|
15 |
-
/**
|
16 |
-
* Tools we add to WC
|
17 |
-
* @param array $tools
|
18 |
-
* @return array
|
19 |
-
*/
|
20 |
-
public function tools( $tools ) {
|
21 |
-
if(!isset($tools['delete_trashed_orders'])){
|
22 |
-
$tools['delete_trashed_orders'] = array(
|
23 |
-
'name' => __( 'Delete Trashed Orders','order-import-export-for-woocommerce'),
|
24 |
-
'button' => __( 'Delete Trashed Orders','order-import-export-for-woocommerce' ),
|
25 |
-
'desc' => __( 'This tool will delete all Trashed Orders.', 'order-import-export-for-woocommerce' ),
|
26 |
-
'callback' => array( $this, 'delete_trashed_orders' )
|
27 |
-
);
|
28 |
-
}
|
29 |
-
if(!isset($tools['delete_all_orders'])){
|
30 |
-
$tools['delete_all_orders'] = array(
|
31 |
-
'name' => __( 'Delete Orders','order-import-export-for-woocommerce'),
|
32 |
-
'button' => __( 'Delete ALL Orders','order-import-export-for-woocommerce' ),
|
33 |
-
'desc' => __( 'This tool will delete all orders allowing you to start fresh.', 'order-import-export-for-woocommerce' ),
|
34 |
-
'callback' => array( $this, 'delete_all_orders' )
|
35 |
-
);
|
36 |
-
}
|
37 |
-
return $tools;
|
38 |
-
}
|
39 |
-
|
40 |
-
/**
|
41 |
-
* Delete Trashed Orders
|
42 |
-
*/
|
43 |
-
public function delete_trashed_orders() {
|
44 |
-
global $wpdb;
|
45 |
-
// Delete Trashed Orders
|
46 |
-
$result = absint( $wpdb->delete( $wpdb->posts, array( 'post_type' => 'shop_order' , 'post_status' => 'trash') ) );
|
47 |
-
|
48 |
-
// Delete meta and term relationships with no post
|
49 |
-
$wpdb->query( "DELETE pm
|
50 |
-
FROM {$wpdb->postmeta} pm
|
51 |
-
LEFT JOIN {$wpdb->posts} wp ON wp.ID = pm.post_id
|
52 |
-
WHERE wp.ID IS NULL" );
|
53 |
-
// Delete order items with no post
|
54 |
-
$wpdb->query( "DELETE oi
|
55 |
-
FROM {$wpdb->prefix}woocommerce_order_items oi
|
56 |
-
LEFT JOIN {$wpdb->posts} wp ON wp.ID = oi.order_id
|
57 |
-
WHERE wp.ID IS NULL" );
|
58 |
-
// Delete order item meta with no post
|
59 |
-
$wpdb->query( "DELETE om
|
60 |
-
FROM {$wpdb->prefix}woocommerce_order_itemmeta om
|
61 |
-
LEFT JOIN {$wpdb->prefix}woocommerce_order_items oi ON oi.order_item_id = om.order_item_id
|
62 |
-
WHERE oi.order_item_id IS NULL" );
|
63 |
-
echo '<div class="updated"><p>' . sprintf( __( '%d Orders Deleted', 'order-import-export-for-woocommerce' ), ( $result ) ) . '</p></div>';
|
64 |
-
}
|
65 |
-
|
66 |
-
/**
|
67 |
-
* Delete all orders
|
68 |
-
*/
|
69 |
-
public function delete_all_orders() {
|
70 |
-
global $wpdb;
|
71 |
-
|
72 |
-
// Delete Orders
|
73 |
-
$result = absint( $wpdb->delete( $wpdb->posts, array( 'post_type' => 'shop_order' ) ) );
|
74 |
-
|
75 |
-
// Delete meta and term relationships with no post
|
76 |
-
$wpdb->query( "DELETE pm
|
77 |
-
FROM {$wpdb->postmeta} pm
|
78 |
-
LEFT JOIN {$wpdb->posts} wp ON wp.ID = pm.post_id
|
79 |
-
WHERE wp.ID IS NULL" );
|
80 |
-
// Delete order items with no post
|
81 |
-
$wpdb->query( "DELETE oi
|
82 |
-
FROM {$wpdb->prefix}woocommerce_order_items oi
|
83 |
-
LEFT JOIN {$wpdb->posts} wp ON wp.ID = oi.order_id
|
84 |
-
WHERE wp.ID IS NULL" );
|
85 |
-
// Delete order item meta with no post
|
86 |
-
$wpdb->query( "DELETE om
|
87 |
-
FROM {$wpdb->prefix}woocommerce_order_itemmeta om
|
88 |
-
LEFT JOIN {$wpdb->prefix}woocommerce_order_items oi ON oi.order_item_id = om.order_item_id
|
89 |
-
WHERE oi.order_item_id IS NULL" );
|
90 |
-
echo '<div class="updated"><p>' . sprintf( __( '%d Orders Deleted', 'order-import-export-for-woocommerce' ), $result ) . '</p></div>';
|
91 |
-
}
|
92 |
-
}
|
93 |
-
|
94 |
-
new WF_OrderImpExpCsv_System_Status_Tools();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/class-wt-import-export-for-woo-activator.php
ADDED
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Fired during plugin activation
|
4 |
+
*
|
5 |
+
* @link https://www.webtoffee.com/
|
6 |
+
* @since 1.0.0
|
7 |
+
*
|
8 |
+
* @package Wt_Import_Export_For_Woo
|
9 |
+
* @subpackage Wt_Import_Export_For_Woo/includes
|
10 |
+
*/
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Fired during plugin activation.
|
14 |
+
*
|
15 |
+
* This class defines all code necessary to run during the plugin's activation.
|
16 |
+
*
|
17 |
+
* @since 1.0.0
|
18 |
+
* @package Wt_Import_Export_For_Woo
|
19 |
+
* @subpackage Wt_Import_Export_For_Woo/includes
|
20 |
+
* @author Webtoffee <info@webtoffee.com>
|
21 |
+
*/
|
22 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Basic_Activator_Order')){
|
23 |
+
class Wt_Import_Export_For_Woo_Basic_Activator_Order {
|
24 |
+
|
25 |
+
/**
|
26 |
+
* Short Description. (use period)
|
27 |
+
*
|
28 |
+
* Long Description.
|
29 |
+
*
|
30 |
+
* @since 1.0.0
|
31 |
+
*/
|
32 |
+
public static function activate()
|
33 |
+
{
|
34 |
+
global $wpdb;
|
35 |
+
delete_option('wt_o_iew_is_active'); /* remove if exists */
|
36 |
+
|
37 |
+
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
38 |
+
if(is_multisite())
|
39 |
+
{
|
40 |
+
// Get all blogs in the network and activate plugin on each one
|
41 |
+
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
|
42 |
+
foreach($blog_ids as $blog_id )
|
43 |
+
{
|
44 |
+
switch_to_blog( $blog_id );
|
45 |
+
self::install_tables();
|
46 |
+
restore_current_blog();
|
47 |
+
}
|
48 |
+
}
|
49 |
+
else
|
50 |
+
{
|
51 |
+
self::install_tables();
|
52 |
+
}
|
53 |
+
|
54 |
+
add_option('wt_o_iew_is_active', 1);
|
55 |
+
}
|
56 |
+
|
57 |
+
public static function install_tables()
|
58 |
+
{
|
59 |
+
global $wpdb;
|
60 |
+
$charset_collate = $wpdb->get_charset_collate();
|
61 |
+
//install necessary tables
|
62 |
+
|
63 |
+
//creating table for saving template data================
|
64 |
+
$search_query = "SHOW TABLES LIKE %s";
|
65 |
+
$tb='wt_iew_mapping_template';
|
66 |
+
$like = '%' . $wpdb->prefix.$tb.'%';
|
67 |
+
$table_name = $wpdb->prefix.$tb;
|
68 |
+
if(!$wpdb->get_results($wpdb->prepare($search_query, $like), ARRAY_N))
|
69 |
+
{
|
70 |
+
$sql_settings = "CREATE TABLE IF NOT EXISTS `$table_name` (
|
71 |
+
`id` INT NOT NULL AUTO_INCREMENT,
|
72 |
+
`template_type` VARCHAR(255) NOT NULL,
|
73 |
+
`item_type` VARCHAR(255) NOT NULL,
|
74 |
+
`name` VARCHAR(255) NOT NULL,
|
75 |
+
`data` LONGTEXT NOT NULL,
|
76 |
+
PRIMARY KEY (`id`)
|
77 |
+
) DEFAULT CHARSET=utf8;";
|
78 |
+
dbDelta($sql_settings);
|
79 |
+
}
|
80 |
+
//creating table for saving template data================
|
81 |
+
|
82 |
+
//creating table for saving export/import history================
|
83 |
+
$search_query = "SHOW TABLES LIKE %s";
|
84 |
+
$tb='wt_iew_action_history';
|
85 |
+
$like = '%'.$wpdb->prefix.$tb.'%';
|
86 |
+
$table_name = $wpdb->prefix.$tb;
|
87 |
+
if(!$wpdb->get_results($wpdb->prepare($search_query, $like), ARRAY_N))
|
88 |
+
{
|
89 |
+
$sql_settings = "CREATE TABLE IF NOT EXISTS `$table_name` (
|
90 |
+
`id` INT NOT NULL AUTO_INCREMENT,
|
91 |
+
`template_type` VARCHAR(255) NOT NULL,
|
92 |
+
`item_type` VARCHAR(255) NOT NULL,
|
93 |
+
`file_name` VARCHAR(255) NOT NULL,
|
94 |
+
`created_at` INT NOT NULL DEFAULT '0',
|
95 |
+
`status` INT NOT NULL DEFAULT '0',
|
96 |
+
`status_text` VARCHAR(255) NOT NULL,
|
97 |
+
`offset` INT NOT NULL DEFAULT '0',
|
98 |
+
`total` INT NOT NULL DEFAULT '0',
|
99 |
+
`data` LONGTEXT NOT NULL,
|
100 |
+
PRIMARY KEY (`id`)
|
101 |
+
) DEFAULT CHARSET=utf8;";
|
102 |
+
dbDelta($sql_settings);
|
103 |
+
}
|
104 |
+
//creating table for saving export/import history================
|
105 |
+
|
106 |
+
//creating table for saving ftp details================
|
107 |
+
$search_query = "SHOW TABLES LIKE %s";
|
108 |
+
$tb='wt_iew_ftp';
|
109 |
+
$like = '%'.$wpdb->prefix.$tb.'%';
|
110 |
+
$table_name = $wpdb->prefix.$tb;
|
111 |
+
if(!$wpdb->get_results($wpdb->prepare($search_query, $like), ARRAY_N))
|
112 |
+
{
|
113 |
+
$sql_settings = "CREATE TABLE IF NOT EXISTS `$table_name` (
|
114 |
+
`id` INT NOT NULL AUTO_INCREMENT,
|
115 |
+
`name` VARCHAR(255) NOT NULL,
|
116 |
+
`server` VARCHAR(255) NOT NULL,
|
117 |
+
`user_name` VARCHAR(255) NOT NULL,
|
118 |
+
`password` VARCHAR(255) NOT NULL,
|
119 |
+
`port` INT NOT NULL DEFAULT '21',
|
120 |
+
`ftps` INT NOT NULL DEFAULT '0',
|
121 |
+
`is_sftp` INT NOT NULL DEFAULT '0',
|
122 |
+
`passive_mode` INT NOT NULL DEFAULT '0',
|
123 |
+
`export_path` VARCHAR(255) NOT NULL,
|
124 |
+
`import_path` VARCHAR(255) NOT NULL,
|
125 |
+
PRIMARY KEY (`id`)
|
126 |
+
) DEFAULT CHARSET=utf8;";
|
127 |
+
dbDelta($sql_settings);
|
128 |
+
}
|
129 |
+
//creating table for saving ftp details================
|
130 |
+
|
131 |
+
|
132 |
+
//creating table for saving cron data================
|
133 |
+
$search_query = "SHOW TABLES LIKE %s";
|
134 |
+
$tb='wt_iew_cron';
|
135 |
+
$like = '%'.$wpdb->prefix.$tb.'%';
|
136 |
+
$table_name = $wpdb->prefix.$tb;
|
137 |
+
if(!$wpdb->get_results($wpdb->prepare($search_query, $like), ARRAY_N))
|
138 |
+
{
|
139 |
+
$sql_settings = "CREATE TABLE IF NOT EXISTS `$table_name` (
|
140 |
+
`id` INT NOT NULL AUTO_INCREMENT,
|
141 |
+
`status` INT NOT NULL DEFAULT '0',
|
142 |
+
`old_status` INT NOT NULL DEFAULT '0',
|
143 |
+
`action_type` VARCHAR(255) NOT NULL,
|
144 |
+
`schedule_type` VARCHAR(50) NOT NULL,
|
145 |
+
`item_type` VARCHAR(255) NOT NULL,
|
146 |
+
`data` LONGTEXT NOT NULL,
|
147 |
+
`start_time` INT NOT NULL,
|
148 |
+
`cron_data` TEXT NOT NULL,
|
149 |
+
`last_run` INT NOT NULL,
|
150 |
+
`next_offset` INT NOT NULL DEFAULT '0',
|
151 |
+
`history_id_list` TEXT NOT NULL,
|
152 |
+
`history_id` INT NOT NULL,
|
153 |
+
PRIMARY KEY (`id`)
|
154 |
+
) DEFAULT CHARSET=utf8;";
|
155 |
+
dbDelta($sql_settings);
|
156 |
+
}
|
157 |
+
//creating table for saving cron data================
|
158 |
+
}
|
159 |
+
}
|
160 |
+
}
|
includes/class-wt-import-export-for-woo-deactivator.php
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Fired during plugin deactivation
|
5 |
+
*
|
6 |
+
* @link https://www.webtoffee.com/
|
7 |
+
* @since 1.0.0
|
8 |
+
*
|
9 |
+
* @package Wt_Import_Export_For_Woo
|
10 |
+
* @subpackage Wt_Import_Export_For_Woo/includes
|
11 |
+
*/
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Fired during plugin deactivation.
|
15 |
+
*
|
16 |
+
* This class defines all code necessary to run during the plugin's deactivation.
|
17 |
+
*
|
18 |
+
* @since 1.0.0
|
19 |
+
* @package Wt_Import_Export_For_Woo
|
20 |
+
* @subpackage Wt_Import_Export_For_Woo/includes
|
21 |
+
* @author Webtoffee <info@webtoffee.com>
|
22 |
+
*/
|
23 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Basic_Deactivator_Order')){
|
24 |
+
class Wt_Import_Export_For_Woo_Basic_Deactivator_Order {
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Short Description. (use period)
|
28 |
+
*
|
29 |
+
* Long Description.
|
30 |
+
*
|
31 |
+
* @since 1.0.0
|
32 |
+
*/
|
33 |
+
public static function deactivate() {
|
34 |
+
delete_option('wt_o_iew_is_active');
|
35 |
+
}
|
36 |
+
|
37 |
+
}
|
38 |
+
}
|
includes/class-wt-import-export-for-woo-i18n.php
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Define the internationalization functionality
|
5 |
+
*
|
6 |
+
* Loads and defines the internationalization files for this plugin
|
7 |
+
* so that it is ready for translation.
|
8 |
+
*
|
9 |
+
* @link https://www.webtoffee.com/
|
10 |
+
* @since 1.0.0
|
11 |
+
*
|
12 |
+
* @package Wt_Import_Export_For_Woo
|
13 |
+
* @subpackage Wt_Import_Export_For_Woo/includes
|
14 |
+
*/
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Define the internationalization functionality.
|
18 |
+
*
|
19 |
+
* Loads and defines the internationalization files for this plugin
|
20 |
+
* so that it is ready for translation.
|
21 |
+
*
|
22 |
+
* @since 1.0.0
|
23 |
+
* @package Wt_Import_Export_For_Woo
|
24 |
+
* @subpackage Wt_Import_Export_For_Woo/includes
|
25 |
+
* @author Webtoffee <info@webtoffee.com>
|
26 |
+
*/
|
27 |
+
if(!class_exists('Wt_Import_Export_For_Woo_i18n_Basic')){
|
28 |
+
class Wt_Import_Export_For_Woo_i18n_Basic {
|
29 |
+
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Load the plugin text domain for translation.
|
33 |
+
*
|
34 |
+
* @since 1.0.0
|
35 |
+
*/
|
36 |
+
public function load_plugin_textdomain() {
|
37 |
+
|
38 |
+
load_plugin_textdomain(
|
39 |
+
'wt-import-export-for-woo',
|
40 |
+
false,
|
41 |
+
dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
|
42 |
+
);
|
43 |
+
|
44 |
+
}
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
}
|
49 |
+
}
|
includes/class-wt-import-export-for-woo-loader.php
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Register all actions and filters for the plugin
|
5 |
+
*
|
6 |
+
* @link https://www.webtoffee.com/
|
7 |
+
* @since 1.0.0
|
8 |
+
*
|
9 |
+
* @package Wt_Import_Export_For_Woo
|
10 |
+
* @subpackage Wt_Import_Export_For_Woo/includes
|
11 |
+
*/
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Register all actions and filters for the plugin.
|
15 |
+
*
|
16 |
+
* Maintain a list of all hooks that are registered throughout
|
17 |
+
* the plugin, and register them with the WordPress API. Call the
|
18 |
+
* run function to execute the list of actions and filters.
|
19 |
+
*
|
20 |
+
* @package Wt_Import_Export_For_Woo
|
21 |
+
* @subpackage Wt_Import_Export_For_Woo/includes
|
22 |
+
* @author Webtoffee <info@webtoffee.com>
|
23 |
+
*/
|
24 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Loader_Basic')){
|
25 |
+
class Wt_Import_Export_For_Woo_Loader_Basic {
|
26 |
+
|
27 |
+
/**
|
28 |
+
* The array of actions registered with WordPress.
|
29 |
+
*
|
30 |
+
* @since 1.0.0
|
31 |
+
* @access protected
|
32 |
+
* @var array $actions The actions registered with WordPress to fire when the plugin loads.
|
33 |
+
*/
|
34 |
+
protected $actions;
|
35 |
+
|
36 |
+
/**
|
37 |
+
* The array of filters registered with WordPress.
|
38 |
+
*
|
39 |
+
* @since 1.0.0
|
40 |
+
* @access protected
|
41 |
+
* @var array $filters The filters registered with WordPress to fire when the plugin loads.
|
42 |
+
*/
|
43 |
+
protected $filters;
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Initialize the collections used to maintain the actions and filters.
|
47 |
+
*
|
48 |
+
* @since 1.0.0
|
49 |
+
*/
|
50 |
+
public function __construct() {
|
51 |
+
|
52 |
+
$this->actions = array();
|
53 |
+
$this->filters = array();
|
54 |
+
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Add a new action to the collection to be registered with WordPress.
|
59 |
+
*
|
60 |
+
* @since 1.0.0
|
61 |
+
* @param string $hook The name of the WordPress action that is being registered.
|
62 |
+
* @param object $component A reference to the instance of the object on which the action is defined.
|
63 |
+
* @param string $callback The name of the function definition on the $component.
|
64 |
+
* @param int $priority Optional. The priority at which the function should be fired. Default is 10.
|
65 |
+
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
|
66 |
+
*/
|
67 |
+
public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
|
68 |
+
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Add a new filter to the collection to be registered with WordPress.
|
73 |
+
*
|
74 |
+
* @since 1.0.0
|
75 |
+
* @param string $hook The name of the WordPress filter that is being registered.
|
76 |
+
* @param object $component A reference to the instance of the object on which the filter is defined.
|
77 |
+
* @param string $callback The name of the function definition on the $component.
|
78 |
+
* @param int $priority Optional. The priority at which the function should be fired. Default is 10.
|
79 |
+
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1
|
80 |
+
*/
|
81 |
+
public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
|
82 |
+
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* A utility function that is used to register the actions and hooks into a single
|
87 |
+
* collection.
|
88 |
+
*
|
89 |
+
* @since 1.0.0
|
90 |
+
* @access private
|
91 |
+
* @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
|
92 |
+
* @param string $hook The name of the WordPress filter that is being registered.
|
93 |
+
* @param object $component A reference to the instance of the object on which the filter is defined.
|
94 |
+
* @param string $callback The name of the function definition on the $component.
|
95 |
+
* @param int $priority The priority at which the function should be fired.
|
96 |
+
* @param int $accepted_args The number of arguments that should be passed to the $callback.
|
97 |
+
* @return array The collection of actions and filters registered with WordPress.
|
98 |
+
*/
|
99 |
+
private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
|
100 |
+
|
101 |
+
$hooks[] = array(
|
102 |
+
'hook' => $hook,
|
103 |
+
'component' => $component,
|
104 |
+
'callback' => $callback,
|
105 |
+
'priority' => $priority,
|
106 |
+
'accepted_args' => $accepted_args
|
107 |
+
);
|
108 |
+
|
109 |
+
return $hooks;
|
110 |
+
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Register the filters and actions with WordPress.
|
115 |
+
*
|
116 |
+
* @since 1.0.0
|
117 |
+
*/
|
118 |
+
public function run() {
|
119 |
+
|
120 |
+
foreach ( $this->filters as $hook ) {
|
121 |
+
add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
|
122 |
+
}
|
123 |
+
|
124 |
+
foreach ( $this->actions as $hook ) {
|
125 |
+
add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
|
126 |
+
}
|
127 |
+
|
128 |
+
}
|
129 |
+
|
130 |
+
}
|
131 |
+
}
|
includes/class-wt-import-export-for-woo-remoteadapter.php
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if(!class_exists('Wt_Import_Export_For_Woo_RemoteAdapter_Basic')){
|
3 |
+
abstract class Wt_Import_Export_For_Woo_RemoteAdapter_Basic
|
4 |
+
{
|
5 |
+
public $id='';
|
6 |
+
public $title='';
|
7 |
+
public function __construct()
|
8 |
+
{
|
9 |
+
|
10 |
+
}
|
11 |
+
abstract public function upload($local_file, $remote_file_name, $form_data, $out);
|
12 |
+
abstract public function delete();
|
13 |
+
}
|
14 |
+
}
|
includes/class-wt-import-export-for-woo.php
ADDED
@@ -0,0 +1,331 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The file that defines the core plugin class
|
4 |
+
*
|
5 |
+
* A class definition that includes attributes and functions used across both the
|
6 |
+
* public-facing side of the site and the admin area.
|
7 |
+
*
|
8 |
+
* @link https://www.webtoffee.com/
|
9 |
+
* @since 1.0.0
|
10 |
+
*
|
11 |
+
* @package Wt_Import_Export_For_Woo
|
12 |
+
* @subpackage Wt_Import_Export_For_Woo/includes
|
13 |
+
*/
|
14 |
+
|
15 |
+
/**
|
16 |
+
* The core plugin class.
|
17 |
+
*
|
18 |
+
* This is used to define internationalization, admin-specific hooks, and
|
19 |
+
* public-facing site hooks.
|
20 |
+
*
|
21 |
+
* Also maintains the unique identifier of this plugin as well as the current
|
22 |
+
* version of the plugin.
|
23 |
+
*
|
24 |
+
* @since 1.0.0
|
25 |
+
* @package Wt_Import_Export_For_Woo
|
26 |
+
* @subpackage Wt_Import_Export_For_Woo/includes
|
27 |
+
* @author Webtoffee <info@webtoffee.com>
|
28 |
+
*/
|
29 |
+
if(!class_exists('Wt_Import_Export_For_Woo_Basic')){
|
30 |
+
class Wt_Import_Export_For_Woo_Basic {
|
31 |
+
|
32 |
+
/**
|
33 |
+
* The loader that's responsible for maintaining and registering all hooks that power
|
34 |
+
* the plugin.
|
35 |
+
*
|
36 |
+
* @since 1.0.0
|
37 |
+
* @access protected
|
38 |
+
* @var Wt_Import_Export_For_Woo_Loader $loader Maintains and registers all hooks for the plugin.
|
39 |
+
*/
|
40 |
+
protected $loader;
|
41 |
+
|
42 |
+
/**
|
43 |
+
* The unique identifier of this plugin.
|
44 |
+
*
|
45 |
+
* @since 1.0.0
|
46 |
+
* @access protected
|
47 |
+
* @var string $plugin_name The string used to uniquely identify this plugin.
|
48 |
+
*/
|
49 |
+
protected $plugin_name;
|
50 |
+
|
51 |
+
/**
|
52 |
+
* The current version of the plugin.
|
53 |
+
*
|
54 |
+
* @since 1.0.0
|
55 |
+
* @access protected
|
56 |
+
* @var string $version The current version of the plugin.
|
57 |
+
*/
|
58 |
+
protected $version;
|
59 |
+
|
60 |
+
public static $loaded_modules=array();
|
61 |
+
|
62 |
+
public static $template_tb='wt_iew_mapping_template';
|
63 |
+
public static $history_tb='wt_iew_action_history';
|
64 |
+
public static $ftp_tb='wt_iew_ftp';
|
65 |
+
public static $cron_tb='wt_iew_cron';
|
66 |
+
|
67 |
+
public $plugin_admin;
|
68 |
+
public $plugin_public;
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Define the core functionality of the plugin.
|
72 |
+
*
|
73 |
+
* Set the plugin name and the plugin version that can be used throughout the plugin.
|
74 |
+
* Load the dependencies, define the locale, and set the hooks for the admin area and
|
75 |
+
* the public-facing side of the site.
|
76 |
+
*
|
77 |
+
* @since 1.0.0
|
78 |
+
*/
|
79 |
+
public function __construct() {
|
80 |
+
if ( defined( 'WT_O_IEW_VERSION' ) ) {
|
81 |
+
$this->version = WT_O_IEW_VERSION;
|
82 |
+
} else {
|
83 |
+
$this->version = '2.0.0';
|
84 |
+
}
|
85 |
+
$this->plugin_name = 'wt-import-export-for-woo-basic';
|
86 |
+
|
87 |
+
$this->load_dependencies();
|
88 |
+
$this->set_locale();
|
89 |
+
$this->define_admin_hooks();
|
90 |
+
$this->define_public_hooks();
|
91 |
+
|
92 |
+
}
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Load the required dependencies for this plugin.
|
96 |
+
*
|
97 |
+
* Include the following files that make up the plugin:
|
98 |
+
*
|
99 |
+
* - Wt_Import_Export_For_Woo_Loader. Orchestrates the hooks of the plugin.
|
100 |
+
* - Wt_Import_Export_For_Woo_i18n. Defines internationalization functionality.
|
101 |
+
* - Wt_Import_Export_For_Woo_Admin. Defines all hooks for the admin area.
|
102 |
+
* - Wt_Import_Export_For_Woo_Public. Defines all hooks for the public side of the site.
|
103 |
+
*
|
104 |
+
* Create an instance of the loader which will be used to register the hooks
|
105 |
+
* with WordPress.
|
106 |
+
*
|
107 |
+
* @since 1.0.0
|
108 |
+
* @access private
|
109 |
+
*/
|
110 |
+
private function load_dependencies() {
|
111 |
+
|
112 |
+
/**
|
113 |
+
* The class responsible for orchestrating the actions and filters of the
|
114 |
+
* core plugin.
|
115 |
+
*/
|
116 |
+
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wt-import-export-for-woo-loader.php';
|
117 |
+
|
118 |
+
/**
|
119 |
+
* The class responsible for defining internationalization functionality
|
120 |
+
* of the plugin.
|
121 |
+
*/
|
122 |
+
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wt-import-export-for-woo-i18n.php';
|
123 |
+
|
124 |
+
/**
|
125 |
+
* The class responsible for defining remote file functionality
|
126 |
+
* of the plugin.
|
127 |
+
*/
|
128 |
+
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wt-import-export-for-woo-remoteadapter.php';
|
129 |
+
|
130 |
+
/**
|
131 |
+
* The class responsible for defining all actions that occur in the admin area.
|
132 |
+
*/
|
133 |
+
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wt-import-export-for-woo-admin.php';
|
134 |
+
|
135 |
+
/**
|
136 |
+
* The class responsible for defining all actions that occur in the public-facing
|
137 |
+
* side of the site.
|
138 |
+
*/
|
139 |
+
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wt-import-export-for-woo-public.php';
|
140 |
+
|
141 |
+
/**
|
142 |
+
* Class includes input sanitization and role checking
|
143 |
+
*/
|
144 |
+
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'helpers/class-wt-security-helper.php';
|
145 |
+
|
146 |
+
/**
|
147 |
+
* Class includes common helper functions
|
148 |
+
*/
|
149 |
+
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'helpers/class-wt-common-helper.php';
|
150 |
+
|
151 |
+
/**
|
152 |
+
* Class includes helper functions for import and export modules
|
153 |
+
*/
|
154 |
+
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'helpers/class-wt-import-export-helper.php';
|
155 |
+
|
156 |
+
/**
|
157 |
+
* Class includes log writing functions
|
158 |
+
*/
|
159 |
+
require_once WT_O_IEW_PLUGIN_PATH . 'admin/classes/class-log.php';
|
160 |
+
require_once WT_O_IEW_PLUGIN_PATH . 'admin/classes/class-logwriter.php';
|
161 |
+
|
162 |
+
|
163 |
+
$this->loader = new Wt_Import_Export_For_Woo_Loader_Basic();
|
164 |
+
$this->plugin_admin = new Wt_Import_Export_For_Woo_Admin_Basic( $this->get_plugin_name(), $this->get_version() );
|
165 |
+
$this->plugin_public = new Wt_Import_Export_For_Woo_Public_Basic( $this->get_plugin_name(), $this->get_version() );
|
166 |
+
}
|
167 |
+
|
168 |
+
/**
|
169 |
+
* Define the locale for this plugin for internationalization.
|
170 |
+
*
|
171 |
+
* Uses the Wt_Import_Export_For_Woo_i18n class in order to set the domain and to register the hook
|
172 |
+
* with WordPress.
|
173 |
+
*
|
174 |
+
* @since 1.0.0
|
175 |
+
* @access private
|
176 |
+
*/
|
177 |
+
private function set_locale() {
|
178 |
+
|
179 |
+
$plugin_i18n = new Wt_Import_Export_For_Woo_i18n_Basic();
|
180 |
+
|
181 |
+
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
|
182 |
+
|
183 |
+
}
|
184 |
+
|
185 |
+
/**
|
186 |
+
* Register all of the hooks related to the admin area functionality
|
187 |
+
* of the plugin.
|
188 |
+
*
|
189 |
+
* @since 1.0.0
|
190 |
+
* @access private
|
191 |
+
*/
|
192 |
+
private function define_admin_hooks()
|
193 |
+
{
|
194 |
+
//ajax hook for saving settings, Includes plugin main settings and settings from module
|
195 |
+
$this->loader->add_action('wp_ajax_wt_iew_save_settings_basic',$this->plugin_admin,'save_settings');
|
196 |
+
|
197 |
+
/* Loading admin modules */
|
198 |
+
$this->plugin_admin->admin_modules();
|
199 |
+
|
200 |
+
/* Plugin page links */
|
201 |
+
// $this->loader->add_filter('plugin_action_links_'.WT_O_IEW_PLUGIN_BASENAME, $this->plugin_admin, 'plugin_action_links');
|
202 |
+
|
203 |
+
/* Admin menus */
|
204 |
+
$this->loader->add_action('admin_menu',$this->plugin_admin, 'admin_menu',11);
|
205 |
+
|
206 |
+
/* Enqueue CSS and JS */
|
207 |
+
$this->loader->add_action( 'admin_enqueue_scripts', $this->plugin_admin, 'enqueue_styles' );
|
208 |
+
$this->loader->add_action( 'admin_enqueue_scripts', $this->plugin_admin, 'enqueue_scripts' );
|
209 |
+
|
210 |
+
}
|
211 |
+
|
212 |
+
/**
|
213 |
+
* Register all of the hooks related to the public-facing functionality
|
214 |
+
* of the plugin.
|
215 |
+
*
|
216 |
+
* @since 1.0.0
|
217 |
+
* @access private
|
218 |
+
*/
|
219 |
+
private function define_public_hooks()
|
220 |
+
{
|
221 |
+
|
222 |
+
$this->loader->add_action( 'wp_enqueue_scripts', $this->plugin_public, 'enqueue_styles' );
|
223 |
+
$this->loader->add_action( 'wp_enqueue_scripts', $this->plugin_public, 'enqueue_scripts' );
|
224 |
+
|
225 |
+
}
|
226 |
+
|
227 |
+
/**
|
228 |
+
* Run the loader to execute all of the hooks with WordPress.
|
229 |
+
*
|
230 |
+
* @since 1.0.0
|
231 |
+
*/
|
232 |
+
public function run() {
|
233 |
+
$this->loader->run();
|
234 |
+
}
|
235 |
+
|
236 |
+
/**
|
237 |
+
* The name of the plugin used to uniquely identify it within the context of
|
238 |
+
* WordPress and to define internationalization functionality.
|
239 |
+
*
|
240 |
+
* @since 1.0.0
|
241 |
+
* @return string The name of the plugin.
|
242 |
+
*/
|
243 |
+
public function get_plugin_name() {
|
244 |
+
return $this->plugin_name;
|
245 |
+
}
|
246 |
+
|
247 |
+
/**
|
248 |
+
* The reference to the class that orchestrates the hooks with the plugin.
|
249 |
+
*
|
250 |
+
* @since 1.0.0
|
251 |
+
* @return Wt_Import_Export_For_Woo_Loader Orchestrates the hooks of the plugin.
|
252 |
+
*/
|
253 |
+
public function get_loader() {
|
254 |
+
return $this->loader;
|
255 |
+
}
|
256 |
+
|
257 |
+
/**
|
258 |
+
* Retrieve the version number of the plugin.
|
259 |
+
*
|
260 |
+
* @since 1.0.0
|
261 |
+
* @return string The version number of the plugin.
|
262 |
+
*/
|
263 |
+
public function get_version() {
|
264 |
+
return $this->version;
|
265 |
+
}
|
266 |
+
|
267 |
+
public static function get_module_id($module_base)
|
268 |
+
{
|
269 |
+
return WT_IEW_PLUGIN_ID_BASIC.'_'.$module_base;
|
270 |
+
}
|
271 |
+
|
272 |
+
/**
|
273 |
+
* Some modules are not start by default. So need to initialize via code OR get object of already started modules
|
274 |
+
*
|
275 |
+
* @since 1.0.0
|
276 |
+
*/
|
277 |
+
public static function load_modules($module)
|
278 |
+
{
|
279 |
+
if(Wt_Import_Export_For_Woo_Admin_Basic::module_exists($module))
|
280 |
+
{
|
281 |
+
if(!isset(self::$loaded_modules[$module]))
|
282 |
+
{
|
283 |
+
$module_class='Wt_Import_Export_For_Woo_Basic_'.ucfirst($module);
|
284 |
+
self::$loaded_modules[$module]=new $module_class;
|
285 |
+
}
|
286 |
+
return self::$loaded_modules[$module];
|
287 |
+
}
|
288 |
+
else
|
289 |
+
{
|
290 |
+
return null;
|
291 |
+
}
|
292 |
+
}
|
293 |
+
|
294 |
+
/**
|
295 |
+
* Generate tab head for settings page.
|
296 |
+
* @since 1.0.0
|
297 |
+
*/
|
298 |
+
public static function generate_settings_tabhead($title_arr, $type="plugin")
|
299 |
+
{
|
300 |
+
$out_arr=apply_filters("wt_iew_".$type."_settings_tabhead_basic",$title_arr);
|
301 |
+
foreach($out_arr as $k=>$v)
|
302 |
+
{
|
303 |
+
if(is_array($v))
|
304 |
+
{
|
305 |
+
$v=(isset($v[2]) ? $v[2] : '').$v[0].' '.(isset($v[1]) ? $v[1] : '');
|
306 |
+
}
|
307 |
+
?>
|
308 |
+
<a class="nav-tab" href="#<?php echo $k;?>"><?php echo $v; ?></a>
|
309 |
+
<?php
|
310 |
+
}
|
311 |
+
}
|
312 |
+
|
313 |
+
/**
|
314 |
+
* Get remote file adapters. Eg: FTP, Gdrive, OneDrive
|
315 |
+
* @param string $action action to be executed, If the current adapter is not suitable for a specific action then skip it
|
316 |
+
* @param string $adapter optional specify an adapter name to retrive the specific one
|
317 |
+
* @return array|single array of remote adapters or single adapter if the adapter name specified
|
318 |
+
*/
|
319 |
+
public static function get_remote_adapters($action, $adapter='')
|
320 |
+
{
|
321 |
+
$adapters=array();
|
322 |
+
$adapters = apply_filters("wt_iew_remote_adapters_basic", $adapters, $action, $adapter);
|
323 |
+
if($adapter != "")
|
324 |
+
{
|
325 |
+
return (isset($adapters[ $adapter ]) ? $adapters[ $adapter ] : null);
|
326 |
+
}
|
327 |
+
return $adapters;
|
328 |
+
}
|
329 |
+
|
330 |
+
}
|
331 |
+
}
|
includes/class-wt-non-apache-info.php
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( !defined( 'ABSPATH' ) ) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
if ( !class_exists( 'wt_inform_server_secure' ) ) {
|
6 |
+
|
7 |
+
class wt_inform_server_secure {
|
8 |
+
|
9 |
+
/**
|
10 |
+
* config options
|
11 |
+
*/
|
12 |
+
public $plugin = "";
|
13 |
+
public $banner_message = "";
|
14 |
+
public $sholud_show_server_info = '';
|
15 |
+
|
16 |
+
public function __construct( $plugin ) {
|
17 |
+
$this->plugin = $plugin;
|
18 |
+
$this->sholud_show_server_info = 'wt_' . $this->plugin . '_show_server_info';
|
19 |
+
|
20 |
+
if ( !$this->wt_get_display_server_info() ) {
|
21 |
+
if ( Wt_Import_Export_For_Woo_Basic_Common_Helper::wt_is_screen_allowed() ) {
|
22 |
+
$this->banner_css_class = 'wt_' . $this->plugin . '_show_server_info';
|
23 |
+
add_action( 'admin_notices', array( $this, 'show_banner' ) );
|
24 |
+
add_action( 'admin_print_footer_scripts', array( $this, 'add_banner_scripts' ) ); /* add banner scripts */
|
25 |
+
}
|
26 |
+
}
|
27 |
+
$this->ajax_action_name = $this->plugin . '_process_show_server_info_action';
|
28 |
+
add_action( 'wp_ajax_' . $this->ajax_action_name, array( $this, 'process_server_info__action' ) ); /* process banner user action */
|
29 |
+
}
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Prints the banner
|
33 |
+
*/
|
34 |
+
public function show_banner() {
|
35 |
+
?>
|
36 |
+
<div class="<?php echo $this->banner_css_class; ?> notice-warning notice is-dismissible">
|
37 |
+
|
38 |
+
<p>
|
39 |
+
<?php echo $this->banner_message; ?>
|
40 |
+
</p>
|
41 |
+
<p>
|
42 |
+
<?php if ( (strpos( $_SERVER[ 'SERVER_SOFTWARE' ], 'nginx' ) !== false ) ): ?>
|
43 |
+
<h4><?php _e( 'Incase of Nginx server, copy the below code into your server config file to restrict public access to the wp-content folder or contact the server team to assist accordingly.' ); ?></h4>
|
44 |
+
<code>
|
45 |
+
#Deny access to wp-content folders<br/>
|
46 |
+
location ~* ^/(wp-content)/(.*?)\.(zip|gz|tar|csv|bzip2|7z)\$ { deny all; }<br/>
|
47 |
+
location ~ ^/wp-content/webtoffee_import { deny all; }
|
48 |
+
</code>
|
49 |
+
<?php endif; ?>
|
50 |
+
</p>
|
51 |
+
</div>
|
52 |
+
<?php
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Ajax hook to process user action on the banner
|
57 |
+
*/
|
58 |
+
public function process_server_info__action() {
|
59 |
+
check_ajax_referer( $this->plugin );
|
60 |
+
if ( isset( $_POST[ 'wt_action_type' ] ) && 'dismiss' == $_POST[ 'wt_action_type' ] ) {
|
61 |
+
$this->wt_set_display_server_info( 1 );
|
62 |
+
}
|
63 |
+
exit();
|
64 |
+
}
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Add banner JS to admin footer
|
68 |
+
*/
|
69 |
+
public function add_banner_scripts() {
|
70 |
+
$ajax_url = admin_url( 'admin-ajax.php' );
|
71 |
+
$nonce = wp_create_nonce( $this->plugin );
|
72 |
+
?>
|
73 |
+
<script type="text/javascript">
|
74 |
+
( function ( $ ) {
|
75 |
+
"use strict";
|
76 |
+
|
77 |
+
/* prepare data object */
|
78 |
+
var data_obj = {
|
79 |
+
_wpnonce: '<?php echo $nonce; ?>',
|
80 |
+
action: '<?php echo $this->ajax_action_name; ?>',
|
81 |
+
wt_action_type: 'dismiss',
|
82 |
+
};
|
83 |
+
|
84 |
+
$( document ).on( 'click', '.<?php echo $this->banner_css_class; ?> .notice-dismiss', function ( e )
|
85 |
+
{
|
86 |
+
e.preventDefault();
|
87 |
+
$.ajax( {
|
88 |
+
url: '<?php echo $ajax_url; ?>',
|
89 |
+
data: data_obj,
|
90 |
+
type: 'POST',
|
91 |
+
} );
|
92 |
+
|
93 |
+
} );
|
94 |
+
|
95 |
+
} )( jQuery )
|
96 |
+
</script>
|
97 |
+
<?php
|
98 |
+
}
|
99 |
+
|
100 |
+
public function wt_get_display_server_info() {
|
101 |
+
|
102 |
+
if ( (strpos( $_SERVER[ 'SERVER_SOFTWARE' ], 'Apache' ) !== false) || (strpos( $_SERVER[ 'SERVER_SOFTWARE' ], 'LiteSpeed' ) !== false) ) {
|
103 |
+
return true;
|
104 |
+
} else {
|
105 |
+
return (bool) get_option( $this->sholud_show_server_info );
|
106 |
+
}
|
107 |
+
}
|
108 |
+
|
109 |
+
public function wt_set_display_server_info( $display = false ) {
|
110 |
+
update_option( $this->sholud_show_server_info, $display ? 1 : 0 );
|
111 |
+
}
|
112 |
+
|
113 |
+
}
|
114 |
+
|
115 |
+
}
|
includes/class-wt-order-legacy-menu-moved.php
ADDED
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) {
|
3 |
+
exit;
|
4 |
+
}
|
5 |
+
if (!class_exists('wt_order_legacy_menu_moved')) {
|
6 |
+
|
7 |
+
class wt_order_legacy_menu_moved {
|
8 |
+
|
9 |
+
/**
|
10 |
+
* config options
|
11 |
+
*/
|
12 |
+
public $plugin = "";
|
13 |
+
public $prefix = "";
|
14 |
+
public $menu_title = "";
|
15 |
+
public $plugin_title = "";
|
16 |
+
public $banner_message = "";
|
17 |
+
public $old_menu = '';
|
18 |
+
public $sholud_show_legacy_menu = '';
|
19 |
+
public $old_menu_params = array();
|
20 |
+
|
21 |
+
public function __construct($plugin) {
|
22 |
+
$this->plugin = $plugin;
|
23 |
+
$this->sholud_show_legacy_menu = 'wt_' . $this->plugin . '_show_legacy_menu';
|
24 |
+
add_action('upgrader_process_complete', array($this, 'wt_upgrade_completed'), 10, 2);
|
25 |
+
if ($this->wt_should_display_legacy_menu()) {
|
26 |
+
add_action('admin_menu', array($this, 'wt_maybe_add_legacy_menu_redirect'));
|
27 |
+
if (Wt_Import_Export_For_Woo_Basic_Common_Helper::wt_is_screen_allowed()) {
|
28 |
+
$this->banner_css_class = 'wt_' . $this->plugin . '_show_legacy_menu';
|
29 |
+
add_action('admin_notices', array($this, 'show_banner'));
|
30 |
+
add_action('admin_print_footer_scripts', array($this, 'add_banner_scripts')); /* add banner scripts */
|
31 |
+
}
|
32 |
+
}
|
33 |
+
$this->ajax_action_name = $this->plugin . '_process_show_legacy_menu_action';
|
34 |
+
add_action('wp_ajax_' . $this->ajax_action_name, array($this, 'process_user_action')); /* process banner user action */
|
35 |
+
add_action('admin_init',array($this,'wt_import_export_menu_old_moved'));
|
36 |
+
}
|
37 |
+
|
38 |
+
public function wt_upgrade_completed($upgrader_object, $options) {
|
39 |
+
// The path to our plugin's main file
|
40 |
+
$our_plugin = plugin_basename(__FILE__);
|
41 |
+
// If an update has taken place and the updated type is plugins and the plugins element exists
|
42 |
+
if ($options['action'] == 'update' && $options['type'] == 'plugin' && isset($options['plugins'])) {
|
43 |
+
// Iterate through the plugins being updated and check if ours is there
|
44 |
+
foreach ($options['plugins'] as $plugin) {
|
45 |
+
if ($plugin == $our_plugin) {
|
46 |
+
$this->display_legacy_menu(1);
|
47 |
+
}
|
48 |
+
}
|
49 |
+
}
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Prints the banner
|
54 |
+
*/
|
55 |
+
public function show_banner() {
|
56 |
+
?>
|
57 |
+
<div class="<?php echo $this->banner_css_class; ?> notice-info notice is-dismissible">
|
58 |
+
|
59 |
+
<p>
|
60 |
+
<?php echo $this->banner_message; ?>
|
61 |
+
</p>
|
62 |
+
<p>
|
63 |
+
|
64 |
+
<a class="button button-primary" data-type="remove_legacy_menu_banner"><?php _e('Remove order legacy menu');?></a>
|
65 |
+
</p>
|
66 |
+
</div>
|
67 |
+
<?php
|
68 |
+
}
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Ajax hook to process user action on the banner
|
72 |
+
*/
|
73 |
+
public function process_user_action() {
|
74 |
+
check_ajax_referer($this->plugin);
|
75 |
+
if (isset($_POST['wt_action_type']) && 'dismiss' == $_POST['wt_action_type']) {
|
76 |
+
$this->display_legacy_menu(0);
|
77 |
+
}
|
78 |
+
exit();
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Add banner JS to admin footer
|
83 |
+
*/
|
84 |
+
public function add_banner_scripts() {
|
85 |
+
$ajax_url = admin_url('admin-ajax.php');
|
86 |
+
$nonce = wp_create_nonce($this->plugin);
|
87 |
+
?>
|
88 |
+
<script type="text/javascript">
|
89 |
+
(function ($) {
|
90 |
+
"use strict";
|
91 |
+
|
92 |
+
/* prepare data object */
|
93 |
+
var data_obj = {
|
94 |
+
_wpnonce: '<?php echo $nonce; ?>',
|
95 |
+
action: '<?php echo $this->ajax_action_name; ?>',
|
96 |
+
wt_action_type: 'dismiss',
|
97 |
+
};
|
98 |
+
|
99 |
+
$(document).on('click', '.<?php echo $this->banner_css_class; ?> a.button', function (e)
|
100 |
+
{
|
101 |
+
e.preventDefault();
|
102 |
+
var elm = $(this);
|
103 |
+
elm.parents('.<?php echo $this->banner_css_class; ?>').hide();
|
104 |
+
|
105 |
+
$.ajax({
|
106 |
+
url: '<?php echo $ajax_url; ?>',
|
107 |
+
data: data_obj,
|
108 |
+
type: 'POST'
|
109 |
+
});
|
110 |
+
|
111 |
+
}).on('click', '.<?php echo $this->banner_css_class; ?> .notice-dismiss', function (e)
|
112 |
+
{
|
113 |
+
e.preventDefault();
|
114 |
+
$.ajax({
|
115 |
+
url: '<?php echo $ajax_url; ?>',
|
116 |
+
data: data_obj,
|
117 |
+
type: 'POST',
|
118 |
+
});
|
119 |
+
|
120 |
+
});
|
121 |
+
|
122 |
+
})(jQuery)
|
123 |
+
</script>
|
124 |
+
<?php
|
125 |
+
}
|
126 |
+
|
127 |
+
/**
|
128 |
+
* Maybe add menu item back in original spot to help people transition
|
129 |
+
*/
|
130 |
+
public function wt_maybe_add_legacy_menu_redirect() {
|
131 |
+
if(isset($this->old_menu_params) && !empty($this->old_menu_params) && is_array($this->old_menu_params)){
|
132 |
+
foreach ($this->old_menu_params as $menu) {
|
133 |
+
add_submenu_page($menu['parent_slug'],__($menu['menu_title']), __($menu['menu_title']), $menu['capability'], 'import-export-menu-old', array($this, 'wt_import_export_menu_old_moved_old'));
|
134 |
+
}
|
135 |
+
}
|
136 |
+
}
|
137 |
+
|
138 |
+
public function wt_import_export_menu_old_moved_old(){
|
139 |
+
// this mooved wt_import_export_menu_old_moved
|
140 |
+
}
|
141 |
+
|
142 |
+
/**
|
143 |
+
* Call back for transition menu item
|
144 |
+
*/
|
145 |
+
public function wt_import_export_menu_old_moved() {
|
146 |
+
if(isset($_GET['page']) && $_GET['page']=='import-export-menu-old'){
|
147 |
+
wp_safe_redirect(admin_url('/admin.php?page=wt_import_export_for_woo_basic_export'), 301);
|
148 |
+
exit();
|
149 |
+
}
|
150 |
+
}
|
151 |
+
|
152 |
+
public function wt_should_display_legacy_menu() {
|
153 |
+
return (bool) get_option($this->sholud_show_legacy_menu);
|
154 |
+
}
|
155 |
+
|
156 |
+
public function display_legacy_menu($display = false) {
|
157 |
+
update_option($this->sholud_show_legacy_menu, $display ? 1 : 0 );
|
158 |
+
}
|
159 |
+
|
160 |
+
}
|
161 |
+
|
162 |
+
}
|
includes/exporter/class-wf-cpnimpexpcsv-exporter.php
DELETED
@@ -1,107 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
if (!defined('ABSPATH')) {
|
4 |
-
exit;
|
5 |
-
}
|
6 |
-
|
7 |
-
class WF_CpnImpExpCsv_Exporter {
|
8 |
-
|
9 |
-
public static function do_export($post_type = 'shop_coupon') {
|
10 |
-
global $wpdb;
|
11 |
-
$export_limit = !empty($_POST['limit']) ? absint($_POST['limit']) : 999999999;
|
12 |
-
$export_count = 0;
|
13 |
-
$limit = 100;
|
14 |
-
$current_offset = !empty($_POST['offset']) ? absint($_POST['offset']) : 0;
|
15 |
-
$sortcolumn = !empty($_POST['sortcolumn']) ? sanitize_text_field($_POST['sortcolumn']) : 'ID';
|
16 |
-
$delimiter = !empty($_POST['delimiter']) ? wc_clean( wp_unslash($_POST['delimiter'])): ',';
|
17 |
-
$csv_columns = include( 'data/data-wf-post-columns-coupon.php' );
|
18 |
-
if ($limit > $export_limit)
|
19 |
-
$limit = $export_limit;
|
20 |
-
$wpdb->hide_errors();
|
21 |
-
@set_time_limit(0);
|
22 |
-
if (function_exists('apache_setenv'))
|
23 |
-
@apache_setenv('no-gzip', 1);
|
24 |
-
@ini_set('zlib.output_compression', 0);
|
25 |
-
@ob_end_clean();
|
26 |
-
|
27 |
-
header('Content-Type: text/csv; charset=UTF-8');
|
28 |
-
header('Content-Disposition: attachment; filename=woocommerce-coupon-export-' . date('Y_m_d_H_i_s', current_time('timestamp')) . '.csv');
|
29 |
-
header('Pragma: no-cache');
|
30 |
-
header('Expires: 0');
|
31 |
-
|
32 |
-
$fp = fopen('php://output', 'w');
|
33 |
-
|
34 |
-
$row = array();
|
35 |
-
foreach ($csv_columns as $column => $value) {
|
36 |
-
$row[] = $value;
|
37 |
-
}
|
38 |
-
|
39 |
-
$row = array_map('WF_CpnImpExpCsv_Exporter::wrap_column', $row);
|
40 |
-
fwrite($fp, implode($delimiter, $row) . "\n");
|
41 |
-
unset($row);
|
42 |
-
|
43 |
-
while ($export_count < $export_limit) {
|
44 |
-
$coupon_args = apply_filters('coupon_csv_product_export_args', array(
|
45 |
-
'numberposts' => $limit,
|
46 |
-
'post_status' => array('publish', 'pending', 'private', 'draft'),
|
47 |
-
'post_type' => 'shop_coupon',
|
48 |
-
'orderby' => $sortcolumn,
|
49 |
-
'suppress_filters' => false,
|
50 |
-
'order' => 'ASC',
|
51 |
-
'offset' => $current_offset
|
52 |
-
));
|
53 |
-
|
54 |
-
$coupons = get_posts($coupon_args);
|
55 |
-
if (!$coupons || is_wp_error($coupons))
|
56 |
-
break;
|
57 |
-
foreach ($coupons as $product) {
|
58 |
-
foreach ($csv_columns as $column => $value) {
|
59 |
-
if(is_array($product->$column)){
|
60 |
-
$product->$column = implode(',', $product->$column);
|
61 |
-
}
|
62 |
-
if (isset($product->meta->$column)) {
|
63 |
-
$row[] = self::format_data($product->meta->$column);
|
64 |
-
} elseif (isset($product->$column) && !is_array($product->$column)) {
|
65 |
-
if ($column === 'post_title') {
|
66 |
-
$row[] = sanitize_text_field($product->$column);
|
67 |
-
}elseif($column =='date_expires'){
|
68 |
-
$row[] = !empty($product->$column)?date("Y-m-d",$product->$column): '' ;
|
69 |
-
|
70 |
-
} else {
|
71 |
-
$row[] = self::format_data($product->$column);
|
72 |
-
}
|
73 |
-
} else {
|
74 |
-
$row[] = '';
|
75 |
-
}
|
76 |
-
}
|
77 |
-
$row = array_map('WF_CpnImpExpCsv_Exporter::wrap_column', $row);
|
78 |
-
fwrite($fp, implode($delimiter, $row) . "\n");
|
79 |
-
unset($row);
|
80 |
-
}
|
81 |
-
|
82 |
-
$current_offset += $limit;
|
83 |
-
$export_count += $limit;
|
84 |
-
unset($coupons);
|
85 |
-
}
|
86 |
-
fclose($fp);
|
87 |
-
exit;
|
88 |
-
}
|
89 |
-
|
90 |
-
public static function format_data($data) {
|
91 |
-
if (!is_array($data))
|
92 |
-
;
|
93 |
-
$data = (string) urldecode($data);
|
94 |
-
$enc = mb_detect_encoding($data, 'UTF-8, ISO-8859-1', true);
|
95 |
-
$data = ( $enc == 'UTF-8' ) ? $data : utf8_encode($data);
|
96 |
-
return $data;
|
97 |
-
}
|
98 |
-
|
99 |
-
/**
|
100 |
-
* Wrap a column in quotes for the CSV
|
101 |
-
* @param string data to wrap
|
102 |
-
* @return string wrapped data
|
103 |
-
*/
|
104 |
-
public static function wrap_column($data) {
|
105 |
-
return '"' . str_replace('"', '""', $data) . '"';
|
106 |
-
}
|
107 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/exporter/class-wf-orderimpexpcsv-exporter.php
DELETED
@@ -1,452 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
if (!defined('ABSPATH')) {
|
4 |
-
exit;
|
5 |
-
}
|
6 |
-
|
7 |
-
class WF_OrderImpExpCsv_Exporter {
|
8 |
-
|
9 |
-
/**
|
10 |
-
* Order Exporter Tool
|
11 |
-
*/
|
12 |
-
|
13 |
-
public static function do_export($post_type = 'shop_order') {
|
14 |
-
global $wpdb;
|
15 |
-
$limit = !empty($_POST['limit']) ? absint($_POST['limit']) : 999999999;
|
16 |
-
$export_offset = !empty($_POST['offset']) ? absint($_POST['offset']) : 0;
|
17 |
-
$csv_columns = include( 'data/data-wf-post-columns.php' );
|
18 |
-
$user_columns_name = ! empty( $_POST['columns_name'] ) ? wc_clean($_POST['columns_name']) : $csv_columns;
|
19 |
-
$export_columns = ! empty( $_POST['columns'] ) ? wc_clean($_POST['columns']) : array();
|
20 |
-
$export_order_statuses = !empty($_POST['order_status']) ? wc_clean($_POST['order_status']) : 'any';
|
21 |
-
$delimiter = !empty($_POST['delimiter']) ? wc_clean( wp_unslash($_POST['delimiter'])) : ',';
|
22 |
-
$end_date = empty($_POST['end_date']) ? date('Y-m-d 23:59:59.99', current_time('timestamp')) : sanitize_text_field($_POST['end_date']) . ' 23:59:59.99';
|
23 |
-
$start_date = empty($_POST['start_date']) ? date('Y-m-d 00:00:00', 0) : sanitize_text_field($_POST['start_date']). ' 00:00:00';
|
24 |
-
|
25 |
-
$wpdb->hide_errors();
|
26 |
-
@set_time_limit(0);
|
27 |
-
if (function_exists('apache_setenv'))
|
28 |
-
@apache_setenv('no-gzip', 1);
|
29 |
-
@ini_set('zlib.output_compression', 0);
|
30 |
-
@ob_end_clean();
|
31 |
-
|
32 |
-
header('Content-Type: text/csv; charset=UTF-8');
|
33 |
-
header('Content-Disposition: attachment; filename=woocommerce-order-export.csv');
|
34 |
-
header('Pragma: no-cache');
|
35 |
-
header('Expires: 0');
|
36 |
-
|
37 |
-
$fp = fopen('php://output', 'w');
|
38 |
-
|
39 |
-
// Headers
|
40 |
-
|
41 |
-
$query_args = array(
|
42 |
-
'fields' => 'ids',
|
43 |
-
'post_type' => 'shop_order',
|
44 |
-
'post_status' => $export_order_statuses,
|
45 |
-
'posts_per_page' => $limit,
|
46 |
-
'offset' => $export_offset,
|
47 |
-
'date_query' => array(
|
48 |
-
array(
|
49 |
-
'before' => $end_date,
|
50 |
-
'after' => $start_date,
|
51 |
-
'inclusive' => true,
|
52 |
-
),
|
53 |
-
),
|
54 |
-
|
55 |
-
);
|
56 |
-
|
57 |
-
$query = new WP_Query($query_args);
|
58 |
-
$order_ids = $query->posts;
|
59 |
-
|
60 |
-
// Variable to hold the CSV data we're exporting
|
61 |
-
$row = array();
|
62 |
-
// Export header rows
|
63 |
-
foreach ($csv_columns as $column => $value) {
|
64 |
-
$temp_head = esc_attr( $user_columns_name[$column] );
|
65 |
-
if ( ! $export_columns || in_array( $column, $export_columns ) )
|
66 |
-
$row[] = $temp_head;
|
67 |
-
}
|
68 |
-
$max_line_items = WF_OrderImpExpCsv_Exporter::get_max_line_items($order_ids);
|
69 |
-
for ($i = 1; $i <= $max_line_items; $i++) {
|
70 |
-
$row[] = "line_item_{$i}";
|
71 |
-
}
|
72 |
-
|
73 |
-
$row = array_map('WF_OrderImpExpCsv_Exporter::wrap_column', $row);
|
74 |
-
fwrite($fp, implode($delimiter, $row) . "\n");
|
75 |
-
unset($row);
|
76 |
-
// Loop orders
|
77 |
-
foreach ($order_ids as $order_id) {
|
78 |
-
//$row = array();
|
79 |
-
$data = WF_OrderImpExpCsv_Exporter::get_orders_csv_row($order_id , $export_columns);
|
80 |
-
// Add to csv
|
81 |
-
$row = array_map('WF_OrderImpExpCsv_Exporter::wrap_column', $data);
|
82 |
-
fwrite($fp, implode($delimiter, $row) . "\n");
|
83 |
-
unset($row);
|
84 |
-
unset($data);
|
85 |
-
}
|
86 |
-
fclose($fp);
|
87 |
-
exit;
|
88 |
-
}
|
89 |
-
|
90 |
-
public static function format_data($data) {
|
91 |
-
if (!is_array($data))
|
92 |
-
;
|
93 |
-
$data = (string) urldecode($data);
|
94 |
-
$enc = mb_detect_encoding($data, 'UTF-8, ISO-8859-1', true);
|
95 |
-
$data = ( $enc == 'UTF-8' ) ? $data : utf8_encode($data);
|
96 |
-
return $data;
|
97 |
-
}
|
98 |
-
|
99 |
-
/**
|
100 |
-
* Wrap a column in quotes for the CSV
|
101 |
-
* @param string data to wrap
|
102 |
-
* @return string wrapped data
|
103 |
-
*/
|
104 |
-
public static function wrap_column($data) {
|
105 |
-
return '"' . str_replace('"', '""', $data) . '"';
|
106 |
-
}
|
107 |
-
|
108 |
-
public static function get_max_line_items($order_ids) {
|
109 |
-
$max_line_items = 0;
|
110 |
-
foreach ($order_ids as $order_id) {
|
111 |
-
$order = wc_get_order($order_id);
|
112 |
-
$line_items_count = count($order->get_items());
|
113 |
-
if ($line_items_count >= $max_line_items) {
|
114 |
-
$max_line_items = $line_items_count;
|
115 |
-
}
|
116 |
-
}
|
117 |
-
return $max_line_items;
|
118 |
-
}
|
119 |
-
|
120 |
-
public static function get_orders_csv_row($order_id , $export_columns) {
|
121 |
-
$order = wc_get_order($order_id);
|
122 |
-
$line_items = $shipping_items = $fee_items = $tax_items = $coupon_items = $refund_items = array();
|
123 |
-
|
124 |
-
// get line items
|
125 |
-
foreach ($order->get_items() as $item_id => $item) {
|
126 |
-
$product = (WC()->version < '4.4.0') ? $order->get_product_from_item($item) : $item->get_product(); // get_product_from_item() deprecated since version 4.4.0
|
127 |
-
if (!is_object($product)) {
|
128 |
-
$product = new WC_Product(0);
|
129 |
-
}
|
130 |
-
|
131 |
-
$line_item = array(
|
132 |
-
'name' => html_entity_decode($product->get_title() ? $product->get_title() : $item['name'], ENT_NOQUOTES, 'UTF-8'),
|
133 |
-
'product_id' => (WC()->version < '2.7.0')?$product->id:$product->get_id(),
|
134 |
-
'sku' => $product->get_sku(),
|
135 |
-
'quantity' => $item['qty'],
|
136 |
-
'total' => wc_format_decimal($order->get_line_total($item), 2),
|
137 |
-
'sub_total' => wc_format_decimal($order->get_line_subtotal($item), 2),
|
138 |
-
);
|
139 |
-
|
140 |
-
// add line item tax
|
141 |
-
$line_tax_data = isset($item['line_tax_data']) ? $item['line_tax_data'] : array();
|
142 |
-
$tax_data = maybe_unserialize($line_tax_data);
|
143 |
-
|
144 |
-
$line_item['tax'] = isset($tax_data['total']) ? wc_format_decimal(wc_round_tax_total(array_sum((array) $tax_data['total'])), 2) : '';
|
145 |
-
$line_tax_ser = maybe_serialize($line_tax_data);
|
146 |
-
if(isset($line_tax_data['total'])){
|
147 |
-
foreach ($line_tax_data['total'] as $rate_key => $rate_value) {
|
148 |
-
$tdata = WC_Tax::get_rate_label($rate_key);
|
149 |
-
$line_tax_total_data[] = $tdata."=".$rate_value;
|
150 |
-
}
|
151 |
-
}
|
152 |
-
if(!empty($line_tax_total_data)){
|
153 |
-
$line_tax_totat = implode(",", $line_tax_total_data);
|
154 |
-
$line_item['tax_total'] = !empty($line_tax_totat)?$line_tax_totat:'';
|
155 |
-
}
|
156 |
-
|
157 |
-
foreach ($line_tax_data['subtotal'] as $srate_key => $srate_value) {
|
158 |
-
$stdata = WC_Tax::get_rate_label($srate_key);
|
159 |
-
$line_tax_subtotal_data[] = $stdata."=".$srate_value;
|
160 |
-
}
|
161 |
-
if(!empty($line_tax_subtotal_data)){
|
162 |
-
$line_tax_subtotat = implode(",", $line_tax_subtotal_data);
|
163 |
-
$line_item['tax_subtotal'] = !empty($line_tax_subtotat)?$line_tax_subtotat:'';
|
164 |
-
}
|
165 |
-
// $line_item['tax_data'] = $line_tax_ser;
|
166 |
-
$line_items[] = $line_item;
|
167 |
-
}
|
168 |
-
|
169 |
-
$line_items_shipping = $order->get_items('shipping');
|
170 |
-
|
171 |
-
foreach ($line_items_shipping as $item_id => $item) {
|
172 |
-
$item_meta = self::get_order_line_item_meta($item_id);
|
173 |
-
foreach ($item_meta as $key => $value) {
|
174 |
-
switch ($key){
|
175 |
-
case 'Items':
|
176 |
-
case 'method_id':
|
177 |
-
case 'taxes':
|
178 |
-
if(is_object($value))
|
179 |
-
$value = $value->meta_value;
|
180 |
-
if (is_array($value))
|
181 |
-
$value = implode(',', $value);
|
182 |
-
$meta[$key] = $value;
|
183 |
-
break;
|
184 |
-
|
185 |
-
}
|
186 |
-
}
|
187 |
-
foreach (array('Items','method_id','taxes') as $value){
|
188 |
-
if(!isset($meta[$value])){
|
189 |
-
$meta[$value] = '';
|
190 |
-
}
|
191 |
-
}
|
192 |
-
$shipping_items[] = trim(implode('|', array('items:' .$meta['Items'], 'method_id:' .$meta['method_id'], 'taxes:' .$meta['taxes'])));
|
193 |
-
}
|
194 |
-
|
195 |
-
// get fee items & total
|
196 |
-
$fee_total = 0;
|
197 |
-
$fee_tax_total = 0;
|
198 |
-
|
199 |
-
foreach ($order->get_fees() as $fee_id => $fee) {
|
200 |
-
$fee_items[] = implode('|', array(
|
201 |
-
'name:' . html_entity_decode($fee['name'], ENT_NOQUOTES, 'UTF-8'),
|
202 |
-
'total:' . wc_format_decimal($fee['line_total'], 2),
|
203 |
-
'tax:' . wc_format_decimal($fee['line_tax'], 2),
|
204 |
-
));
|
205 |
-
$fee_total += $fee['line_total'];
|
206 |
-
$fee_tax_total += $fee['line_tax'];
|
207 |
-
}
|
208 |
-
add_filter('woocommerce_order_hide_zero_taxes','__return_false');
|
209 |
-
// get tax items
|
210 |
-
foreach ($order->get_tax_totals() as $tax_code => $tax) {
|
211 |
-
$tax_items[] = implode('|', array(
|
212 |
-
'rate_id:'.$tax->rate_id,
|
213 |
-
'code:' . $tax_code,
|
214 |
-
'total:' . wc_format_decimal($tax->amount, 2),
|
215 |
-
'label:'.$tax->label,
|
216 |
-
'tax_rate_compound:'.$tax->is_compound,
|
217 |
-
));
|
218 |
-
}
|
219 |
-
|
220 |
-
// add coupons
|
221 |
-
if ( (WC()->version < '4.4.0' ) ) {
|
222 |
-
foreach ( $order->get_items('coupon') as $_ => $coupon_item ) {
|
223 |
-
$discount_amount = !empty( $coupon_item[ 'discount_amount' ] ) ? $coupon_item[ 'discount_amount' ] : 0;
|
224 |
-
$coupon_items[] = implode( '|', array(
|
225 |
-
'code:' . $coupon_item[ 'name' ],
|
226 |
-
'amount:' . wc_format_decimal( $discount_amount, 2 ),
|
227 |
-
) );
|
228 |
-
}
|
229 |
-
} else {
|
230 |
-
foreach ( $order->get_coupon_codes() as $_ => $coupon_code ) {
|
231 |
-
$coupon_obj = new WC_Coupon($coupon_code);
|
232 |
-
$discount_amount = !empty( $coupon_obj->get_amount() ) ? $coupon_obj->get_amount() : 0;
|
233 |
-
$coupon_items[] = implode( '|', array(
|
234 |
-
'code:' . $coupon_code,
|
235 |
-
'amount:' . wc_format_decimal( $discount_amount, 2 ),
|
236 |
-
) );
|
237 |
-
}
|
238 |
-
}
|
239 |
-
|
240 |
-
foreach ($order->get_refunds() as $refunded_items){
|
241 |
-
|
242 |
-
if ((WC()->version < '2.7.0')) {
|
243 |
-
$refund_items[] = implode('|', array(
|
244 |
-
'amount:' . $refunded_items->get_refund_amount(),
|
245 |
-
'reason:' . $refunded_items->reason,
|
246 |
-
'date:' . date('Y-m-d H:i:s', strtotime( $refunded_items->date_created )),
|
247 |
-
));
|
248 |
-
} else {
|
249 |
-
$refund_items[] = implode('|', array(
|
250 |
-
'amount:' . $refunded_items->get_amount(),
|
251 |
-
'reason:' . $refunded_items->get_reason(),
|
252 |
-
'date:' . date('Y-m-d H:i:s', strtotime( $refunded_items->get_date_created())),
|
253 |
-
));
|
254 |
-
}
|
255 |
-
|
256 |
-
}
|
257 |
-
|
258 |
-
if (version_compare(WC_VERSION, '2.7', '<')) {
|
259 |
-
$order_data = array(
|
260 |
-
'order_id' => $order->id,
|
261 |
-
'order_number' => $order->get_order_number(),
|
262 |
-
'order_date' => date('Y-m-d H:i:s', strtotime(get_post($order->id)->post_date)),
|
263 |
-
'status' => $order->get_status(),
|
264 |
-
'shipping_total' => $order->get_total_shipping(),
|
265 |
-
'shipping_tax_total' => wc_format_decimal($order->get_shipping_tax(), 2),
|
266 |
-
'fee_total' => wc_format_decimal($fee_total, 2),
|
267 |
-
'fee_tax_total' => wc_format_decimal($fee_tax_total, 2),
|
268 |
-
'tax_total' => wc_format_decimal($order->get_total_tax(), 2),
|
269 |
-
'cart_discount' => (defined( 'WC_VERSION' ) && (WC_VERSION >= 2.3)) ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_cart_discount(), 2),
|
270 |
-
'order_discount' => (defined( 'WC_VERSION' ) && (WC_VERSION >= 2.3)) ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_order_discount(), 2),
|
271 |
-
'discount_total' => wc_format_decimal($order->get_total_discount(), 2),
|
272 |
-
'order_total' => wc_format_decimal($order->get_total(), 2),
|
273 |
-
// 'refunded_total' => wc_format_decimal($order->get_total_refunded(), 2),
|
274 |
-
'order_currency' => $order->get_order_currency(),
|
275 |
-
'payment_method' => $order->payment_method,
|
276 |
-
'shipping_method' => $order->get_shipping_method(),
|
277 |
-
'customer_id' => $order->get_user_id(),
|
278 |
-
'customer_user' => $order->get_user_id(),
|
279 |
-
'customer_email' => ($a = get_userdata($order->get_user_id() )) ? $a->user_email : '',
|
280 |
-
'billing_first_name' => $order->billing_first_name,
|
281 |
-
'billing_last_name' => $order->billing_last_name,
|
282 |
-
'billing_company' => $order->billing_company,
|
283 |
-
'billing_email' => $order->billing_email,
|
284 |
-
'billing_phone' => $order->billing_phone,
|
285 |
-
'billing_address_1' => $order->billing_address_1,
|
286 |
-
'billing_address_2' => $order->billing_address_2,
|
287 |
-
'billing_postcode' => $order->billing_postcode,
|
288 |
-
'billing_city' => $order->billing_city,
|
289 |
-
'billing_state' => $order->billing_state,
|
290 |
-
'billing_country' => $order->billing_country,
|
291 |
-
'shipping_first_name' => $order->shipping_first_name,
|
292 |
-
'shipping_last_name' => $order->shipping_last_name,
|
293 |
-
'shipping_company' => $order->shipping_company,
|
294 |
-
'shipping_address_1' => $order->shipping_address_1,
|
295 |
-
'shipping_address_2' => $order->shipping_address_2,
|
296 |
-
'shipping_postcode' => $order->shipping_postcode,
|
297 |
-
'shipping_city' => $order->shipping_city,
|
298 |
-
'shipping_state' => $order->shipping_state,
|
299 |
-
'shipping_country' => $order->shipping_country,
|
300 |
-
'customer_note' => $order->customer_note,
|
301 |
-
'shipping_items' => implode(';', $shipping_items),
|
302 |
-
'fee_items' => implode(';', $fee_items),
|
303 |
-
'tax_items' => implode(';', $tax_items),
|
304 |
-
'coupon_items' => implode(';', $coupon_items),
|
305 |
-
'refund_items' => implode(';', $refund_items),
|
306 |
-
'order_notes' => implode('||', WF_OrderImpExpCsv_Exporter::get_order_notes($order)),
|
307 |
-
'download_permissions' => $order->download_permissions_granted ? $order->download_permissions_granted : 0,
|
308 |
-
);
|
309 |
-
}else{
|
310 |
-
$order_data = array(
|
311 |
-
'order_id' => $order->get_id(),
|
312 |
-
'order_number' => $order->get_order_number(),
|
313 |
-
'order_date' => date('Y-m-d H:i:s', strtotime(get_post($order->get_id())->post_date)),
|
314 |
-
'status' => $order->get_status(),
|
315 |
-
'shipping_total' => $order->get_total_shipping(),
|
316 |
-
'shipping_tax_total' => wc_format_decimal($order->get_shipping_tax(), 2),
|
317 |
-
'fee_total' => wc_format_decimal($fee_total, 2),
|
318 |
-
'fee_tax_total' => wc_format_decimal($fee_tax_total, 2),
|
319 |
-
'tax_total' => wc_format_decimal($order->get_total_tax(), 2),
|
320 |
-
'cart_discount' => (defined('WC_VERSION') && (WC_VERSION >= 2.3)) ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_cart_discount(), 2),
|
321 |
-
'order_discount' => (defined('WC_VERSION') && (WC_VERSION >= 2.3)) ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_order_discount(), 2),
|
322 |
-
'discount_total' => wc_format_decimal($order->get_total_discount(), 2),
|
323 |
-
'order_total' => @wc_format_decimal($order->get_total(), 2),
|
324 |
-
// 'refunded_total' => wc_format_decimal($order->get_total_refunded(), 2),
|
325 |
-
'order_currency' => $order->get_currency(),
|
326 |
-
'payment_method' => $order->get_payment_method(),
|
327 |
-
'shipping_method' => $order->get_shipping_method(),
|
328 |
-
'customer_id' => $order->get_user_id(),
|
329 |
-
'customer_user' => $order->get_user_id(),
|
330 |
-
'customer_email' => ($a = get_userdata($order->get_user_id() )) ? $a->user_email : '',
|
331 |
-
'billing_first_name' => $order->get_billing_first_name(),
|
332 |
-
'billing_last_name' => $order->get_billing_last_name(),
|
333 |
-
'billing_company' => $order->get_billing_company(),
|
334 |
-
'billing_email' => $order->get_billing_email(),
|
335 |
-
'billing_phone' => $order->get_billing_phone(),
|
336 |
-
'billing_address_1' => $order->get_billing_address_1(),
|
337 |
-
'billing_address_2' => $order->get_billing_address_2(),
|
338 |
-
'billing_postcode' => $order->get_billing_postcode(),
|
339 |
-
'billing_city' => $order->get_billing_city(),
|
340 |
-
'billing_state' => $order->get_billing_state(),
|
341 |
-
'billing_country' => $order->get_billing_country(),
|
342 |
-
'shipping_first_name' => $order->get_shipping_first_name(),
|
343 |
-
'shipping_last_name' => $order->get_shipping_last_name(),
|
344 |
-
'shipping_company' => $order->get_shipping_company(),
|
345 |
-
'shipping_address_1' => $order->get_shipping_address_1(),
|
346 |
-
'shipping_address_2' => $order->get_shipping_address_2(),
|
347 |
-
'shipping_postcode' => $order->get_shipping_postcode(),
|
348 |
-
'shipping_city' => $order->get_shipping_city(),
|
349 |
-
'shipping_state' => $order->get_shipping_state(),
|
350 |
-
'shipping_country' => $order->get_shipping_country(),
|
351 |
-
'customer_note' => $order->get_customer_note(),
|
352 |
-
'shipping_items' => implode(';', $shipping_items),
|
353 |
-
'fee_items' => implode(';', $fee_items),
|
354 |
-
'tax_items' => implode(';', $tax_items),
|
355 |
-
'coupon_items' => implode(';', $coupon_items),
|
356 |
-
'refund_items' => implode(';', $refund_items),
|
357 |
-
'order_notes' => implode('||', (defined('WC_VERSION') && (WC_VERSION >= 3.2)) ? WF_OrderImpExpCsv_Exporter::get_order_notes_new($order) : WF_OrderImpExpCsv_Exporter::get_order_notes($order)),
|
358 |
-
'download_permissions' => $order->is_download_permitted() ? $order->is_download_permitted() : 0,
|
359 |
-
'customer_ip_address' => $order->get_customer_ip_address() ? $order->get_customer_ip_address() : '',
|
360 |
-
'paid_date' => '',
|
361 |
-
'completed_date' => '',
|
362 |
-
);
|
363 |
-
if($order->get_date_paid()){
|
364 |
-
$paid_date = $order->get_date_paid();
|
365 |
-
$paid_date_timestamp = strtotime($paid_date);
|
366 |
-
$formatted_paid_date = date('Y-m-d H:i:s', $paid_date_timestamp);
|
367 |
-
$order_data['paid_date'] = $formatted_paid_date ;
|
368 |
-
|
369 |
-
}
|
370 |
-
if($order->get_date_completed()){
|
371 |
-
$date_completed = $order->get_date_completed();
|
372 |
-
$date_completed_timestamp = strtotime($date_completed);
|
373 |
-
$formatted_date_completed = date('Y-m-d H:i:s', $date_completed_timestamp);
|
374 |
-
$order_data['completed_date'] = $formatted_date_completed ;
|
375 |
-
|
376 |
-
}
|
377 |
-
}
|
378 |
-
foreach ($order_data as $key => $value) {
|
379 |
-
if (!$export_columns || in_array( $key, $export_columns ) ){
|
380 |
-
// need to modify code
|
381 |
-
}else{
|
382 |
-
unset($order_data[$key]);
|
383 |
-
}
|
384 |
-
}
|
385 |
-
$li = 1;
|
386 |
-
foreach ($line_items as $line_item) {
|
387 |
-
foreach ($line_item as $name => $value) {
|
388 |
-
$line_item[$name] = $name . ':' . $value;
|
389 |
-
}
|
390 |
-
$line_item = implode('|', $line_item);
|
391 |
-
$order_data["line_item_{$li}"] = $line_item;
|
392 |
-
$li++;
|
393 |
-
}
|
394 |
-
return $order_data;
|
395 |
-
}
|
396 |
-
|
397 |
-
public static function get_order_notes($order) {
|
398 |
-
$callback = array('WC_Comments', 'exclude_order_comments');
|
399 |
-
$args = array(
|
400 |
-
'post_id' => (WC()->version < '2.7.0')?$order->id:$order->get_id(),
|
401 |
-
'approve' => 'approve',
|
402 |
-
'type' => 'order_note'
|
403 |
-
);
|
404 |
-
|
405 |
-
remove_filter('comments_clauses', $callback);
|
406 |
-
$notes = get_comments($args);
|
407 |
-
add_filter('comments_clauses', $callback);
|
408 |
-
$notes = array_reverse($notes);
|
409 |
-
$order_notes = array();
|
410 |
-
foreach ($notes as $note) {
|
411 |
-
$date = $note->comment_date;
|
412 |
-
$customer_note = 0;
|
413 |
-
if (get_comment_meta($note->comment_ID, 'is_customer_note', '1')){
|
414 |
-
$customer_note = 1;
|
415 |
-
}
|
416 |
-
$order_notes[] = implode('|', array(
|
417 |
-
'content:' .str_replace(array("\r", "\n"), ' ', $note->comment_content),
|
418 |
-
'date:'.(!empty($date) ? $date : current_time( 'mysql' )),
|
419 |
-
'customer:'.$customer_note,
|
420 |
-
'added_by:'.$note->added_by
|
421 |
-
));
|
422 |
-
}
|
423 |
-
return $order_notes;
|
424 |
-
}
|
425 |
-
|
426 |
-
public static function get_order_notes_new($order) {
|
427 |
-
$notes = wc_get_order_notes(array('order_id' => $order->get_id(),'order_by' => 'date_created','order' => 'ASC'));
|
428 |
-
$order_notes = array();
|
429 |
-
foreach ($notes as $note) {
|
430 |
-
$order_notes[] = implode('|', array(
|
431 |
-
'content:' .str_replace(array("\r", "\n"), ' ', $note->content),
|
432 |
-
'date:'.$note->date_created->date('Y-m-d H:i:s'),
|
433 |
-
'customer:'.$note->customer_note,
|
434 |
-
'added_by:'.$note->added_by
|
435 |
-
));
|
436 |
-
}
|
437 |
-
return $order_notes;
|
438 |
-
}
|
439 |
-
|
440 |
-
public static function get_order_line_item_meta($item_id){
|
441 |
-
global $wpdb;
|
442 |
-
$filtered_meta = apply_filters('wt_order_export_select_line_item_meta',array());
|
443 |
-
$filtered_meta = !empty($filtered_meta) ? implode("','",$filtered_meta) : '';
|
444 |
-
$query = "SELECT meta_key,meta_value
|
445 |
-
FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE order_item_id = '$item_id'";
|
446 |
-
if(!empty($filtered_meta)){
|
447 |
-
$query .= " AND meta_key IN ('".$filtered_meta."')";
|
448 |
-
}
|
449 |
-
$meta_keys = $wpdb->get_results($query , OBJECT_K );
|
450 |
-
return $meta_keys;
|
451 |
-
}
|
452 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/importer/class-wf-cpnimpexpcsv-coupon-import.php
DELETED
@@ -1,688 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WordPress Importer class for managing the import process of a CSV file
|
4 |
-
*
|
5 |
-
* @package WordPress
|
6 |
-
* @subpackage Importer
|
7 |
-
*/
|
8 |
-
if ( ! class_exists( 'WP_Importer' ) )
|
9 |
-
return;
|
10 |
-
|
11 |
-
class WF_CpnImpExpCsv_Coupon_Import extends WP_Importer {
|
12 |
-
|
13 |
-
var $id;
|
14 |
-
var $file_url;
|
15 |
-
var $delimiter;
|
16 |
-
// var $merge_empty_cells;
|
17 |
-
// mappings from old information to new
|
18 |
-
var $processed_posts = array();
|
19 |
-
// Results
|
20 |
-
var $import_results = array();
|
21 |
-
|
22 |
-
/**
|
23 |
-
* Constructor
|
24 |
-
*/
|
25 |
-
public function __construct() {
|
26 |
-
if (WC()->version < '2.7.0') {
|
27 |
-
$this->log = new WC_Logger();
|
28 |
-
} else {
|
29 |
-
$this->log = wc_get_logger();
|
30 |
-
}
|
31 |
-
$this->import_page = 'coupon_csv';
|
32 |
-
$this->file_url_import_enabled = apply_filters( 'coupon_csv_coupon_file_url_import_enabled', true );
|
33 |
-
}
|
34 |
-
|
35 |
-
/**
|
36 |
-
* Registered callback function for the WordPress Importer
|
37 |
-
*
|
38 |
-
* Manages the three separate stages of the CSV import process
|
39 |
-
*/
|
40 |
-
public function dispatch() {
|
41 |
-
global $woocommerce, $wpdb;
|
42 |
-
if ( ! empty( $_POST['delimiter'] ) ) {
|
43 |
-
$this->delimiter = stripslashes( trim( $_POST['delimiter'] ) );
|
44 |
-
}else if ( ! empty( $_GET['delimiter'] ) ) {
|
45 |
-
$this->delimiter = stripslashes( trim( $_GET['delimiter'] ) );
|
46 |
-
}
|
47 |
-
if ( ! $this->delimiter )
|
48 |
-
$this->delimiter = ',';
|
49 |
-
// if ( ! empty( $_POST['merge_empty_cells'] ) || ! empty( $_GET['merge_empty_cells'] ) ) {
|
50 |
-
// $this->merge_empty_cells = 1;
|
51 |
-
// } else{
|
52 |
-
// $this->merge_empty_cells = 0;
|
53 |
-
// }
|
54 |
-
$step = empty( $_GET['step'] ) ? 0 : absint($_GET['step']);
|
55 |
-
switch ( $step ) {
|
56 |
-
case 0 :
|
57 |
-
$this->header();
|
58 |
-
$this->greet();
|
59 |
-
break;
|
60 |
-
case 1 :
|
61 |
-
$this->header();
|
62 |
-
check_admin_referer( 'import-upload' );
|
63 |
-
if(!empty($_GET['file_url']))
|
64 |
-
$this->file_url = esc_url_raw( $_GET['file_url'] );
|
65 |
-
if(!empty($_GET['file_id']))
|
66 |
-
$this->id = absint($_GET['file_id']) ;
|
67 |
-
if ( !empty($_GET['clearmapping']) || $this->handle_upload() )
|
68 |
-
$this->import_options();
|
69 |
-
else
|
70 |
-
//_e( 'Error with handle_upload!', 'order-import-export-for-woocommerce' );
|
71 |
-
wp_redirect(wp_get_referer().'&wf_coupon_ie_msg=3');
|
72 |
-
exit;
|
73 |
-
break;
|
74 |
-
case 2 :
|
75 |
-
$this->header();
|
76 |
-
check_admin_referer( 'import-woocommerce' );
|
77 |
-
$this->id = absint($_POST['import_id']);
|
78 |
-
if ( $this->file_url_import_enabled )
|
79 |
-
$this->file_url = esc_url_raw( $_POST['import_url'] );
|
80 |
-
if ( $this->id )
|
81 |
-
$file = get_attached_file( $this->id );
|
82 |
-
else if ( $this->file_url_import_enabled )
|
83 |
-
$file = ABSPATH . $this->file_url;
|
84 |
-
$file = str_replace( "\\", "/", $file );
|
85 |
-
if ( $file ) {
|
86 |
-
$file_delimiter = $this->detectDelimiter($file);
|
87 |
-
if(!empty($file_delimiter) && ($file_delimiter != $this->delimiter)){
|
88 |
-
echo '<p class="error"><strong>' . __("Basic version supports only ',' as delimiter. Your file's delimiter seems to be unsupported.", 'users-customers-import-export-for-wp-woocommerce') . '</strong></p>';
|
89 |
-
break;
|
90 |
-
}
|
91 |
-
?>
|
92 |
-
<table id="import-progress" class="widefat_importer widefat">
|
93 |
-
<thead>
|
94 |
-
<tr>
|
95 |
-
<th class="status"> </th>
|
96 |
-
<th class="row"><?php _e( 'Row', 'order-import-export-for-woocommerce' ); ?></th>
|
97 |
-
<th><?php _e( 'Coupon Id', 'order-import-export-for-woocommerce' ); ?></th>
|
98 |
-
<th><?php _e( 'Coupon Name', 'order-import-export-for-woocommerce' ); ?></th>
|
99 |
-
<th class="reason"><?php _e( 'Status Msg', 'order-import-export-for-woocommerce' ); ?></th>
|
100 |
-
</tr>
|
101 |
-
</thead>
|
102 |
-
<tfoot>
|
103 |
-
<tr class="importer-loading">
|
104 |
-
<td colspan="5"></td>
|
105 |
-
</tr>
|
106 |
-
</tfoot>
|
107 |
-
<tbody></tbody>
|
108 |
-
</table>
|
109 |
-
<script type="text/javascript">
|
110 |
-
jQuery(document).ready(function($) {
|
111 |
-
if ( ! window.console ) { window.console = function(){}; }
|
112 |
-
var processed_posts = [];
|
113 |
-
var i = 1;
|
114 |
-
var done_count = 0;
|
115 |
-
function import_rows( start_pos, end_pos ) {
|
116 |
-
var data = {
|
117 |
-
action: 'coupon_csv_import_request',
|
118 |
-
file: '<?php echo addslashes( $file ); ?>',
|
119 |
-
delimiter: '<?php echo $this->delimiter; ?>',
|
120 |
-
//merge_empty_cells: '<?php //echo $this->merge_empty_cells; ?>',
|
121 |
-
start_pos: start_pos,
|
122 |
-
end_pos: end_pos,
|
123 |
-
wt_nonce : '<?php echo wp_create_nonce( WF_CPN_IMP_EXP_ID )?>',
|
124 |
-
};
|
125 |
-
return $.ajax({
|
126 |
-
url: '<?php echo add_query_arg( array( 'import_page' => $this->import_page, 'step' => '3', 'merge' => ! empty( $_GET['merge'] ) ? '1' : '0' ), admin_url( 'admin-ajax.php' ) ); ?>',
|
127 |
-
data: data,
|
128 |
-
type: 'POST',
|
129 |
-
success: function( response ) {
|
130 |
-
if ( response ) {
|
131 |
-
try {
|
132 |
-
// Get the valid JSON only from the returned string
|
133 |
-
if ( response.indexOf("<!--WC_START-->") >= 0 )
|
134 |
-
response = response.split("<!--WC_START-->")[1]; // Strip off before after WC_START
|
135 |
-
if ( response.indexOf("<!--WC_END-->") >= 0 )
|
136 |
-
response = response.split("<!--WC_END-->")[0]; // Strip off anything after WC_END
|
137 |
-
// Parse
|
138 |
-
var results = $.parseJSON( response );
|
139 |
-
if ( results.error ) {
|
140 |
-
$('#import-progress tbody').append( '<tr id="row-' + i + '" class="error"><td class="status" colspan="5">' + results.error + '</td></tr>' );
|
141 |
-
i++;
|
142 |
-
} else if ( results.import_results && $( results.import_results ).size() > 0 ) {
|
143 |
-
$.each( results.processed_posts, function( index, value ) {
|
144 |
-
processed_posts.push( value );
|
145 |
-
});
|
146 |
-
$( results.import_results ).each(function( index, row ) {
|
147 |
-
$('#import-progress tbody').append( '<tr id="row-' + i + '" class="' + row['status'] + '"><td><mark class="result" title="' + row['status'] + '">' + row['status'] + '</mark></td><td class="row">' + i + '</td><td>' + row['post_id'] + '</td><td>' + row['post_title'] + '</td><td class="reason">' + row['reason'] + '</td></tr>' );
|
148 |
-
i++;
|
149 |
-
});
|
150 |
-
}
|
151 |
-
} catch(err) {}
|
152 |
-
} else {
|
153 |
-
$('#import-progress tbody').append( '<tr class="error"><td class="status" colspan="5">' + '<?php _e( 'AJAX Error', 'order-import-export-for-woocommerce' ); ?>' + '</td></tr>' );
|
154 |
-
}
|
155 |
-
var w = $(window);
|
156 |
-
var row = $( "#row-" + ( i - 1 ) );
|
157 |
-
if ( row.length ) {
|
158 |
-
w.scrollTop( row.offset().top - (w.height()/2) );
|
159 |
-
}
|
160 |
-
done_count++;
|
161 |
-
$('body').trigger( 'coupon_csv_import_request_complete' );
|
162 |
-
}
|
163 |
-
});
|
164 |
-
}
|
165 |
-
var rows = [];
|
166 |
-
|
167 |
-
<?php
|
168 |
-
$limit = apply_filters( 'coupon_csv_import_limit_per_request', 10 );
|
169 |
-
$enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
|
170 |
-
if ( $enc )
|
171 |
-
setlocale( LC_ALL, 'en_US.' . $enc );
|
172 |
-
@ini_set( 'auto_detect_line_endings', true );
|
173 |
-
|
174 |
-
$count = 0;
|
175 |
-
$previous_position = 0;
|
176 |
-
$position = 0;
|
177 |
-
$import_count = 0;
|
178 |
-
|
179 |
-
// Get CSV positions
|
180 |
-
if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
|
181 |
-
while ( ( $postmeta = fgetcsv( $handle, 0, $this->delimiter) ) !== FALSE ) {
|
182 |
-
$count++;
|
183 |
-
if ( $count >= $limit ) {
|
184 |
-
$previous_position = $position;
|
185 |
-
$position = ftell( $handle );
|
186 |
-
$count = 0;
|
187 |
-
$import_count ++;
|
188 |
-
// Import rows between $previous_position $position
|
189 |
-
?>rows.push( [ <?php echo $previous_position; ?>, <?php echo $position; ?> ] ); <?php
|
190 |
-
}
|
191 |
-
}
|
192 |
-
// Remainder
|
193 |
-
if ( $count > 0 ) {
|
194 |
-
?>rows.push( [ <?php echo $position; ?>, '' ] ); <?php
|
195 |
-
$import_count ++;
|
196 |
-
}
|
197 |
-
fclose( $handle );
|
198 |
-
}
|
199 |
-
?>
|
200 |
-
|
201 |
-
var data = rows.shift();
|
202 |
-
var regen_count = 0;
|
203 |
-
import_rows( data[0], data[1] );
|
204 |
-
$('body').on( 'coupon_csv_import_request_complete', function() {
|
205 |
-
if ( done_count == <?php echo $import_count; ?> ) {
|
206 |
-
import_done();
|
207 |
-
} else {
|
208 |
-
// Call next request
|
209 |
-
data = rows.shift();
|
210 |
-
import_rows( data[0], data[1] );
|
211 |
-
}
|
212 |
-
});
|
213 |
-
function import_done() {
|
214 |
-
var data = {
|
215 |
-
action: 'coupon_csv_import_request',
|
216 |
-
file: '<?php echo $file; ?>',
|
217 |
-
processed_posts: processed_posts,
|
218 |
-
wt_nonce : '<?php echo wp_create_nonce( WF_CPN_IMP_EXP_ID )?>',
|
219 |
-
};
|
220 |
-
|
221 |
-
$.ajax({
|
222 |
-
url: '<?php echo add_query_arg( array( 'import_page' => $this->import_page, 'step' => '4', 'merge' => ! empty( $_GET['merge'] ) ? 1 : 0 ), admin_url( 'admin-ajax.php' ) ); ?>',
|
223 |
-
data: data,
|
224 |
-
type: 'POST',
|
225 |
-
success: function( response ) {
|
226 |
-
//console.log( response );
|
227 |
-
$('#import-progress tbody').append( '<tr class="complete"><td colspan="5">' + response + '</td></tr>' );
|
228 |
-
$('.importer-loading').hide();
|
229 |
-
}
|
230 |
-
});
|
231 |
-
}
|
232 |
-
});
|
233 |
-
</script>
|
234 |
-
<?php
|
235 |
-
} else {
|
236 |
-
echo '<p class="error">' . __( 'Error finding uploaded file!', 'order-import-export-for-woocommerce' ) . '</p>';
|
237 |
-
}
|
238 |
-
break;
|
239 |
-
case 3 :
|
240 |
-
$nonce = (isset($_POST['wt_nonce']) ? sanitize_text_field($_POST['wt_nonce']) : '');
|
241 |
-
if (!wp_verify_nonce($nonce, WF_CPN_IMP_EXP_ID) || !WF_Coupon_Import_Export_CSV::hf_user_permission()) {
|
242 |
-
wp_die(__('Access Denied', 'order-import-export-for-woocommerce'));
|
243 |
-
}
|
244 |
-
$file = stripslashes( $_POST['file'] );
|
245 |
-
if (filter_var($file, FILTER_VALIDATE_URL)){ // Validating given path is valid path, not a URL
|
246 |
-
die();
|
247 |
-
}
|
248 |
-
add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
|
249 |
-
if ( function_exists( 'gc_enable' ) )
|
250 |
-
gc_enable();
|
251 |
-
@set_time_limit(0);
|
252 |
-
@ob_flush();
|
253 |
-
@flush();
|
254 |
-
$wpdb->hide_errors();
|
255 |
-
$start_pos = isset( $_POST['start_pos'] ) ? absint( $_POST['start_pos'] ) : 0;
|
256 |
-
$end_pos = isset( $_POST['end_pos'] ) ? absint( $_POST['end_pos'] ) : '';
|
257 |
-
$position = $this->import_start( $file, $start_pos, $end_pos );
|
258 |
-
$this->import();
|
259 |
-
$this->import_end();
|
260 |
-
|
261 |
-
$results = array();
|
262 |
-
$results['import_results'] = $this->import_results;
|
263 |
-
$results['processed_posts'] = $this->processed_posts;
|
264 |
-
|
265 |
-
echo "<!--WC_START-->";
|
266 |
-
echo json_encode( $results );
|
267 |
-
echo "<!--WC_END-->";
|
268 |
-
exit;
|
269 |
-
break;
|
270 |
-
case 4 :
|
271 |
-
$nonce = (isset($_POST['wt_nonce']) ? sanitize_text_field($_POST['wt_nonce']) : '');
|
272 |
-
if (!wp_verify_nonce($nonce, WF_CPN_IMP_EXP_ID) || !WF_Coupon_Import_Export_CSV::hf_user_permission()) {
|
273 |
-
wp_die(__('Access Denied', 'order-import-export-for-woocommerce'));
|
274 |
-
}
|
275 |
-
add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
|
276 |
-
|
277 |
-
if ( function_exists( 'gc_enable' ) )
|
278 |
-
gc_enable();
|
279 |
-
|
280 |
-
@set_time_limit(0);
|
281 |
-
@ob_flush();
|
282 |
-
@flush();
|
283 |
-
$wpdb->hide_errors();
|
284 |
-
|
285 |
-
$this->processed_posts = isset( $_POST['processed_posts']) ? array_map('intval', $_POST['processed_posts']) : array();
|
286 |
-
$file = isset($_POST['file']) ? stripslashes($_POST['file']) : '';
|
287 |
-
|
288 |
-
_e( 'Step 1...', 'order-import-export-for-woocommerce' ) . ' ';
|
289 |
-
wp_defer_term_counting( true );
|
290 |
-
wp_defer_comment_counting( true );
|
291 |
-
_e( 'Step 2...', 'order-import-export-for-woocommerce' ) . ' ';
|
292 |
-
echo 'Step 3...' . ' '; // Easter egg
|
293 |
-
_e( 'Finalizing...', 'order-import-export-for-woocommerce' ) . ' ';
|
294 |
-
// SUCCESS
|
295 |
-
_e( 'Finished. Import complete.', 'order-import-export-for-woocommerce' );
|
296 |
-
if(in_array(pathinfo($file, PATHINFO_EXTENSION),array('txt','csv'))){
|
297 |
-
unlink($file);
|
298 |
-
}
|
299 |
-
$this->import_end();
|
300 |
-
exit;
|
301 |
-
break;
|
302 |
-
}
|
303 |
-
$this->footer();
|
304 |
-
}
|
305 |
-
|
306 |
-
/**
|
307 |
-
* format_data_from_csv
|
308 |
-
*/
|
309 |
-
public function format_data_from_csv( $data, $enc ) {
|
310 |
-
return ( $enc == 'UTF-8' ) ? $data : utf8_encode( $data );
|
311 |
-
}
|
312 |
-
|
313 |
-
/**
|
314 |
-
* Display pre-import options
|
315 |
-
*/
|
316 |
-
public function import_options(){
|
317 |
-
$j = 0;
|
318 |
-
if ( $this->id )
|
319 |
-
$file = get_attached_file( $this->id );
|
320 |
-
else if ( $this->file_url_import_enabled )
|
321 |
-
$file = ABSPATH . $this->file_url;
|
322 |
-
else
|
323 |
-
return;
|
324 |
-
// Set locale
|
325 |
-
$enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
|
326 |
-
if ( $enc ) setlocale( LC_ALL, 'en_US.' . $enc );
|
327 |
-
@ini_set( 'auto_detect_line_endings', true );
|
328 |
-
// Get headers
|
329 |
-
if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ){
|
330 |
-
$row = $raw_headers = array();
|
331 |
-
$header = fgetcsv( $handle, 0, $this->delimiter );
|
332 |
-
while ( ( $postmeta = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ){
|
333 |
-
foreach ( $header as $key => $heading ){
|
334 |
-
if ( ! $heading ) continue;
|
335 |
-
$s_heading = strtolower( $heading );
|
336 |
-
$row[$s_heading] = ( isset( $postmeta[$key] ) ) ? $this->format_data_from_csv( $postmeta[$key], $enc ) : '';
|
337 |
-
$raw_headers[ $s_heading ] = $heading;
|
338 |
-
}
|
339 |
-
break;
|
340 |
-
}
|
341 |
-
fclose( $handle );
|
342 |
-
}
|
343 |
-
$merge = (!empty($_GET['merge']) && $_GET['merge']) ? 1 : 0;
|
344 |
-
include( 'views-coupon/html-wf-import-options.php' );
|
345 |
-
}
|
346 |
-
|
347 |
-
/**
|
348 |
-
* The main controller for the actual import stage.
|
349 |
-
*/
|
350 |
-
public function import(){
|
351 |
-
wp_suspend_cache_invalidation( true );
|
352 |
-
$this->hf_coupon_log_data_change( 'coupon-csv-import', '---' );
|
353 |
-
$this->hf_coupon_log_data_change( 'coupon-csv-import', __( 'Processing coupons.', 'order-import-export-for-woocommerce' ) );
|
354 |
-
foreach ( $this->parsed_data as $key => &$item ){
|
355 |
-
//$coupon = $this->parser->parse_coupon( $item, $this->merge_empty_cells );
|
356 |
-
$coupon = $this->parser->parse_coupon( $item);
|
357 |
-
if ( ! is_wp_error( $coupon ) )
|
358 |
-
$this->process_coupon( $coupon);
|
359 |
-
else
|
360 |
-
$this->add_import_result( 'failed', $coupon->get_error_message(), 'Not parsed', json_encode( $item ) );
|
361 |
-
unset( $item, $coupon );
|
362 |
-
}
|
363 |
-
$this->hf_coupon_log_data_change( 'coupon-csv-import', __( 'Finished processing coupons.', 'order-import-export-for-woocommerce' ) );
|
364 |
-
wp_suspend_cache_invalidation( false );
|
365 |
-
}
|
366 |
-
|
367 |
-
/**
|
368 |
-
* Parses the CSV file and prepares us for the task of processing parsed data
|
369 |
-
*
|
370 |
-
* @param string $file Path to the CSV file for importing
|
371 |
-
*/
|
372 |
-
public function import_start( $file, $start_pos, $end_pos) {
|
373 |
-
$memory = size_format( (WC()->version < '2.7.0')?woocommerce_let_to_num( ini_get( 'memory_limit' ) ):wc_let_to_num( ini_get( 'memory_limit' ) ) );
|
374 |
-
$wp_memory = size_format( (WC()->version < '2.7.0')? woocommerce_let_to_num( WP_MEMORY_LIMIT ) : wc_let_to_num( WP_MEMORY_LIMIT ) );
|
375 |
-
$this->hf_coupon_log_data_change( 'coupon-csv-import', '---[ New Import ] PHP Memory: ' . $memory . ', WP Memory: ' . $wp_memory );
|
376 |
-
$this->hf_coupon_log_data_change( 'coupon-csv-import', __( 'Parsing coupons CSV.', 'order-import-export-for-woocommerce' ) );
|
377 |
-
$this->parser = new WF_CSV_Parser_Coupon( 'shop_coupon' );
|
378 |
-
list( $this->parsed_data, $this->raw_headers, $position ) = $this->parser->parse_data( $file, $this->delimiter, $start_pos, $end_pos);
|
379 |
-
$this->hf_coupon_log_data_change( 'coupon-csv-import', __( 'Finished parsing coupons CSV.', 'order-import-export-for-woocommerce' ) );
|
380 |
-
unset( $import_data );
|
381 |
-
wp_defer_term_counting( true );
|
382 |
-
wp_defer_comment_counting( true );
|
383 |
-
return $position;
|
384 |
-
}
|
385 |
-
|
386 |
-
/**
|
387 |
-
* Performs post-import cleanup of files and the cache
|
388 |
-
*/
|
389 |
-
public function import_end() {
|
390 |
-
do_action( 'import_end' );
|
391 |
-
}
|
392 |
-
|
393 |
-
/**
|
394 |
-
* Handles the CSV upload and initial parsing of the file to prepare for
|
395 |
-
* displaying author import options
|
396 |
-
*
|
397 |
-
* @return bool False if error uploading or invalid file, true otherwise
|
398 |
-
*/
|
399 |
-
public function handle_upload() {
|
400 |
-
if ( empty( $_POST['file_url'] ) ) {
|
401 |
-
$file = wp_import_handle_upload();
|
402 |
-
if ( isset( $file['error'] ) ) {
|
403 |
-
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'order-import-export-for-woocommerce' ) . '</strong><br />';
|
404 |
-
echo esc_html( $file['error'] ) . '</p>';
|
405 |
-
return false;
|
406 |
-
}
|
407 |
-
$this->id = absint($file['id']);
|
408 |
-
return true;
|
409 |
-
} else {
|
410 |
-
if ( file_exists( ABSPATH . $_POST['file_url'] ) ){
|
411 |
-
$this->file_url = esc_url_raw( $_POST['file_url'] );
|
412 |
-
return true;
|
413 |
-
} else {
|
414 |
-
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'order-import-export-for-woocommerce' ) . '</strong></p>';
|
415 |
-
return false;
|
416 |
-
}
|
417 |
-
}
|
418 |
-
return false;
|
419 |
-
}
|
420 |
-
|
421 |
-
public function coupon_exists( $title, $ID = '', $post_name = '' ){
|
422 |
-
global $wpdb;
|
423 |
-
// Post Title Check
|
424 |
-
$post_title = stripslashes( sanitize_post_field( 'post_title', $title, 0, 'db' ) );
|
425 |
-
$query = "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_coupon' AND post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )";
|
426 |
-
$args = array();
|
427 |
-
if ( ! empty ( $post_name ) ) {
|
428 |
-
$query .= ' AND post_name = %s';
|
429 |
-
$args[] = $post_name;
|
430 |
-
}
|
431 |
-
if ( ! empty ( $args ) ) {
|
432 |
-
$posts_that_exist = $wpdb->get_col( $wpdb->prepare( $query, $args ) );
|
433 |
-
if ( $posts_that_exist ) {
|
434 |
-
foreach( $posts_that_exist as $post_exists ) {
|
435 |
-
if ( $ID == $post_exists ) {
|
436 |
-
return true;
|
437 |
-
}
|
438 |
-
}
|
439 |
-
}
|
440 |
-
}
|
441 |
-
return false;
|
442 |
-
}
|
443 |
-
|
444 |
-
/**
|
445 |
-
* Create new posts based on import information
|
446 |
-
*/
|
447 |
-
public function process_coupon($post) {
|
448 |
-
$processing_coupon_id = absint($post['post_id']);
|
449 |
-
$processing_coupon = get_post($processing_coupon_id);
|
450 |
-
$processing_coupon_title = $processing_coupon ? $processing_coupon->post_title : '';
|
451 |
-
$processing_coupon_sku = $processing_coupon ? $processing_coupon->sku : '';
|
452 |
-
$merging = !empty($post['merging']);
|
453 |
-
|
454 |
-
if (!empty($post['post_title'])) {
|
455 |
-
$processing_coupon_title = $post['post_title'];
|
456 |
-
}
|
457 |
-
$post['post_type'] = 'shop_coupon';
|
458 |
-
|
459 |
-
if (!empty($processing_coupon_id) && isset($this->processed_posts[$processing_coupon_id])) {
|
460 |
-
$this->add_import_result('skipped', __('Coupon already processed', 'order-import-export-for-woocommerce'), $processing_coupon_id, $processing_coupon_title);
|
461 |
-
$this->hf_coupon_log_data_change('coupon-csv-import', __('> Coupon ID already processed. Skipping.', 'order-import-export-for-woocommerce'), true);
|
462 |
-
unset($post);
|
463 |
-
return;
|
464 |
-
}
|
465 |
-
|
466 |
-
if (!empty($post['post_status']) && $post['post_status'] == 'auto-draft') {
|
467 |
-
$this->add_import_result('skipped', __('Skipping auto-draft', 'order-import-export-for-woocommerce'), $processing_coupon_id, $processing_coupon_title);
|
468 |
-
$this->hf_coupon_log_data_change('coupon-csv-import', __('> Skipping auto-draft.', 'order-import-export-for-woocommerce'), true);
|
469 |
-
unset($post);
|
470 |
-
return;
|
471 |
-
}
|
472 |
-
$is_post_exist_in_db = get_post_type($processing_coupon_id);
|
473 |
-
if (!$merging) {
|
474 |
-
if ($this->coupon_exists($processing_coupon_title, $processing_coupon_id, $post['post_name'])) {
|
475 |
-
if (!$processing_coupon_id) {
|
476 |
-
$usr_msg = 'Coupon with same title already exists.';
|
477 |
-
} else {
|
478 |
-
$usr_msg = 'Coupon already exists.';
|
479 |
-
}
|
480 |
-
$this->add_import_result('skipped', __($usr_msg, 'order-import-export-for-woocommerce'), $processing_coupon_id, $processing_coupon_title);
|
481 |
-
$this->hf_coupon_log_data_change('coupon-csv-import', sprintf(__('> “%s”' . $usr_msg, 'order-import-export-for-woocommerce'), esc_html($processing_coupon_title)), true);
|
482 |
-
unset($post);
|
483 |
-
return;
|
484 |
-
}
|
485 |
-
|
486 |
-
if ($processing_coupon_id && is_string(get_post_status($processing_coupon_id)) && ($is_post_exist_in_db == $post['post_type'] )) {
|
487 |
-
$this->add_import_result('skipped', __('Coupon with same ID already exists.', 'order-import-export-for-woocommerce'), $processing_coupon_id, get_the_title($processing_coupon_id));
|
488 |
-
$this->hf_coupon_log_data_change('coupon-csv-import', sprintf(__('> “%s” ID already exists.', 'order-import-export-for-woocommerce'), esc_html($processing_coupon_id)), true);
|
489 |
-
unset($post);
|
490 |
-
return;
|
491 |
-
}
|
492 |
-
|
493 |
-
if ( $processing_coupon_id && is_string( get_post_status( $processing_coupon_id ) ) && ($is_post_exist_in_db !== $post['post_type'] ) ) {
|
494 |
-
$this->add_import_result( 'skipped', __( 'Importing coupon(ID) conflicts with an existing post.', 'order-import-export-for-woocommerce' ), $processing_coupon_id, get_the_title( $processing_coupon_id ) );
|
495 |
-
$this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> “%s” ID already exists.', 'order-import-export-for-woocommerce'), esc_html( $processing_coupon_id ) ), true );
|
496 |
-
unset( $post );
|
497 |
-
return;
|
498 |
-
}
|
499 |
-
}
|
500 |
-
if ($merging && $processing_coupon_id && !empty($is_post_exist_in_db) && ($is_post_exist_in_db !== $post['post_type'] )) {
|
501 |
-
$this->add_import_result('skipped', __('Importing coupon(ID) conflicts with an existing post which is not a coupon.', 'order-import-export-for-woocommerce'), $processing_coupon_id, $processing_coupon_title);
|
502 |
-
$this->hf_coupon_log_data_change('coupon-csv-import', sprintf(__('> “%s” is not a coupon.', 'order-import-export-for-woocommerce'), esc_html($processing_coupon_id)), true);
|
503 |
-
unset($post);
|
504 |
-
return;
|
505 |
-
}
|
506 |
-
|
507 |
-
if ($merging && !empty($is_post_exist_in_db)) {
|
508 |
-
$post_id = $processing_coupon_id;
|
509 |
-
$this->hf_coupon_log_data_change('coupon-csv-import', sprintf(__('> Merging coupon ID %s.', 'order-import-export-for-woocommerce'), $post_id), true);
|
510 |
-
$postdata = array('ID' => $post_id);
|
511 |
-
|
512 |
-
// if ($this->merge_empty_cells) {
|
513 |
-
// if (isset($post['post_content'])) {
|
514 |
-
// $postdata['post_content'] = $post['post_content'];
|
515 |
-
// }
|
516 |
-
// if (isset($post['post_excerpt'])) {
|
517 |
-
// $postdata['post_excerpt'] = $post['post_excerpt'];
|
518 |
-
// }
|
519 |
-
// } else {
|
520 |
-
if (!empty($post['post_content'])) {
|
521 |
-
$postdata['post_content'] = $post['post_content'];
|
522 |
-
}
|
523 |
-
if (!empty($post['post_excerpt'])) {
|
524 |
-
$postdata['post_excerpt'] = $post['post_excerpt'];
|
525 |
-
}
|
526 |
-
// }
|
527 |
-
if (!empty($post['post_title'])) {
|
528 |
-
$postdata['post_title'] = $post['post_title'];
|
529 |
-
}
|
530 |
-
if (!empty($post['post_author'])) {
|
531 |
-
$postdata['post_author'] = absint($post['post_author']);
|
532 |
-
}
|
533 |
-
if (!empty($post['post_date'])) {
|
534 |
-
$postdata['post_date'] = date("Y-m-d H:i:s", strtotime($post['post_date']));
|
535 |
-
}
|
536 |
-
if (!empty($post['post_date_gmt'])) {
|
537 |
-
$postdata['post_date_gmt'] = date("Y-m-d H:i:s", strtotime($post['post_date_gmt']));
|
538 |
-
}
|
539 |
-
if (!empty($post['post_name'])) {
|
540 |
-
$postdata['post_name'] = $post['post_name'];
|
541 |
-
}
|
542 |
-
if (!empty($post['post_status'])) {
|
543 |
-
$postdata['post_status'] = $post['post_status'];
|
544 |
-
}
|
545 |
-
if (sizeof($postdata) > 1) {
|
546 |
-
$result = wp_update_post($postdata);
|
547 |
-
if (!$result) {
|
548 |
-
$this->add_import_result('failed', __('Failed to update coupon', 'order-import-export-for-woocommerce'), $post_id, $processing_coupon_title);
|
549 |
-
$this->hf_coupon_log_data_change('coupon-csv-import', sprintf(__('> Failed to update coupon %s', 'order-import-export-for-woocommerce'), $post_id), true);
|
550 |
-
unset($post);
|
551 |
-
return;
|
552 |
-
} else {
|
553 |
-
$this->hf_coupon_log_data_change('coupon-csv-import', __('> Merged post data: ', 'order-import-export-for-woocommerce') . print_r($postdata, true));
|
554 |
-
}
|
555 |
-
}
|
556 |
-
} else {
|
557 |
-
$merging = FALSE;
|
558 |
-
$this->hf_coupon_log_data_change('coupon-csv-import', sprintf(__('> Inserting %s', 'order-import-export-for-woocommerce'), esc_html($processing_coupon_title)), true);
|
559 |
-
$postdata = array(
|
560 |
-
'import_id' => $post['post_id'],
|
561 |
-
'post_author' => (isset($post['post_author']) && !empty($post['post_author'])) ? absint($post['post_author']) : get_current_user_id(),
|
562 |
-
'post_date' => (isset($post['post_date']) && !empty($post['post_date'])) ? date('Y-m-d H:i:s', strtotime($post['post_date'])) : '',
|
563 |
-
'post_date_gmt' => (isset($post['post_date_gmt']) && !empty($post['post_date_gmt'])) ? date('Y-m-d H:i:s', strtotime($post['post_date_gmt'])) : '',
|
564 |
-
'post_content' => $post['post_excerpt'],
|
565 |
-
'post_excerpt' => $post['post_excerpt'],
|
566 |
-
'post_title' => $post['post_title'],
|
567 |
-
'post_name' => (isset($post['post_name']) && !empty($post['post_name'])) ? $post['post_name'] : sanitize_title($post['post_title']),
|
568 |
-
'post_status' => (isset($post['post_status']) && !empty($post['post_status'])) ? $post['post_status'] : 'publish',
|
569 |
-
'post_type' => 'shop_coupon',
|
570 |
-
);
|
571 |
-
|
572 |
-
$post_id = wp_insert_post($postdata, true);
|
573 |
-
|
574 |
-
if (is_wp_error($post_id)) {
|
575 |
-
$this->add_import_result('failed', __('Failed to import coupon', 'order-import-export-for-woocommerce'), $processing_coupon_id, $processing_coupon_title);
|
576 |
-
$this->hf_coupon_log_data_change('coupon-csv-import', sprintf(__('Failed to import coupon “%s”', 'order-import-export-for-woocommerce'), esc_html($processing_coupon_title)));
|
577 |
-
unset($post);
|
578 |
-
return;
|
579 |
-
} else {
|
580 |
-
$this->hf_coupon_log_data_change('coupon-csv-import', sprintf(__('> Inserted - coupon ID is %s.', 'order-import-export-for-woocommerce'), $post_id));
|
581 |
-
}
|
582 |
-
}
|
583 |
-
|
584 |
-
unset($postdata);
|
585 |
-
|
586 |
-
if (empty($processing_coupon_id)) {
|
587 |
-
$processing_coupon_id = (int) $post_id;
|
588 |
-
}
|
589 |
-
|
590 |
-
$this->processed_posts[intval($processing_coupon_id)] = (int) $post_id;
|
591 |
-
if (!empty($post['postmeta']) && is_array($post['postmeta'])) {
|
592 |
-
foreach ($post['postmeta'] as $meta) {
|
593 |
-
$key = apply_filters('import_post_meta_key', $meta['key']);
|
594 |
-
|
595 |
-
if ($key) {
|
596 |
-
if ($key == 'product_categories' || $key == 'exclude_product_categories') {
|
597 |
-
update_post_meta($post_id, $key, explode(",", $meta['value']));
|
598 |
-
} elseif ($key == 'customer_email') {
|
599 |
-
$data = explode(',', $meta['value']);
|
600 |
-
update_post_meta($post_id, $key, $data);
|
601 |
-
} elseif ($key == 'expiry_date') {
|
602 |
-
$data = strtotime($meta['value']);
|
603 |
-
update_post_meta($post_id, 'date_expires', $data);
|
604 |
-
}else {
|
605 |
-
update_post_meta($post_id, $key, maybe_unserialize($meta['value']));
|
606 |
-
}
|
607 |
-
}
|
608 |
-
}
|
609 |
-
unset($post['postmeta']);
|
610 |
-
}
|
611 |
-
if ($merging) {
|
612 |
-
$this->add_import_result('merged', 'Coupon Merge successful', $post_id, $processing_coupon_title);
|
613 |
-
$this->hf_coupon_log_data_change('coupon-csv-import', sprintf(__('> Finished merging post ID %s.', 'order-import-export-for-woocommerce'), $post_id));
|
614 |
-
} else {
|
615 |
-
$this->add_import_result('imported', 'Coupon Import successful', $post_id, $processing_coupon_title);
|
616 |
-
$this->hf_coupon_log_data_change('coupon-csv-import', sprintf(__('> Finished importing post ID %s.', 'order-import-export-for-woocommerce'), $post_id));
|
617 |
-
}
|
618 |
-
unset($post);
|
619 |
-
}
|
620 |
-
|
621 |
-
/**
|
622 |
-
* Log a row's import status
|
623 |
-
*/
|
624 |
-
protected function add_import_result( $status, $reason, $post_id = '', $post_title = '' ) {
|
625 |
-
$this->import_results[] = array(
|
626 |
-
'post_title' => $post_title,
|
627 |
-
'post_id' => $post_id,
|
628 |
-
'status' => $status,
|
629 |
-
'reason' => $reason
|
630 |
-
);
|
631 |
-
}
|
632 |
-
|
633 |
-
// Display import page title
|
634 |
-
public function header() {
|
635 |
-
echo '<div><div class="icon32" id="icon-woocommerce-importer"><br></div>';
|
636 |
-
echo '<h2>' . ( empty( $_GET['merge'] ) ? __( 'Import', 'order-import-export-for-woocommerce' ) : __( 'Merge Coupons', 'order-import-export-for-woocommerce' ) ) . '</h2>';
|
637 |
-
}
|
638 |
-
|
639 |
-
// Close div.wrap
|
640 |
-
public function footer() {
|
641 |
-
echo '</div>';
|
642 |
-
}
|
643 |
-
|
644 |
-
/**
|
645 |
-
* Display introductory text and file upload form
|
646 |
-
*/
|
647 |
-
public function greet() {
|
648 |
-
$action = 'admin.php?import=coupon_csv&step=1&merge=' . ( ! empty( $_GET['merge'] ) ? 1 : 0 );
|
649 |
-
$bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
|
650 |
-
$size = size_format( $bytes );
|
651 |
-
$upload_dir = wp_upload_dir();
|
652 |
-
include( 'views-coupon/html-wf-import-greeting.php' );
|
653 |
-
}
|
654 |
-
|
655 |
-
/**
|
656 |
-
* Added to http_request_timeout filter to force timeout at 60 seconds during import
|
657 |
-
* @return int 60
|
658 |
-
*/
|
659 |
-
public function bump_request_timeout( $val ) {
|
660 |
-
return 60;
|
661 |
-
}
|
662 |
-
|
663 |
-
public function hf_coupon_log_data_change ($content = 'coupon-csv-import',$data=''){
|
664 |
-
if (WC()->version < '2.7.0'){
|
665 |
-
$this->log->add($content,$data);
|
666 |
-
}else{
|
667 |
-
$context = array( 'source' => $content );
|
668 |
-
$this->log->log("debug", $data ,$context);
|
669 |
-
}
|
670 |
-
}
|
671 |
-
|
672 |
-
public function detectDelimiter($csvFile) {
|
673 |
-
$delimiters = array(
|
674 |
-
';' => 0,
|
675 |
-
',' => 0,
|
676 |
-
"\t" => 0,
|
677 |
-
"|" => 0
|
678 |
-
);
|
679 |
-
|
680 |
-
$handle = @fopen($csvFile, "r");
|
681 |
-
$firstLine = @fgets($handle);
|
682 |
-
@fclose($handle);
|
683 |
-
foreach ($delimiters as $delimiter => &$count) {
|
684 |
-
$count = count(str_getcsv($firstLine, $delimiter));
|
685 |
-
}
|
686 |
-
return array_search(max($delimiters), $delimiters);
|
687 |
-
}
|
688 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/importer/class-wf-cpnimpexpcsv-importer.php
DELETED
@@ -1,41 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
3 |
-
exit;
|
4 |
-
}
|
5 |
-
|
6 |
-
class WF_CpnImpExpCsv_Importer {
|
7 |
-
|
8 |
-
/**
|
9 |
-
* Coupon Exporter Tool
|
10 |
-
*/
|
11 |
-
public static function load_wp_importer() {
|
12 |
-
// Load Importer API
|
13 |
-
require_once ABSPATH . 'wp-admin/includes/import.php';
|
14 |
-
|
15 |
-
if ( ! class_exists( 'WP_Importer' ) ) {
|
16 |
-
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
|
17 |
-
if ( file_exists( $class_wp_importer ) ) {
|
18 |
-
require $class_wp_importer;
|
19 |
-
}
|
20 |
-
}
|
21 |
-
}
|
22 |
-
|
23 |
-
/**
|
24 |
-
* Coupon Importer Tool
|
25 |
-
*/
|
26 |
-
public static function coupon_importer() {
|
27 |
-
if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
|
28 |
-
return;
|
29 |
-
}
|
30 |
-
|
31 |
-
self::load_wp_importer();
|
32 |
-
|
33 |
-
// includes
|
34 |
-
require_once 'class-wf-cpnimpexpcsv-coupon-import.php';
|
35 |
-
require_once 'class-wf-csv-parser-coupon.php';
|
36 |
-
|
37 |
-
// Dispatch
|
38 |
-
$GLOBALS['WF_CSV_Coupon_Import'] = new WF_CpnImpExpCsv_Coupon_Import();
|
39 |
-
$GLOBALS['WF_CSV_Coupon_Import'] ->dispatch();
|
40 |
-
}
|
41 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/importer/class-wf-csv-parser-coupon.php
DELETED
@@ -1,175 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WooCommerce CSV Importer class for managing parsing of CSV files.
|
4 |
-
*/
|
5 |
-
class WF_CSV_Parser_Coupon {
|
6 |
-
var $row;
|
7 |
-
var $post_type;
|
8 |
-
var $reserved_fields; // Fields we map/handle (not custom fields)
|
9 |
-
var $post_defaults; // Default post data
|
10 |
-
var $postmeta_defaults; // default post meta
|
11 |
-
var $postmeta_allowed; // post meta validation
|
12 |
-
|
13 |
-
/**
|
14 |
-
* Constructor
|
15 |
-
*/
|
16 |
-
public function __construct( $post_type = 'shop_coupon' ) {
|
17 |
-
$this->post_type = $post_type;
|
18 |
-
$this->reserved_fields = include( 'data-coupon/data-wf-reserved-fields.php' );
|
19 |
-
$this->post_defaults = include( 'data-coupon/data-wf-post-defaults.php' );
|
20 |
-
$this->postmeta_defaults = include( 'data-coupon/data-wf-postmeta-defaults.php' );
|
21 |
-
$this->postmeta_allowed = include( 'data-coupon/data-wf-postmeta-allowed.php' );
|
22 |
-
}
|
23 |
-
|
24 |
-
/**
|
25 |
-
* Format data from the csv file
|
26 |
-
* @param string $data
|
27 |
-
* @param string $enc
|
28 |
-
* @return string
|
29 |
-
*/
|
30 |
-
public function format_data_from_csv( $data, $enc ) {
|
31 |
-
return ( $enc == 'UTF-8' ) ? $data : utf8_encode( $data );
|
32 |
-
}
|
33 |
-
|
34 |
-
/**
|
35 |
-
* Parse the data
|
36 |
-
* @param string $file [description]
|
37 |
-
* @param string $delimiter [description]
|
38 |
-
* @param integer $start_pos [description]
|
39 |
-
* @param integer $end_pos [description]
|
40 |
-
* @return array
|
41 |
-
*/
|
42 |
-
public function parse_data( $file, $delimiter, $start_pos = 0, $end_pos = null) {
|
43 |
-
// Set locale
|
44 |
-
$enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
|
45 |
-
if ( $enc )
|
46 |
-
setlocale( LC_ALL, 'en_US.' . $enc );
|
47 |
-
@ini_set( 'auto_detect_line_endings', true );
|
48 |
-
$parsed_data = array();
|
49 |
-
$raw_headers = array();
|
50 |
-
// Put all CSV data into an associative array
|
51 |
-
if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
|
52 |
-
$header = fgetcsv( $handle, 0, $delimiter );
|
53 |
-
if ( $start_pos != 0 )
|
54 |
-
fseek( $handle, $start_pos );
|
55 |
-
while ( ( $postmeta = fgetcsv( $handle, 0, $delimiter , '"', '"' ) ) !== FALSE ) {
|
56 |
-
$row = array();
|
57 |
-
foreach ( $header as $key => $heading ) {
|
58 |
-
// Heading is the lowercase version of the column name
|
59 |
-
$s_heading = strtolower( $heading );
|
60 |
-
if ( $s_heading == '' )
|
61 |
-
continue;
|
62 |
-
// Add the heading to the parsed data
|
63 |
-
$row[$s_heading] = ( isset( $postmeta[$key] ) ) ? $this->format_data_from_csv( $postmeta[$key], $enc ) : '';
|
64 |
-
// Raw Headers stores the actual column name in the CSV
|
65 |
-
$raw_headers[ $s_heading ] = $heading;
|
66 |
-
}
|
67 |
-
$parsed_data[] = $row;
|
68 |
-
unset( $postmeta, $row );
|
69 |
-
$position = ftell( $handle );
|
70 |
-
if ( $end_pos && $position >= $end_pos )
|
71 |
-
break;
|
72 |
-
}
|
73 |
-
fclose( $handle );
|
74 |
-
}
|
75 |
-
return array( $parsed_data, $raw_headers, $position );
|
76 |
-
}
|
77 |
-
|
78 |
-
|
79 |
-
/**
|
80 |
-
* Parse Coupons
|
81 |
-
* @param array $item
|
82 |
-
* @return array
|
83 |
-
*/
|
84 |
-
public function parse_coupon( $item ) {
|
85 |
-
global $WF_CSV_Coupon_Import, $wpdb;
|
86 |
-
$this->row++;
|
87 |
-
$postmeta = $coupon = array();
|
88 |
-
// Merging
|
89 |
-
$merging = ( ! empty( $_GET['merge'] ) && $_GET['merge'] ) ? true : false;
|
90 |
-
$this->post_defaults['post_type'] = 'shop_coupon';
|
91 |
-
$post_id = ( ! empty( $item['id'] ) ) ? $item['id'] : 0;
|
92 |
-
$post_id = ( ! empty( $item['post_id'] ) ) ? $item['post_id'] : $post_id;
|
93 |
-
if (!empty($item['date_expires'])) {
|
94 |
-
$item['expiry_date'] = $item['date_expires'];
|
95 |
-
if (false === ( $item['date_expires'] = strtotime($item['date_expires']) )) {
|
96 |
-
$WF_CSV_Coupon_Import->hf_coupon_log_data_change('coupon-csv-import', __('> > Invalid date_expires format', 'order-import-export-for-woocommerce'));
|
97 |
-
}
|
98 |
-
}
|
99 |
-
if ( $merging ) {
|
100 |
-
$coupon['merging'] = true;
|
101 |
-
$WF_CSV_Coupon_Import->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> Row %s - preparing for merge.', 'order-import-export-for-woocommerce'), $this->row ) );
|
102 |
-
if ( ! $post_id ) {
|
103 |
-
$WF_CSV_Coupon_Import->hf_coupon_log_data_change( 'coupon-csv-import', __( '> > Cannot merge without id or sku. Importing instead.', 'order-import-export-for-woocommerce') );
|
104 |
-
$merging = false;
|
105 |
-
} else {
|
106 |
-
if ( ! $post_id ) {
|
107 |
-
$post_db_type = $this->post_defaults['post_type'];
|
108 |
-
$post_pass_type = '"'.$post_db_type.'"';
|
109 |
-
$db_query = $wpdb->prepare("SELECT $wpdb->posts.ID
|
110 |
-
FROM $wpdb->posts
|
111 |
-
LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)
|
112 |
-
WHERE $wpdb->posts.post_type = $post_pass_type
|
113 |
-
AND $wpdb->posts.post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )
|
114 |
-
AND $wpdb->posts.ID = '%d'
|
115 |
-
", $item['ID']);
|
116 |
-
$found_product_id = $wpdb->get_var($db_query);
|
117 |
-
if ( ! $found_product_id ) {
|
118 |
-
$WF_CSV_Coupon_Import->hf_coupon_log_data_change( 'coupon-csv-import', sprintf(__( '> > Skipped. Cannot find coupon with sku %s. Importing instead.', 'order-import-export-for-woocommerce'), $item['sku']) );
|
119 |
-
$merging = false;
|
120 |
-
} else {
|
121 |
-
$post_id = $found_product_id;
|
122 |
-
$WF_CSV_Coupon_Import->hf_coupon_log_data_change( 'coupon-csv-import', sprintf(__( '> > Found coupon with ID %s.', 'order-import-export-for-woocommerce'), $post_id) );
|
123 |
-
}
|
124 |
-
}
|
125 |
-
$coupon['merging'] = true;
|
126 |
-
}
|
127 |
-
}
|
128 |
-
if ( ! $merging ) {
|
129 |
-
$coupon['merging'] = false;
|
130 |
-
$WF_CSV_Coupon_Import->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> Row %s - preparing for import.', 'order-import-export-for-woocommerce'), $this->row ) );
|
131 |
-
if ( isset($item['post_parent']) && $item['post_parent']=== '' && $item['post_title']=== '') {
|
132 |
-
$WF_CSV_Coupon_Import->hf_coupon_log_data_change( 'coupon-csv-import', __( '> > Skipped. No post_title set for new coupon.', 'order-import-export-for-woocommerce') );
|
133 |
-
return new WP_Error( 'parse-error', __( 'No post_title set for new coupon.', 'order-import-export-for-woocommerce' ) );
|
134 |
-
}
|
135 |
-
if ( isset($item['post_parent']) && $item['post_parent']!== '' && $item['post_parent']!== null && $item['parent_sku'] === '' ) {
|
136 |
-
$WF_CSV_Coupon_Import->hf_coupon_log_data_change( 'coupon-csv-import', __( '> > Skipped. No parent set for new variation product.', 'order-import-export-for-woocommerce') );
|
137 |
-
return new WP_Error( 'parse-error', __( 'No parent set for new variation product.', 'order-import-export-for-woocommerce' ) );
|
138 |
-
}
|
139 |
-
}
|
140 |
-
$coupon['post_id'] = $post_id;
|
141 |
-
foreach ( $this->post_defaults as $column => $default ) {
|
142 |
-
if ( isset( $item[ $column ] ) ) $coupon[ $column ] = $item[ $column ];
|
143 |
-
}
|
144 |
-
// Get custom fields
|
145 |
-
foreach ( $this->postmeta_defaults as $column => $default ) {
|
146 |
-
if ( isset( $item[$column] ) )
|
147 |
-
$postmeta[$column] = (string) $item[$column];
|
148 |
-
elseif ( isset( $item[$column] ) )
|
149 |
-
$postmeta[$column] = (string) $item[$column];
|
150 |
-
// Check custom fields are valid
|
151 |
-
if ( isset( $postmeta[$column] ) && isset( $this->postmeta_allowed[$column] ) && ! in_array( $postmeta[$column], $this->postmeta_allowed[$column] ) ) {
|
152 |
-
$postmeta[$column] = $this->postmeta_defaults[$column];
|
153 |
-
}
|
154 |
-
}
|
155 |
-
if ( ! $merging ) {
|
156 |
-
// Merge post meta with defaults
|
157 |
-
$coupon = wp_parse_args( $coupon, $this->post_defaults );
|
158 |
-
$postmeta = wp_parse_args( $postmeta, $this->postmeta_defaults );
|
159 |
-
}
|
160 |
-
if ( ! empty( $coupon['post_status'] ) ) {
|
161 |
-
if ( ! in_array( $coupon['post_status'], array( 'publish', 'private', 'draft', 'pending', 'future', 'inherit', 'trash' ) ) ) {
|
162 |
-
$coupon['post_status'] = 'publish';
|
163 |
-
}
|
164 |
-
if ( ! in_array( $coupon['post_status'], array( 'private', 'publish' ) ) ) {
|
165 |
-
$coupon['post_status'] = 'publish';
|
166 |
-
}
|
167 |
-
}
|
168 |
-
foreach ( $postmeta as $key => $value ) {
|
169 |
-
$coupon['postmeta'][] = array( 'key' => esc_attr($key), 'value' => $value );
|
170 |
-
}
|
171 |
-
$coupon['post_title'] = ( ! empty( $item['post_title'] ) ) ? $item['post_title'] : '';
|
172 |
-
unset( $item, $postmeta );
|
173 |
-
return $coupon;
|
174 |
-
}
|
175 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/importer/class-wf-csv-parser.php
DELETED
@@ -1,782 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* WooCommerce CSV Importer class for managing parsing of CSV files.
|
5 |
-
*/
|
6 |
-
class WF_CSV_Parser {
|
7 |
-
|
8 |
-
var $row;
|
9 |
-
var $post_type;
|
10 |
-
var $posts = array();
|
11 |
-
var $processed_posts = array();
|
12 |
-
var $file_url_import_enabled = true;
|
13 |
-
var $log;
|
14 |
-
var $merged = 0;
|
15 |
-
var $skipped = 0;
|
16 |
-
var $imported = 0;
|
17 |
-
var $errored = 0;
|
18 |
-
var $id;
|
19 |
-
var $file_url;
|
20 |
-
var $delimiter;
|
21 |
-
|
22 |
-
/**
|
23 |
-
* Constructor
|
24 |
-
*/
|
25 |
-
public function __construct($post_type = 'shop_order') {
|
26 |
-
$this->post_type = $post_type;
|
27 |
-
$this->order_meta_fields = array(
|
28 |
-
"order_tax",
|
29 |
-
"order_shipping",
|
30 |
-
"order_shipping_tax",
|
31 |
-
"shipping_total",
|
32 |
-
"shipping_tax_total",
|
33 |
-
"fee_total",
|
34 |
-
"fee_tax_total",
|
35 |
-
"tax_total",
|
36 |
-
"discount_total",
|
37 |
-
"customer_user",
|
38 |
-
"cart_discount",
|
39 |
-
"order_discount",
|
40 |
-
"order_total",
|
41 |
-
"order_currency",
|
42 |
-
"payment_method",
|
43 |
-
"customer_email",
|
44 |
-
"billing_first_name",
|
45 |
-
"billing_last_name",
|
46 |
-
"billing_company",
|
47 |
-
"billing_address_1",
|
48 |
-
"billing_address_2",
|
49 |
-
"billing_city",
|
50 |
-
"billing_state",
|
51 |
-
"billing_postcode",
|
52 |
-
"billing_country",
|
53 |
-
"billing_email",
|
54 |
-
"billing_phone",
|
55 |
-
"shipping_first_name",
|
56 |
-
"shipping_last_name",
|
57 |
-
"shipping_company",
|
58 |
-
"shipping_address_1",
|
59 |
-
"shipping_address_2",
|
60 |
-
"shipping_city",
|
61 |
-
"shipping_state",
|
62 |
-
"shipping_postcode",
|
63 |
-
"shipping_country",
|
64 |
-
"shipping_method",
|
65 |
-
"download_permissions",
|
66 |
-
"customer_ip_address",
|
67 |
-
"paid_date",
|
68 |
-
"completed_date"
|
69 |
-
);
|
70 |
-
}
|
71 |
-
|
72 |
-
/**
|
73 |
-
* Format data from the csv file
|
74 |
-
* @param string $data
|
75 |
-
* @param string $enc
|
76 |
-
* @return string
|
77 |
-
*/
|
78 |
-
public function format_data_from_csv($data, $enc) {
|
79 |
-
return ( $enc == 'UTF-8' ) ? $data : utf8_encode($data);
|
80 |
-
}
|
81 |
-
|
82 |
-
/**
|
83 |
-
* Parse the data
|
84 |
-
* @param string $file [description]
|
85 |
-
* @param string $delimiter [description]
|
86 |
-
* @param integer $start_pos [description]
|
87 |
-
* @param integer $end_pos [description]
|
88 |
-
* @return array
|
89 |
-
*/
|
90 |
-
public function parse_data($file, $delimiter, $start_pos = 0, $end_pos = null) {
|
91 |
-
// Set locale
|
92 |
-
$enc = mb_detect_encoding($file, 'UTF-8, ISO-8859-1', true);
|
93 |
-
if ($enc)
|
94 |
-
setlocale(LC_ALL, 'en_US.' . $enc);
|
95 |
-
@ini_set('auto_detect_line_endings', true);
|
96 |
-
$parsed_data = array();
|
97 |
-
$raw_headers = array();
|
98 |
-
// Put all CSV data into an associative array
|
99 |
-
if (( $handle = fopen($file, "r") ) !== FALSE) {
|
100 |
-
$header = fgetcsv($handle, 0, $delimiter);
|
101 |
-
if ($start_pos != 0)
|
102 |
-
fseek($handle, $start_pos);
|
103 |
-
while (( $postmeta = fgetcsv($handle, 0, $delimiter) ) !== FALSE) {
|
104 |
-
$row = array();
|
105 |
-
foreach ($header as $key => $heading) {
|
106 |
-
$s_heading = $heading;
|
107 |
-
if ($s_heading == '')
|
108 |
-
continue;
|
109 |
-
// Add the heading to the parsed data
|
110 |
-
$row[$s_heading] = ( isset($postmeta[$key]) ) ? $this->format_data_from_csv($postmeta[$key], $enc) : '';
|
111 |
-
// Raw Headers stores the actual column name in the CSV
|
112 |
-
$raw_headers[$s_heading] = $heading;
|
113 |
-
}
|
114 |
-
$parsed_data[] = $row;
|
115 |
-
unset($postmeta, $row);
|
116 |
-
$position = ftell($handle);
|
117 |
-
if ($end_pos && $position >= $end_pos)
|
118 |
-
break;
|
119 |
-
}
|
120 |
-
fclose($handle);
|
121 |
-
}
|
122 |
-
return array($parsed_data, $raw_headers, $position);
|
123 |
-
}
|
124 |
-
|
125 |
-
/**
|
126 |
-
* Parse orders
|
127 |
-
* @param array $item
|
128 |
-
* @param integer $merge_empty_cells
|
129 |
-
* @return array
|
130 |
-
*/
|
131 |
-
public function parse_orders($parsed_data, $raw_headers, $merging, $record_offset) {
|
132 |
-
$item = $parsed_data;
|
133 |
-
global $WF_CSV_Order_Import, $wpdb;
|
134 |
-
//$allow_unknown_products = isset( $_POST['allow_unknown_products'] ) && $_POST['allow_unknown_products'] ? true : false;
|
135 |
-
$allow_unknown_products = true;
|
136 |
-
$results = array();
|
137 |
-
// Count row
|
138 |
-
$row = 0;
|
139 |
-
// skipped records
|
140 |
-
$skipped = 0;
|
141 |
-
$csv_export_file = true;
|
142 |
-
$available_methods = WC()->shipping()->load_shipping_methods();
|
143 |
-
$available_gateways = WC()->payment_gateways->payment_gateways();
|
144 |
-
$shop_order_status = $this->wc_get_order_statuses_neat();
|
145 |
-
$tax_rates = array();
|
146 |
-
foreach ($wpdb->get_results("SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates") as $_row) {
|
147 |
-
$tax_rates[$_row->tax_rate_id] = $_row;
|
148 |
-
}
|
149 |
-
$row++;
|
150 |
-
if ($row <= $record_offset) {
|
151 |
-
$WF_CSV_Order_Import->add_import_result('skipped', __('skipped due to record offset', 'order-import-export-for-woocommerce'));
|
152 |
-
$WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> Row %s - skipped due to record offset.', 'order-import-export-for-woocommerce'), $row));
|
153 |
-
unset($item);
|
154 |
-
return;
|
155 |
-
}
|
156 |
-
$postmeta = $order = array();
|
157 |
-
if (!$csv_export_file) {
|
158 |
-
// standard format: optional integer order number and formatted order number
|
159 |
-
$order_number = (!empty($item['order_number']) ) ? $item['order_number'] : null;
|
160 |
-
$order_number_formatted = (!empty($item['order_number_formatted']) ) ? $item['order_number_formatted'] : $order_number;
|
161 |
-
$WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> Row %s - preparing for import.', 'order-import-export-for-woocommerce'), $row));
|
162 |
-
// validate the supplied formatted order number/order number
|
163 |
-
if (is_numeric($order_number_formatted) && !$order_number)
|
164 |
-
$order_number = $order_number_formatted; // use formatted for underlying order number if possible
|
165 |
-
if ($order_number && !is_numeric($order_number)) {
|
166 |
-
$WF_CSV_Order_Import->add_import_result('skipped', sprintf(__('> > Skipped. Order number field must be an integer: %s.', 'order-import-export-for-woocommerce'), $order_number));
|
167 |
-
$WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Order number field must be an integer: %s.', 'order-import-export-for-woocommerce'), $order_number));
|
168 |
-
$skipped++;
|
169 |
-
unset($item);
|
170 |
-
return;
|
171 |
-
}
|
172 |
-
if ($order_number_formatted && !$order_number) {
|
173 |
-
$WF_CSV_Order_Import->add_import_result('skipped', __('Skipped. Formatted order number provided but no numerical order number, see the documentation for further details.', 'order-import-export-for-woocommerce'));
|
174 |
-
$WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', __('> > Skipped. Formatted order number provided but no numerical order number, see the documentation for further details.', 'order-import-export-for-woocommerce'));
|
175 |
-
$skipped++;
|
176 |
-
unset($item);
|
177 |
-
return;
|
178 |
-
}
|
179 |
-
} else {
|
180 |
-
$order_number_formatted = !empty($item['order_id']) ? $item['order_id'] : 0;
|
181 |
-
$order_number = (!empty($item['order_number']) ? $item['order_number'] : ( is_numeric($order_number_formatted) ? $order_number_formatted : 0 ) );
|
182 |
-
}
|
183 |
-
if ($order_number_formatted) {
|
184 |
-
// verify that this order number isn't already in use
|
185 |
-
$query_args = array(
|
186 |
-
'numberposts' => 1,
|
187 |
-
'meta_key' => apply_filters('woocommerce_order_number_formatted_meta_name', '_order_number_formatted'),
|
188 |
-
'meta_value' => $order_number_formatted,
|
189 |
-
'post_type' => 'shop_order',
|
190 |
-
'post_status' => array_keys(wc_get_order_statuses()),
|
191 |
-
'fields' => 'ids',
|
192 |
-
);
|
193 |
-
$order_id = 0;
|
194 |
-
$orders = get_posts($query_args);
|
195 |
-
if (!empty($orders)) {
|
196 |
-
list( $order_id ) = get_posts($query_args);
|
197 |
-
}
|
198 |
-
$order_id = apply_filters('woocommerce_find_order_by_order_number', $order_id, $order_number_formatted);
|
199 |
-
if ($order_id) {
|
200 |
-
// skip if order ID already exist.
|
201 |
-
$WF_CSV_Order_Import->add_import_result('skipped', sprintf(__('Skipped. Order %s already exists.', 'order-import-export-for-woocommerce'), $order_number_formatted));
|
202 |
-
$WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Order %s already exists.', 'order-import-export-for-woocommerce'), $order_number_formatted));
|
203 |
-
$skipped++;
|
204 |
-
unset($item);
|
205 |
-
return;
|
206 |
-
}
|
207 |
-
}
|
208 |
-
// handle the special (optional) customer_user field
|
209 |
-
if (isset($item['customer_id']) && $item['customer_id']) {
|
210 |
-
// attempt to find the customer user
|
211 |
-
$found_customer = false;
|
212 |
-
if (is_int($item['customer_id'])) {
|
213 |
-
$found_customer = get_user_by('id', $item['customer_id']);
|
214 |
-
if (!$found_customer) {
|
215 |
-
$WF_CSV_Order_Import->add_import_result('skipped', sprintf(__('Skipped. Unknown order status (%s).', 'order-import-export-for-woocommerce'), $item['status']));
|
216 |
-
$WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Cannot find customer with id %s.', 'order-import-export-for-woocommerce'), $item['customer_id']));
|
217 |
-
$skipped++;
|
218 |
-
unset($item);
|
219 |
-
return;
|
220 |
-
}
|
221 |
-
} elseif (is_email($item['customer_id'])) {
|
222 |
-
// check by email
|
223 |
-
$found_customer = email_exists($item['customer_id']);
|
224 |
-
}
|
225 |
-
if (!$found_customer) {
|
226 |
-
$found_customer = username_exists($item['customer_id']);
|
227 |
-
}
|
228 |
-
if (!$found_customer) {
|
229 |
-
// guest checkout
|
230 |
-
$item['customer_id'] = 0;
|
231 |
-
} else {
|
232 |
-
$item['customer_id'] = $found_customer; // user id
|
233 |
-
}
|
234 |
-
} elseif ($csv_export_file && isset($item['billing_email']) && $item['billing_email']) {
|
235 |
-
// see if we can link to user by billing email id
|
236 |
-
$found_customer = email_exists($item['billing_email']);
|
237 |
-
if ($found_customer)
|
238 |
-
$item['customer_id'] = $found_customer;
|
239 |
-
else
|
240 |
-
$item['customer_id'] = 0; // guest checkout
|
241 |
-
} else {
|
242 |
-
// guest checkout
|
243 |
-
$item['customer_id'] = 0;
|
244 |
-
}
|
245 |
-
if (!empty($item['status'])) {
|
246 |
-
$order['status'] = $item['status'];
|
247 |
-
$found_status = false;
|
248 |
-
$available_statuses = array();
|
249 |
-
foreach ($shop_order_status as $status_slug => $status_name) {
|
250 |
-
if (0 == strcasecmp($status_slug, $item['status']))
|
251 |
-
$found_status = true;
|
252 |
-
$available_statuses[] = $status_slug;
|
253 |
-
}
|
254 |
-
if (!$found_status) {
|
255 |
-
$WF_CSV_Order_Import->add_import_result('skipped', sprintf(__('Skipped. Unknown order status (%s).', 'order-import-export-for-woocommerce'), $item['status']));
|
256 |
-
$WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Unknown order status %s (%s).', 'order-import-export-for-woocommerce'), $item['status'], implode($available_statuses, ', ')));
|
257 |
-
$skipped++;
|
258 |
-
unset($item);
|
259 |
-
return;
|
260 |
-
}
|
261 |
-
}
|
262 |
-
if (!empty($item['order_date'])){
|
263 |
-
$item['order_date'] = apply_filters('wt_change_date_format_befor_import', $item['order_date']);
|
264 |
-
if((get_option('date_format') == 'd/m/Y') && strstr($item['order_date'], '/')) {
|
265 |
-
$date_arr = explode(" ", trim($item['order_date']));
|
266 |
-
if(count($date_arr) <= 1){
|
267 |
-
$item['order_date'] = $item['order_date'].' 00:00:00';
|
268 |
-
}
|
269 |
-
$date = DateTime::createFromFormat('d/m/Y H:i:s', $item['order_date']);
|
270 |
-
if(!empty($date))
|
271 |
-
$item['order_date'] = $date->format('Y-m-d H:i:s');
|
272 |
-
}
|
273 |
-
$item['date'] = $item['order_date'];
|
274 |
-
} elseif (isset($item['order_date'])) {
|
275 |
-
$item['date'] = time();
|
276 |
-
}
|
277 |
-
if (!empty($item['date'])) {
|
278 |
-
if(preg_match("/^(\d{2})-(\d{2})-(\d{2}) (\d{1}|\d{2}):(\d{2})$/", $item['date'])){
|
279 |
-
$item['date'] = date_create_from_format('d-m-y H:i', $item['date']);
|
280 |
-
$item['date'] = date_format($item['date'], 'Y-m-d H:i:s');
|
281 |
-
}
|
282 |
-
if (false === ( $item['date'] = strtotime($item['date']) )) {
|
283 |
-
// invalid date format
|
284 |
-
$WF_CSV_Order_Import->add_import_result('skipped', __('Skipped. Invalid date format', 'order-import-export-for-woocommerce'));
|
285 |
-
$WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Invalid date format %s.', 'order-import-export-for-woocommerce'), $item['date']));
|
286 |
-
$skipped++;
|
287 |
-
unset($item);
|
288 |
-
return;
|
289 |
-
}
|
290 |
-
$order['date'] = $item['date'];
|
291 |
-
}
|
292 |
-
$order_notes = array();
|
293 |
-
if (!empty($item['order_notes'])) {
|
294 |
-
$order_notes = explode("||", $item['order_notes']);
|
295 |
-
}
|
296 |
-
// build the order data object
|
297 |
-
$order['order_id'] = !empty($item['order_id']) ? $item['order_id'] : null;
|
298 |
-
$order['order_comments'] = !empty($item['customer_note']) ? $item['customer_note'] : null;
|
299 |
-
$order['notes'] = $order_notes;
|
300 |
-
if (!is_null($order_number))
|
301 |
-
$order['order_number'] = $order_number; // optional order number, for convenience
|
302 |
-
if ($order_number_formatted)
|
303 |
-
$order['order_number_formatted'] = $order_number_formatted;
|
304 |
-
// totals
|
305 |
-
$order_tax = $order_shipping_tax = null;
|
306 |
-
// Get any known order meta fields, and default any missing ones to 0/null
|
307 |
-
// the provided shipping/payment method will be used as-is, and if found in the list of available ones, the respective titles will also be set
|
308 |
-
foreach ($this->order_meta_fields as $column) {
|
309 |
-
switch ($column) {
|
310 |
-
case 'shipping_method':
|
311 |
-
if(isset($item[$column])){
|
312 |
-
$value = $item[$column];
|
313 |
-
// look up shipping method by id or title
|
314 |
-
$shipping_method = isset($available_methods[$value]) ? $value : null;
|
315 |
-
if (!$shipping_method) {
|
316 |
-
// try by title
|
317 |
-
foreach ($available_methods as $method) {
|
318 |
-
if (0 === strcasecmp($method->title, $value)) {
|
319 |
-
$shipping_method = $method->id;
|
320 |
-
break; // go with the first one we find
|
321 |
-
}
|
322 |
-
}
|
323 |
-
}
|
324 |
-
if ($shipping_method) {
|
325 |
-
//known shipping method found
|
326 |
-
$postmeta[] = array('key' => '_shipping_method', 'value' => $shipping_method);
|
327 |
-
$postmeta[] = array('key' => '_shipping_method_title', 'value' => $available_methods[$shipping_method]->title);
|
328 |
-
} elseif ($csv_export_file && $value) {
|
329 |
-
//Order CSV Export format, shipping method title with no corresponding shipping method type found, so just use the title
|
330 |
-
$postmeta[] = array('key' => '_shipping_method', 'value' => '');
|
331 |
-
$postmeta[] = array('key' => '_shipping_method_title', 'value' => $value);
|
332 |
-
} elseif ($value) {
|
333 |
-
//Shipping method but no title
|
334 |
-
$postmeta[] = array('key' => '_shipping_method', 'value' => $value);
|
335 |
-
$postmeta[] = array('key' => '_shipping_method_title', 'value' => '');
|
336 |
-
} else {
|
337 |
-
//none
|
338 |
-
$postmeta[] = array('key' => '_shipping_method', 'value' => '');
|
339 |
-
$postmeta[] = array('key' => '_shipping_method_title', 'value' => '');
|
340 |
-
}
|
341 |
-
}
|
342 |
-
break;
|
343 |
-
case 'payment_method':
|
344 |
-
if (isset($item[$column])) {
|
345 |
-
$value = $item[$column];
|
346 |
-
// look up shipping method by id or title
|
347 |
-
$payment_method = isset($available_gateways[$value]) ? $value : null;
|
348 |
-
if (!$payment_method) {
|
349 |
-
// try by title
|
350 |
-
foreach ($available_gateways as $method) {
|
351 |
-
if (0 === strcasecmp($method->title, $value)) {
|
352 |
-
$payment_method = $method->id;
|
353 |
-
break; // go with the first one we find
|
354 |
-
}
|
355 |
-
}
|
356 |
-
}
|
357 |
-
if ($payment_method) {
|
358 |
-
//Known payment method found
|
359 |
-
$postmeta[] = array('key' => '_payment_method', 'value' => $payment_method);
|
360 |
-
$postmeta[] = array('key' => '_payment_method_title', 'value' => $available_gateways[$payment_method]->title);
|
361 |
-
} elseif ($csv_export_file && $value) {
|
362 |
-
//Order CSV Export format, payment method title with no corresponding payments method type found, so just use the title
|
363 |
-
$postmeta[] = array('key' => '_payment_method', 'value' => '');
|
364 |
-
$postmeta[] = array('key' => '_payment_method_title', 'value' => $value);
|
365 |
-
} elseif ($value) {
|
366 |
-
//payment method but no title
|
367 |
-
$postmeta[] = array('key' => '_payment_method', 'value' => $value);
|
368 |
-
$postmeta[] = array('key' => '_payment_method_title', 'value' => '');
|
369 |
-
} else {
|
370 |
-
//none
|
371 |
-
$postmeta[] = array('key' => '_payment_method', 'value' => '');
|
372 |
-
$postmeta[] = array('key' => '_payment_method_title', 'value' => '');
|
373 |
-
}
|
374 |
-
}
|
375 |
-
break;
|
376 |
-
// handle numerics
|
377 |
-
case 'order_shipping': // legacy
|
378 |
-
case 'shipping_total':
|
379 |
-
if (isset($item[$column])) {
|
380 |
-
$order_shipping = $item[$column]; // save the order shipping total for later use
|
381 |
-
$postmeta[] = array('key' => '_order_shipping', 'value' => number_format((float) $order_shipping, 2, '.', ''));
|
382 |
-
}
|
383 |
-
break;
|
384 |
-
case 'order_shipping_tax': // legacy
|
385 |
-
case 'shipping_tax_total':
|
386 |
-
// ignore blanks but allow zeroes
|
387 |
-
if (isset($item[$column]) && is_numeric($item[$column])) {
|
388 |
-
$order_shipping_tax = $item[$column];
|
389 |
-
}
|
390 |
-
break;
|
391 |
-
case 'order_tax': // legacy
|
392 |
-
case 'tax_total':
|
393 |
-
// ignore blanks but allow zeroes
|
394 |
-
if (isset($item[$column]) && is_numeric($item[$column])) {
|
395 |
-
$order_tax = $item[$column];
|
396 |
-
}
|
397 |
-
break;
|
398 |
-
case 'order_discount':
|
399 |
-
case 'cart_discount':
|
400 |
-
case 'order_total':
|
401 |
-
if (isset($item[$column])) {
|
402 |
-
$value = $item[$column];
|
403 |
-
$postmeta[] = array('key' => '_' . $column, 'value' => number_format((float) $value, 2, '.', ''));
|
404 |
-
}
|
405 |
-
break;
|
406 |
-
|
407 |
-
case 'billing_country':
|
408 |
-
case 'shipping_country':
|
409 |
-
if (isset($item[$column])) {
|
410 |
-
$value = $item[$column];
|
411 |
-
// support country name or code by converting to code
|
412 |
-
$country_code = array_search($value, WC()->countries->countries);
|
413 |
-
if ($country_code)
|
414 |
-
$value = $country_code;
|
415 |
-
$postmeta[] = array('key' => '_' . $column, 'value' => $value);
|
416 |
-
}
|
417 |
-
break;
|
418 |
-
case 'Download Permissions Granted':
|
419 |
-
case 'download_permissions_granted':
|
420 |
-
if (isset($item['download_permissions_granted'])) {
|
421 |
-
$postmeta[] = array('key' => '_download_permissions_granted', 'value' => $item['download_permissions_granted']);
|
422 |
-
}
|
423 |
-
break;
|
424 |
-
case 'download_permissions':
|
425 |
-
if (isset($item['download_permissions'])) {
|
426 |
-
$postmeta[] = array('key' => '_download_permissions_granted', 'value' => $item['download_permissions']);
|
427 |
-
$postmeta[] = array('key' => '_download_permissions', 'value' => $item['download_permissions']);
|
428 |
-
}
|
429 |
-
break;
|
430 |
-
default:
|
431 |
-
if (isset($item[$column])){
|
432 |
-
$postmeta[] = array('key' => '_' . $column, 'value' => $item[$column]);
|
433 |
-
}
|
434 |
-
}
|
435 |
-
}
|
436 |
-
if(isset($item['paid_date']) && !empty($item['paid_date'])){
|
437 |
-
$postmeta[] = array('key' => '_date_paid', 'value' => strtotime($item['paid_date']));
|
438 |
-
}
|
439 |
-
if(isset($item['completed_date']) && !empty($item['completed_date'])){
|
440 |
-
$postmeta[] = array('key' => '_date_completed', 'value' => strtotime($item['completed_date']));
|
441 |
-
}
|
442 |
-
|
443 |
-
if (!empty($item['customer_id']))
|
444 |
-
$postmeta[] = array('key' => '_customer_user', 'value' => $item['customer_id']);
|
445 |
-
$order_shipping_methods = array();
|
446 |
-
$_shipping_methods = array();
|
447 |
-
// pre WC 2.1 format of a single shipping method, left for backwards compatibility of import files
|
448 |
-
if (isset($item['shipping_method']) && $item['shipping_method']) {
|
449 |
-
// collect the shipping method id/cost
|
450 |
-
$_shipping_methods[] = array(
|
451 |
-
$item['shipping_method'],
|
452 |
-
isset($item['shipping_cost']) ? $item['shipping_cost'] : null
|
453 |
-
);
|
454 |
-
}
|
455 |
-
// collect any additional shipping methods
|
456 |
-
$i = null;
|
457 |
-
if (isset($item['shipping_method_1'])) {
|
458 |
-
$i = 1;
|
459 |
-
} elseif (isset($item['shipping_method_2'])) {
|
460 |
-
$i = 2;
|
461 |
-
}
|
462 |
-
if (!is_null($i)) {
|
463 |
-
while (!empty($item['shipping_method_' . $i])) {
|
464 |
-
$_shipping_methods[] = array(
|
465 |
-
$item['shipping_method_' . $i],
|
466 |
-
isset($item['shipping_cost_' . $i]) ? $item['shipping_cost_' . $i] : null
|
467 |
-
);
|
468 |
-
$i++;
|
469 |
-
}
|
470 |
-
}
|
471 |
-
|
472 |
-
// if the order shipping total wasn't set, calculate it
|
473 |
-
if (!isset($order_shipping)) {
|
474 |
-
$order_shipping = 0;
|
475 |
-
foreach ($_shipping_methods as $_shipping_method) {
|
476 |
-
$order_shipping += $_shipping_method[1];
|
477 |
-
}
|
478 |
-
$postmeta[] = array('key' => '_order_shipping' . $column, 'value' => number_format((float) $order_shipping, 2, '.', ''));
|
479 |
-
} elseif (isset($order_shipping) && 1 == count($_shipping_methods) && is_null($_shipping_methods[0][1])) {
|
480 |
-
// special case: if there was a total order shipping but no cost for the single shipping method, use the total shipping for the order shipping line item
|
481 |
-
$_shipping_methods[0][1] = $order_shipping;
|
482 |
-
}
|
483 |
-
foreach ($_shipping_methods as $_shipping_method) {
|
484 |
-
// look up shipping method by id or title
|
485 |
-
$shipping_method = isset($available_methods[$_shipping_method[0]]) ? $_shipping_method[0] : null;
|
486 |
-
if (!$shipping_method) {
|
487 |
-
// try by title
|
488 |
-
foreach ($available_methods as $method) {
|
489 |
-
if (0 === strcasecmp($method->title, $_shipping_method[0])) {
|
490 |
-
$shipping_method = $method->id;
|
491 |
-
break; // go with the first one we find
|
492 |
-
}
|
493 |
-
}
|
494 |
-
}
|
495 |
-
if ($shipping_method) {
|
496 |
-
//Known shipping method found
|
497 |
-
$order_shipping_methods[] = array('method_id' => $shipping_method, 'cost' => $_shipping_method[1], 'title' => $available_methods[$shipping_method]->title);
|
498 |
-
} elseif ($csv_export_file && $_shipping_method[0]) {
|
499 |
-
//Order CSV Export format, shipping method title with no corresponding shipping method type found, so just use the title
|
500 |
-
$order_shipping_methods[] = array('method_id' => '', 'cost' => $_shipping_method[1], 'title' => $_shipping_method[0]);
|
501 |
-
} elseif ($_shipping_method[0]) {
|
502 |
-
//shipping method but no title
|
503 |
-
$order_shipping_methods[] = array('method_id' => $_shipping_method[0], 'cost' => $_shipping_method[1], 'title' => '');
|
504 |
-
}
|
505 |
-
}
|
506 |
-
$order_items = array();
|
507 |
-
if ($csv_export_file) {
|
508 |
-
// standard format
|
509 |
-
if (isset($item['line_item_1']) && !empty($item['line_item_1'])) {
|
510 |
-
// one or more order items
|
511 |
-
$i = 1;
|
512 |
-
while (isset($item['line_item_' . $i]) && !empty($item['line_item_' . $i])) {
|
513 |
-
// $_item_meta = preg_split("~\\\\.(*SKIP)(*FAIL)|\|~s", $item['line_item_' . $i]);
|
514 |
-
$_item_meta = array();
|
515 |
-
if ($item['line_item_' . $i] && empty($_item_meta)) {
|
516 |
-
$_item_meta = explode('|', $item['line_item_' . $i]);
|
517 |
-
}
|
518 |
-
|
519 |
-
$all_tax_data = array();
|
520 |
-
foreach ($_item_meta as $item_key => $item_value) {
|
521 |
-
|
522 |
-
$data_exploded = explode(":", $item_value);
|
523 |
-
if($data_exploded[0] == 'tax_total' && isset($data_exploded[1])&&!empty($data_exploded[1])){
|
524 |
-
$item_taxs = explode(",", $data_exploded[1]);
|
525 |
-
$tax_arr = array();
|
526 |
-
foreach ($item_taxs as $tax_key => $tax_value) {
|
527 |
-
$tax_details = explode("=", $tax_value);
|
528 |
-
$rate_id = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate_id FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_name = %s", $tax_details[0] ) );
|
529 |
-
$tax_arr[intval($rate_id)] = $tax_details[1];
|
530 |
-
}
|
531 |
-
$all_tax_data['total'] = $tax_arr;
|
532 |
-
unset($_item_meta[$item_key]);
|
533 |
-
}
|
534 |
-
if($data_exploded[0] == 'tax_subtotal'&& isset($data_exploded[1])&&!empty($data_exploded[1])){
|
535 |
-
$tax_arr = array();
|
536 |
-
$item_taxs_subtotal = explode(",", $data_exploded[1]);
|
537 |
-
foreach ($item_taxs_subtotal as $tax_stkey => $tax_stvalue) {
|
538 |
-
$st_tax_details = explode("=", $tax_stvalue);
|
539 |
-
$rate_id = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate_id FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_name = %s", $st_tax_details[0] ) );
|
540 |
-
$tax_arr[intval($rate_id)] = $st_tax_details[1];
|
541 |
-
}
|
542 |
-
$all_tax_data['subtotal'] = $tax_arr;
|
543 |
-
unset($_item_meta[$item_key]);
|
544 |
-
}
|
545 |
-
|
546 |
-
}
|
547 |
-
$name = array_shift($_item_meta);
|
548 |
-
$name = substr($name, strpos($name, ":") + 1);
|
549 |
-
$unknown_product_name = $name;
|
550 |
-
$product_identifier_by_id = array_shift($_item_meta); // product_id:id
|
551 |
-
$product_identifier_by_sku = array_shift($_item_meta); // sku
|
552 |
-
$qty = array_shift($_item_meta);
|
553 |
-
$qty = substr($qty, strpos($qty, ":") + 1);
|
554 |
-
$total = array_shift($_item_meta);
|
555 |
-
$total = substr($total, strpos($total, ":") + 1);
|
556 |
-
$sub_total = array_shift($_item_meta);
|
557 |
-
$sub_total = substr($sub_total, strpos($sub_total, ":") + 1);
|
558 |
-
$tax = array_shift($_item_meta);
|
559 |
-
$tax = substr($tax, strpos($tax, ":") + 1);
|
560 |
-
$tax_data = array_shift($_item_meta);
|
561 |
-
$tax_data = $all_tax_data;
|
562 |
-
// find by id
|
563 |
-
if (false !== strpos($product_identifier_by_id, 'product_id:')) {
|
564 |
-
// product by product_id
|
565 |
-
$product_id = substr($product_identifier_by_id, 11);
|
566 |
-
|
567 |
-
// not a product
|
568 |
-
if (!in_array(get_post_type($product_id), array('product', 'product_variation'))) {
|
569 |
-
$product_id = '';
|
570 |
-
}
|
571 |
-
}
|
572 |
-
if (!$product_id) {
|
573 |
-
// find by sku
|
574 |
-
$product_sku = substr($product_identifier_by_sku, strpos($product_identifier_by_sku, ":") + 1);
|
575 |
-
if ($product_sku)
|
576 |
-
$product_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value=%s LIMIT 1", $product_sku));
|
577 |
-
else
|
578 |
-
$product_id = '';
|
579 |
-
}
|
580 |
-
if (!$allow_unknown_products && !$product_id) {
|
581 |
-
// unknown product
|
582 |
-
$WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Unknown order item: %s.', 'order-import-export-for-woocommerce'), $product_identifier));
|
583 |
-
$skipped++;
|
584 |
-
$i++;
|
585 |
-
continue; // break outer loop
|
586 |
-
}
|
587 |
-
// get any additional item meta
|
588 |
-
$item_meta = array();
|
589 |
-
foreach ($_item_meta as $pair) {
|
590 |
-
// replace any escaped pipes
|
591 |
-
$pair = str_replace('\|', '|', $pair);
|
592 |
-
// find the first ':' and split into name-value
|
593 |
-
$split = strpos($pair, ':');
|
594 |
-
$name = substr($pair, 0, $split);
|
595 |
-
$value = substr($pair, $split + 1);
|
596 |
-
$item_meta[$name] = $value;
|
597 |
-
}
|
598 |
-
$order_items[] = array('product_id' => $product_id, 'qty' => $qty, 'total' => $total,'sub_total' => $sub_total,'tax' => $tax, 'tax_data' => $tax_data, 'meta' => $item_meta, 'unknown_product_name' => $unknown_product_name);
|
599 |
-
$i++;
|
600 |
-
}
|
601 |
-
}
|
602 |
-
} else {
|
603 |
-
//CSV Order Export format
|
604 |
-
$sku = $item['item_sku'];
|
605 |
-
$qty = $item['item_amount'];
|
606 |
-
$total = $item['row_price'];
|
607 |
-
if (!$sku || !$qty || !is_numeric($total)) {
|
608 |
-
// invalid item
|
609 |
-
$WF_CSV_Order_Import->add_import_result('skipped', __('skipped. Missing SKU, quantity or total', 'order-import-export-for-woocommerce'));
|
610 |
-
$WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Row %d - %s - skipped. Missing SKU, quantity or total', 'order-import-export-for-woocommerce'), $row, $item['order_id']));
|
611 |
-
$skipped++;
|
612 |
-
unset($item);
|
613 |
-
return; // break outer loop
|
614 |
-
}
|
615 |
-
// find by sku
|
616 |
-
$product_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value=%s LIMIT 1", $sku));
|
617 |
-
if (!$product_id) {
|
618 |
-
// unknown product
|
619 |
-
$WF_CSV_Order_Import->add_import_result('skipped', __('skipped. Unknown order item', 'order-import-export-for-woocommerce'));
|
620 |
-
$WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Row %d - %s - skipped. Unknown order item: %s.', 'order-import-export-for-woocommerce'), $row, $item['order_id'], $sku));
|
621 |
-
$skipped++;
|
622 |
-
unset($item);
|
623 |
-
return; // break outer loop
|
624 |
-
}
|
625 |
-
$order_items[] = array('product_id' => $product_id, 'qty' => $qty, 'total' => $total);
|
626 |
-
}
|
627 |
-
|
628 |
-
// standard format
|
629 |
-
$coupon_item = array();
|
630 |
-
|
631 |
-
if(isset($item['coupon_items']) && !empty($item['coupon_items'])){
|
632 |
-
$coupon_item = explode(';', $item['coupon_items']);
|
633 |
-
}
|
634 |
-
|
635 |
-
//added since refund not importing
|
636 |
-
$refund_item = array();
|
637 |
-
if(isset($item['refund_items']) && !empty($item['refund_items'])){
|
638 |
-
$refund_item = explode(';', $item['refund_items']);
|
639 |
-
}
|
640 |
-
|
641 |
-
$tax_items = array();
|
642 |
-
// standard tax item format which supports multiple tax items in numbered columns containing a pipe-delimated, colon-labeled format
|
643 |
-
if (isset($item['tax_items']) && !empty($item['tax_items'])) {
|
644 |
-
// one or more order tax items
|
645 |
-
// get the first tax item
|
646 |
-
$tax_item = explode(';', $item['tax_items']);
|
647 |
-
// $tax_amount_sum = $shipping_tax_amount_sum = 0;
|
648 |
-
foreach ($tax_item as $tax) {
|
649 |
-
$tax_item_data = array();
|
650 |
-
// turn "label: Tax | tax_amount: 10" into an associative array
|
651 |
-
foreach (explode('|', $tax) as $piece) {
|
652 |
-
list( $name, $value ) = explode(':', $piece);
|
653 |
-
$tax_item_data[trim($name)] = trim($value);
|
654 |
-
}
|
655 |
-
// default rate id to 0 if not set
|
656 |
-
if (!isset($tax_item_data['rate_id'])) {
|
657 |
-
$tax_item_data['rate_id'] = 0;
|
658 |
-
}
|
659 |
-
// have a tax amount or shipping tax amount
|
660 |
-
if (isset($tax_item_data['total']) || isset($tax_item_data['shipping_tax_amount'])) {
|
661 |
-
// try and look up rate id by label if needed
|
662 |
-
if (isset($tax_item_data['label']) && $tax_item_data['label'] && !$tax_item_data['rate_id']) {
|
663 |
-
foreach ($tax_rates as $tax_rate) {
|
664 |
-
if (0 === strcasecmp($tax_rate->tax_rate_name, $tax_item_data['label'])) {
|
665 |
-
// found the tax by label
|
666 |
-
$tax_item_data['rate_id'] = $tax_rate->tax_rate_id;
|
667 |
-
break;
|
668 |
-
}
|
669 |
-
}
|
670 |
-
}
|
671 |
-
// check for a rate being specified which does not exist, and clear it out (technically an error?)
|
672 |
-
if ($tax_item_data['rate_id'] && !isset($tax_rates[$tax_item_data['rate_id']])) {
|
673 |
-
$tax_item_data['rate_id'] = 0;
|
674 |
-
}
|
675 |
-
// default label of 'Tax' if not provided
|
676 |
-
if (!isset($tax_item_data['label']) || !$tax_item_data['label']) {
|
677 |
-
$tax_item_data['label'] = 'Tax';
|
678 |
-
}
|
679 |
-
// default tax amounts to 0 if not set
|
680 |
-
if (!isset($tax_item_data['total'])) {
|
681 |
-
$tax_item_data['total'] = 0;
|
682 |
-
}
|
683 |
-
if (!isset($tax_item_data['shipping_tax_amount'])) {
|
684 |
-
$tax_item_data['shipping_tax_amount'] = 0;
|
685 |
-
}
|
686 |
-
// handle compound flag by using the defined tax rate value (if any)
|
687 |
-
if (!isset($tax_item_data['tax_rate_compound'])) {
|
688 |
-
$tax_item_data['tax_rate_compound'] = '';
|
689 |
-
if ($tax_item_data['rate_id']) {
|
690 |
-
$tax_item_data['tax_rate_compound'] = $tax_rates[$tax_item_data['rate_id']]->tax_rate_compound;
|
691 |
-
}
|
692 |
-
}
|
693 |
-
$tax_items[] = array(
|
694 |
-
'title' => $tax_item_data['code'],
|
695 |
-
'rate_id' => $tax_item_data['rate_id'],
|
696 |
-
'label' => $tax_item_data['label'],
|
697 |
-
'compound' => $tax_item_data['tax_rate_compound'],
|
698 |
-
'tax_amount' => $tax_item_data['total'],
|
699 |
-
'shipping_tax_amount' => $tax_item_data['shipping_tax_amount'],
|
700 |
-
);
|
701 |
-
}
|
702 |
-
}
|
703 |
-
}
|
704 |
-
// add the order tax totals to the order meta
|
705 |
-
$postmeta[] = array('key' => '_order_tax', 'value' => number_format((float) $order_tax, 2, '.', ''));
|
706 |
-
$postmeta[] = array('key' => '_order_shipping_tax', 'value' => number_format((float) $order_shipping_tax, 2, '.', ''));
|
707 |
-
|
708 |
-
// fee items
|
709 |
-
$fee_items = $fee_line_items = array();
|
710 |
-
if (isset($item['fee_items']) && !empty($item['fee_items'])) {
|
711 |
-
$fee_line_items = explode(';', $item['fee_items']);
|
712 |
-
|
713 |
-
$fee_item_data = array();
|
714 |
-
foreach ($fee_line_items as $fee_line_item) {
|
715 |
-
foreach (explode('|', $fee_line_item) as $piece) {
|
716 |
-
list( $name, $value ) = explode(':', $piece);
|
717 |
-
$fee_item_data[trim($name)] = trim($value);
|
718 |
-
}
|
719 |
-
|
720 |
-
if (!isset($fee_item_data['name'])) {
|
721 |
-
$fee_item_data['name'] = 'fee';
|
722 |
-
}
|
723 |
-
|
724 |
-
if (!isset($fee_item_data['total'])) {
|
725 |
-
$fee_item_data['total'] = 0;
|
726 |
-
}
|
727 |
-
if (!isset($fee_item_data['tax'])) {
|
728 |
-
$fee_item_data['tax'] = 0;
|
729 |
-
}
|
730 |
-
|
731 |
-
$fee_items[] = array(
|
732 |
-
'name' => $fee_item_data['name'],
|
733 |
-
'total' => $fee_item_data['total'],
|
734 |
-
'tax' => $fee_item_data['tax'],
|
735 |
-
);
|
736 |
-
}
|
737 |
-
}
|
738 |
-
|
739 |
-
$shipping_items = $shipping_line_items = array();
|
740 |
-
if(isset($item['shipping_items']) && !empty($item['shipping_items'])){
|
741 |
-
$shipping_line_items = explode('|', $item['shipping_items']);
|
742 |
-
$items = array_shift($shipping_line_items);
|
743 |
-
$items = substr($items, strpos($items, ":") + 1);
|
744 |
-
$method_id = array_shift($shipping_line_items);
|
745 |
-
$method_id = substr($method_id, strpos($method_id, ":") + 1);
|
746 |
-
$taxes = array_shift($shipping_line_items);
|
747 |
-
$taxes = substr($taxes, strpos($taxes, ":") + 1);
|
748 |
-
|
749 |
-
$shipping_items = array(
|
750 |
-
'Items' => $items,
|
751 |
-
'method_id' => $method_id,
|
752 |
-
'taxes' => $taxes
|
753 |
-
);
|
754 |
-
}
|
755 |
-
|
756 |
-
if ($order) {
|
757 |
-
$order['postmeta'] = $postmeta;
|
758 |
-
$order['order_items'] = $order_items;
|
759 |
-
$order['coupon_items'] = $coupon_item;
|
760 |
-
$order['refund_items'] = $refund_item;
|
761 |
-
$order['order_shipping'] = $order_shipping_methods;
|
762 |
-
$order['tax_items'] = $tax_items;
|
763 |
-
$order['fee_items'] = $fee_items;
|
764 |
-
$order['shipping_items'] = $shipping_items;
|
765 |
-
// the order array will now contain the necessary name-value pairs for the wp_posts table, and also any meta data in the 'postmeta' array
|
766 |
-
$results[] = $order;
|
767 |
-
}
|
768 |
-
// Result
|
769 |
-
return array(
|
770 |
-
$this->post_type => $results,
|
771 |
-
'skipped' => $skipped,
|
772 |
-
);
|
773 |
-
}
|
774 |
-
|
775 |
-
private function wc_get_order_statuses_neat() {
|
776 |
-
$order_statuses = array();
|
777 |
-
foreach (wc_get_order_statuses() as $slug => $name) {
|
778 |
-
$order_statuses[preg_replace('/^wc-/', '', $slug)] = $name;
|
779 |
-
}
|
780 |
-
return $order_statuses;
|
781 |
-
}
|
782 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/importer/class-wf-orderimpexpcsv-importer.php
DELETED
@@ -1,41 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
3 |
-
exit;
|
4 |
-
}
|
5 |
-
|
6 |
-
class WF_OrderImpExpCsv_Importer {
|
7 |
-
|
8 |
-
/**
|
9 |
-
* Order Exporter Tool
|
10 |
-
*/
|
11 |
-
public static function load_wp_importer() {
|
12 |
-
// Load Importer API
|
13 |
-
require_once ABSPATH . 'wp-admin/includes/import.php';
|
14 |
-
|
15 |
-
if ( ! class_exists( 'WP_Importer' ) ) {
|
16 |
-
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
|
17 |
-
if ( file_exists( $class_wp_importer ) ) {
|
18 |
-
require $class_wp_importer;
|
19 |
-
}
|
20 |
-
}
|
21 |
-
}
|
22 |
-
|
23 |
-
/**
|
24 |
-
* Order Importer Tool
|
25 |
-
*/
|
26 |
-
public static function order_importer() {
|
27 |
-
if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
|
28 |
-
return;
|
29 |
-
}
|
30 |
-
|
31 |
-
self::load_wp_importer();
|
32 |
-
|
33 |
-
// includes
|
34 |
-
require_once 'class-wf-orderimpexpcsv-order-import.php';
|
35 |
-
require_once 'class-wf-csv-parser.php';
|
36 |
-
|
37 |
-
// Dispatch
|
38 |
-
$GLOBALS['WF_CSV_Order_Import'] = new WF_OrderImpExpCsv_Order_Import();
|
39 |
-
$GLOBALS['WF_CSV_Order_Import'] ->dispatch();
|
40 |
-
}
|
41 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/importer/class-wf-orderimpexpcsv-order-import.php
DELETED
@@ -1,962 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WordPress Importer class for managing the import process of a CSV file
|
4 |
-
*
|
5 |
-
* @package WordPress
|
6 |
-
* @subpackage Importer
|
7 |
-
*/
|
8 |
-
if (!class_exists('WP_Importer'))
|
9 |
-
return;
|
10 |
-
|
11 |
-
class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
|
12 |
-
|
13 |
-
var $id;
|
14 |
-
var $file_url;
|
15 |
-
var $delimiter;
|
16 |
-
var $merge_empty_cells;
|
17 |
-
// mappings from old information to new
|
18 |
-
var $processed_terms = array();
|
19 |
-
var $processed_posts = array();
|
20 |
-
var $merged = 0;
|
21 |
-
var $skipped = 0;
|
22 |
-
var $imported = 0;
|
23 |
-
var $errored = 0;
|
24 |
-
// Results
|
25 |
-
var $import_results = array();
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Constructor
|
29 |
-
*/
|
30 |
-
public function __construct() {
|
31 |
-
if (WC()->version < '2.7.0') {
|
32 |
-
$this->log = new WC_Logger();
|
33 |
-
} else {
|
34 |
-
$this->log = wc_get_logger();
|
35 |
-
}
|
36 |
-
$this->import_page = 'woocommerce_wf_order_csv';
|
37 |
-
$this->file_url_import_enabled = apply_filters('woocommerce_csv_product_file_url_import_enabled', true);
|
38 |
-
}
|
39 |
-
|
40 |
-
/**
|
41 |
-
* Registered callback function for the WordPress Importer
|
42 |
-
*
|
43 |
-
* Manages the three separate stages of the CSV import process
|
44 |
-
*/
|
45 |
-
public function dispatch() {
|
46 |
-
global $woocommerce, $wpdb;
|
47 |
-
|
48 |
-
if (!empty($_POST['delimiter'])) {
|
49 |
-
$this->delimiter = stripslashes(trim($_POST['delimiter']));
|
50 |
-
} else if (!empty($_GET['delimiter'])) {
|
51 |
-
$this->delimiter = stripslashes(trim($_GET['delimiter']));
|
52 |
-
}
|
53 |
-
|
54 |
-
if (!$this->delimiter)
|
55 |
-
$this->delimiter = ',';
|
56 |
-
|
57 |
-
if (!empty($_POST['merge_empty_cells']) || !empty($_GET['merge_empty_cells'])) {
|
58 |
-
$this->merge_empty_cells = 1;
|
59 |
-
} else {
|
60 |
-
$this->merge_empty_cells = 0;
|
61 |
-
}
|
62 |
-
|
63 |
-
$step = empty($_GET['step']) ? 0 : absint( $_GET['step']);
|
64 |
-
|
65 |
-
switch ($step) {
|
66 |
-
case 0 :
|
67 |
-
$this->header();
|
68 |
-
$this->greet();
|
69 |
-
break;
|
70 |
-
case 1 :
|
71 |
-
$this->header();
|
72 |
-
|
73 |
-
check_admin_referer('import-upload');
|
74 |
-
|
75 |
-
if (!empty($_GET['file_url']))
|
76 |
-
$this->file_url = esc_url_raw($_GET['file_url']);
|
77 |
-
if (!empty($_GET['file_id']))
|
78 |
-
$this->id = absint ($_GET['file_id']);
|
79 |
-
|
80 |
-
if (!empty($_GET['clearmapping']) || $this->handle_upload())
|
81 |
-
$this->import_options();
|
82 |
-
else
|
83 |
-
_e('Error with handle_upload!', 'order-import-export-for-woocommerce');
|
84 |
-
break;
|
85 |
-
case 2 :
|
86 |
-
$this->header();
|
87 |
-
|
88 |
-
check_admin_referer('import-woocommerce');
|
89 |
-
|
90 |
-
$this->id = absint( $_POST['import_id']);
|
91 |
-
|
92 |
-
if ($this->file_url_import_enabled)
|
93 |
-
$this->file_url = esc_url_raw($_POST['import_url']);
|
94 |
-
|
95 |
-
if ($this->id)
|
96 |
-
$file = get_attached_file($this->id);
|
97 |
-
else if ($this->file_url_import_enabled)
|
98 |
-
$file = ABSPATH . $this->file_url;
|
99 |
-
|
100 |
-
$file = str_replace("\\", "/", $file);
|
101 |
-
|
102 |
-
if ($file) {
|
103 |
-
$file_delimiter = $this->detectDelimiter($file);
|
104 |
-
if(!empty($file_delimiter) && ($file_delimiter != $this->delimiter)){
|
105 |
-
echo '<p class="error"><strong>' . __("Basic version supports only ',' as delimiter. Your file's delimiter seems to be unsupported.", 'users-customers-import-export-for-wp-woocommerce') . '</strong></p>';
|
106 |
-
break;
|
107 |
-
}
|
108 |
-
?>
|
109 |
-
<table id="import-progress" class="widefat_importer widefat">
|
110 |
-
<thead>
|
111 |
-
<tr>
|
112 |
-
<th class="status"> </th>
|
113 |
-
<th class="row"><?php _e('Row', 'order-import-export-for-woocommerce'); ?></th>
|
114 |
-
<th><?php _e('OrderID', 'order-import-export-for-woocommerce'); ?></th>
|
115 |
-
<th><?php _e('Order Status', 'order-import-export-for-woocommerce'); ?></th>
|
116 |
-
<th class="reason"><?php _e('Status Msg', 'order-import-export-for-woocommerce'); ?></th>
|
117 |
-
</tr>
|
118 |
-
</thead>
|
119 |
-
<tfoot>
|
120 |
-
<tr class="importer-loading">
|
121 |
-
<td colspan="5"></td>
|
122 |
-
</tr>
|
123 |
-
</tfoot>
|
124 |
-
<tbody></tbody>
|
125 |
-
</table>
|
126 |
-
<script type="text/javascript">
|
127 |
-
jQuery(document).ready(function($) {
|
128 |
-
if (! window.console) { window.console = function(){}; }
|
129 |
-
var processed_terms = [];
|
130 |
-
var processed_posts = [];
|
131 |
-
var i = 1;
|
132 |
-
var done_count = 0;
|
133 |
-
function import_rows(start_pos, end_pos) {
|
134 |
-
var data = {
|
135 |
-
action: 'woocommerce_csv_order_import_request',
|
136 |
-
file: '<?php echo addslashes($file); ?>',
|
137 |
-
delimiter: '<?php echo $this->delimiter; ?>',
|
138 |
-
merge_empty_cells: '<?php echo $this->merge_empty_cells; ?>',
|
139 |
-
start_pos: start_pos,
|
140 |
-
end_pos: end_pos,
|
141 |
-
wt_nonce : '<?php echo wp_create_nonce( WF_ORDER_IMP_EXP_ID )?>',
|
142 |
-
};
|
143 |
-
return $.ajax({
|
144 |
-
url: '<?php echo add_query_arg(array('import_page' => $this->import_page, 'step' => '3', 'merge' => !empty($_GET['merge']) ? '1' : '0'), admin_url('admin-ajax.php')); ?>',
|
145 |
-
data: data,
|
146 |
-
type: 'POST',
|
147 |
-
success: function(response) {
|
148 |
-
if (response) {
|
149 |
-
try {
|
150 |
-
// Get the valid JSON only from the returned string
|
151 |
-
if (response.indexOf("<!--WC_START-->") >= 0)
|
152 |
-
response = response.split("<!--WC_START-->")[1]; // Strip off before after WC_START
|
153 |
-
if (response.indexOf("<!--WC_END-->") >= 0)
|
154 |
-
response = response.split("<!--WC_END-->")[0]; // Strip off anything after WC_END
|
155 |
-
// Parse
|
156 |
-
var results = $.parseJSON(response);
|
157 |
-
if (results.error) {
|
158 |
-
$('#import-progress tbody').append('<tr id="row-' + i + '" class="error"><td class="status" colspan="5">' + results.error + '</td></tr>');
|
159 |
-
i++;
|
160 |
-
} else if (results.import_results && $(results.import_results).size() > 0) {
|
161 |
-
$.each(results.processed_terms, function(index, value) {
|
162 |
-
processed_terms.push(value);
|
163 |
-
});
|
164 |
-
$.each(results.processed_posts, function(index, value) {
|
165 |
-
processed_posts.push(value);
|
166 |
-
});
|
167 |
-
$(results.import_results).each(function(index, row) {
|
168 |
-
$('#import-progress tbody').append('<tr id="row-' + i + '" class="' + row['status'] + '"><td><mark class="result" title="' + row['status'] + '">' + row['status'] + '</mark></td><td class="row">' + i + '</td><td>' + row['order_number'] + '</td><td>' + row['post_id'] + ' - ' + row['post_title'] + '</td><td class="reason">' + row['reason'] + '</td></tr>');
|
169 |
-
i++;
|
170 |
-
});
|
171 |
-
}
|
172 |
-
} catch (err) {}
|
173 |
-
} else {
|
174 |
-
$('#import-progress tbody').append('<tr class="error"><td class="status" colspan="5">' + '<?php _e('AJAX Error', 'order-import-export-for-woocommerce'); ?>' + '</td></tr>');
|
175 |
-
}
|
176 |
-
var w = $(window);
|
177 |
-
var row = $("#row-" + (i - 1));
|
178 |
-
if (row.length) {
|
179 |
-
w.scrollTop(row.offset().top - (w.height() / 2));
|
180 |
-
}
|
181 |
-
done_count++;
|
182 |
-
$('body').trigger('woocommerce_csv_order_import_request_complete');
|
183 |
-
}
|
184 |
-
});
|
185 |
-
}
|
186 |
-
var rows = [];
|
187 |
-
<?php
|
188 |
-
$limit = apply_filters('woocommerce_csv_import_limit_per_request', 10);
|
189 |
-
$enc = mb_detect_encoding($file, 'UTF-8, ISO-8859-1', true);
|
190 |
-
if ($enc)
|
191 |
-
setlocale(LC_ALL, 'en_US.' . $enc);
|
192 |
-
@ini_set('auto_detect_line_endings', true);
|
193 |
-
$count = 0;
|
194 |
-
$previous_position = 0;
|
195 |
-
$position = 0;
|
196 |
-
$import_count = 0;
|
197 |
-
// Get CSV positions
|
198 |
-
if (( $handle = fopen($file, "r") ) !== FALSE) {
|
199 |
-
while (( $postmeta = fgetcsv($handle, 0, $this->delimiter) ) !== FALSE) {
|
200 |
-
$count++;
|
201 |
-
if ($count >= $limit) {
|
202 |
-
$previous_position = $position;
|
203 |
-
$position = ftell($handle);
|
204 |
-
$count = 0;
|
205 |
-
$import_count ++;
|
206 |
-
// Import rows between $previous_position $position
|
207 |
-
?>rows.push( [ <?php echo $previous_position; ?>, <?php echo $position; ?> ] ); <?php
|
208 |
-
}
|
209 |
-
}
|
210 |
-
// Remainder
|
211 |
-
if ($count > 0) {
|
212 |
-
?>rows.push( [ <?php echo $position; ?>, '' ] ); <?php
|
213 |
-
$import_count ++;
|
214 |
-
}
|
215 |
-
fclose($handle);
|
216 |
-
}
|
217 |
-
?>
|
218 |
-
var data = rows.shift();
|
219 |
-
var regen_count = 0;
|
220 |
-
import_rows( data[0], data[1] );
|
221 |
-
$('body').on( 'woocommerce_csv_order_import_request_complete', function() {
|
222 |
-
if ( done_count == <?php echo $import_count; ?> ) {
|
223 |
-
import_done();
|
224 |
-
} else {
|
225 |
-
// Call next request
|
226 |
-
data = rows.shift();
|
227 |
-
import_rows( data[0], data[1] );
|
228 |
-
}
|
229 |
-
} );
|
230 |
-
function import_done() {
|
231 |
-
var data = {
|
232 |
-
action: 'woocommerce_csv_order_import_request',
|
233 |
-
file: '<?php echo $file; ?>',
|
234 |
-
processed_terms: processed_terms,
|
235 |
-
processed_posts: processed_posts.toString(),
|
236 |
-
wt_nonce : '<?php echo wp_create_nonce( WF_ORDER_IMP_EXP_ID )?>',
|
237 |
-
};
|
238 |
-
$.ajax({
|
239 |
-
url: '<?php echo add_query_arg(array('import_page' => $this->import_page, 'step' => '4', 'merge' => !empty($_GET['merge']) ? 1 : 0), admin_url('admin-ajax.php')); ?>',
|
240 |
-
data: data,
|
241 |
-
type: 'POST',
|
242 |
-
success: function( response ) {
|
243 |
-
$('#import-progress tbody').append( '<tr class="complete"><td colspan="5">' + response + '</td></tr>' );
|
244 |
-
$('.importer-loading').hide();
|
245 |
-
}
|
246 |
-
});
|
247 |
-
}
|
248 |
-
});
|
249 |
-
</script>
|
250 |
-
<?php
|
251 |
-
} else {
|
252 |
-
echo '<p class="error">' . __('Error finding uploaded file!', 'order-import-export-for-woocommerce') . '</p>';
|
253 |
-
}
|
254 |
-
break;
|
255 |
-
case 3 :
|
256 |
-
$nonce = (isset($_POST['wt_nonce']) ? sanitize_text_field($_POST['wt_nonce']) : '');
|
257 |
-
if (!wp_verify_nonce($nonce, WF_ORDER_IMP_EXP_ID) || !WF_Order_Import_Export_CSV::hf_user_permission()) {
|
258 |
-
wp_die(__('Access Denied', 'order-import-export-for-woocommerce'));
|
259 |
-
}
|
260 |
-
$file = stripslashes( $_POST['file'] ); // Validating given path is valid path, not a URL
|
261 |
-
if (filter_var($file, FILTER_VALIDATE_URL)) {
|
262 |
-
die();
|
263 |
-
}
|
264 |
-
add_filter('http_request_timeout', array($this, 'bump_request_timeout'));
|
265 |
-
if (function_exists('gc_enable'))
|
266 |
-
gc_enable();
|
267 |
-
@set_time_limit(0);
|
268 |
-
@ob_flush();
|
269 |
-
@flush();
|
270 |
-
$wpdb->hide_errors();
|
271 |
-
$start_pos = isset($_POST['start_pos']) ? absint($_POST['start_pos']) : 0;
|
272 |
-
$end_pos = isset($_POST['end_pos']) ? absint($_POST['end_pos']) : '';
|
273 |
-
$position = $this->import_start($file, $start_pos, $end_pos);
|
274 |
-
$this->import();
|
275 |
-
$this->import_end();
|
276 |
-
$results = array();
|
277 |
-
$results['import_results'] = $this->import_results;
|
278 |
-
$results['processed_terms'] = $this->processed_terms;
|
279 |
-
$results['processed_posts'] = $this->processed_posts;
|
280 |
-
echo "<!--WC_START-->";
|
281 |
-
echo json_encode($results);
|
282 |
-
echo "<!--WC_END-->";
|
283 |
-
exit;
|
284 |
-
break;
|
285 |
-
case 4 :
|
286 |
-
$nonce = (isset($_POST['wt_nonce']) ? sanitize_text_field($_POST['wt_nonce']) : '');
|
287 |
-
if (!wp_verify_nonce($nonce, WF_ORDER_IMP_EXP_ID) || !WF_Order_Import_Export_CSV::hf_user_permission()) {
|
288 |
-
wp_die(__('Access Denied', 'order-import-export-for-woocommerce'));
|
289 |
-
}
|
290 |
-
if(isset($_POST['processed_posts']) && !empty($_POST['processed_posts'])){
|
291 |
-
$_POST['processed_posts']= explode(',', $_POST['processed_posts']);
|
292 |
-
}
|
293 |
-
add_filter('http_request_timeout', array($this, 'bump_request_timeout'));
|
294 |
-
if (function_exists('gc_enable'))
|
295 |
-
gc_enable();
|
296 |
-
@set_time_limit(0);
|
297 |
-
@ob_flush();
|
298 |
-
@flush();
|
299 |
-
$wpdb->hide_errors();
|
300 |
-
$this->processed_terms = !empty($_POST['processed_terms']) ? wc_clean($_POST['processed_terms']) : array();
|
301 |
-
$this->processed_posts = !empty($_POST['processed_posts']) ? array_map('intval', $_POST['processed_posts']) : array();
|
302 |
-
$file = isset($_POST['file']) ? stripslashes($_POST['file']) : '';
|
303 |
-
|
304 |
-
_e('Step 1...', 'order-import-export-for-woocommerce') . ' ';
|
305 |
-
|
306 |
-
wp_defer_term_counting(true);
|
307 |
-
wp_defer_comment_counting(true);
|
308 |
-
|
309 |
-
_e('Step 2...', 'order-import-export-for-woocommerce') . ' ';
|
310 |
-
|
311 |
-
echo 'Step 3...' . ' '; // Easter egg
|
312 |
-
|
313 |
-
_e('Finalizing...', 'order-import-export-for-woocommerce') . ' ';
|
314 |
-
|
315 |
-
// SUCCESS
|
316 |
-
_e('Finished. Import complete.', 'order-import-export-for-woocommerce');
|
317 |
-
|
318 |
-
|
319 |
-
if(in_array(pathinfo($file, PATHINFO_EXTENSION),array('txt','csv'))){
|
320 |
-
unlink($file);
|
321 |
-
}
|
322 |
-
$this->import_end();
|
323 |
-
|
324 |
-
exit;
|
325 |
-
break;
|
326 |
-
}
|
327 |
-
$this->footer();
|
328 |
-
}
|
329 |
-
|
330 |
-
/**
|
331 |
-
* format_data_from_csv
|
332 |
-
*/
|
333 |
-
public function format_data_from_csv($data, $enc) {
|
334 |
-
return ( $enc == 'UTF-8' ) ? $data : utf8_encode($data);
|
335 |
-
}
|
336 |
-
|
337 |
-
/**
|
338 |
-
* Display pre-import options
|
339 |
-
*/
|
340 |
-
public function import_options() {
|
341 |
-
$j = 0;
|
342 |
-
if ($this->id)
|
343 |
-
$file = get_attached_file($this->id);
|
344 |
-
else if ($this->file_url_import_enabled)
|
345 |
-
$file = ABSPATH . $this->file_url;
|
346 |
-
else
|
347 |
-
return;
|
348 |
-
// Set locale
|
349 |
-
$enc = mb_detect_encoding($file, 'UTF-8, ISO-8859-1', true);
|
350 |
-
if ($enc)
|
351 |
-
setlocale(LC_ALL, 'en_US.' . $enc);
|
352 |
-
@ini_set('auto_detect_line_endings', true);
|
353 |
-
// Get headers
|
354 |
-
if (( $ha
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|