CdataStrategy.php
4 years ago
CdataStrategyAlways.php
4 years ago
CdataStrategyFactory.php
4 years ago
CdataStrategyIllegalCharacters.php
4 years ago
CdataStrategyIllegalCharactersHtmlEntities.php
4 years ago
CdataStrategyNever.php
4 years ago
XMLWriter.php
4 years ago
chunk.php
4 years ago
config.php
4 years ago
download.php
4 years ago
handler.php
4 years ago
helper.php
4 years ago
input.php
4 years ago
installer.php
4 years ago
session.php
4 years ago
wpallimport.php
4 years ago
zip.php
4 years ago
wpallimport.php
582 lines
| 1 | <?php |
| 2 | |
| 3 | final class PMXE_Wpallimport |
| 4 | { |
| 5 | /** |
| 6 | * Singletone instance |
| 7 | * @var PMXE_Wpallimport |
| 8 | */ |
| 9 | protected static $instance; |
| 10 | |
| 11 | /** |
| 12 | * Return singletone instance |
| 13 | * @return PMXE_Wpallimport |
| 14 | */ |
| 15 | static public function getInstance() { |
| 16 | if (self::$instance == NULL) { |
| 17 | self::$instance = new self(); |
| 18 | } |
| 19 | return self::$instance; |
| 20 | } |
| 21 | |
| 22 | private function __construct(){} |
| 23 | |
| 24 | public static function create_an_import( & $export ) |
| 25 | { |
| 26 | |
| 27 | $custom_type = (empty($export->options['cpt'])) ? 'post' : $export->options['cpt'][0]; |
| 28 | |
| 29 | // Do not create an import for WooCommerce Orders & Refunds |
| 30 | // if ( in_array($custom_type, array('shop_order'))) return false; |
| 31 | |
| 32 | if ( $export->options['is_generate_import'] and wp_all_export_is_compatible() ){ |
| 33 | |
| 34 | $import = new PMXI_Import_Record(); |
| 35 | |
| 36 | if ( ! empty($export->options['import_id']) ) $import->getById($export->options['import_id']); |
| 37 | |
| 38 | if ($import->isEmpty()) |
| 39 | { |
| 40 | $import->set(array( |
| 41 | 'parent_import_id' => 99999, |
| 42 | 'xpath' => '/', |
| 43 | 'type' => 'upload', |
| 44 | 'options' => array('empty'), |
| 45 | 'root_element' => 'root', |
| 46 | 'path' => 'path', |
| 47 | 'imported' => 0, |
| 48 | 'created' => 0, |
| 49 | 'updated' => 0, |
| 50 | 'skipped' => 0, |
| 51 | 'deleted' => 0, |
| 52 | 'iteration' => 1 |
| 53 | ))->save(); |
| 54 | |
| 55 | if ( ! empty(PMXE_Plugin::$session) and PMXE_Plugin::$session->has_session() ) |
| 56 | { |
| 57 | PMXE_Plugin::$session->set('import_id', $import->id); |
| 58 | } |
| 59 | $options = $export->options; |
| 60 | $options['import_id'] = $import->id; |
| 61 | |
| 62 | $export->set(array( |
| 63 | 'options' => $options |
| 64 | ))->save(); |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | if ( $import->parent_import_id != 99999 ) |
| 69 | { |
| 70 | $newImport = new PMXI_Import_Record(); |
| 71 | |
| 72 | $newImport->set(array( |
| 73 | 'parent_import_id' => 99999, |
| 74 | 'xpath' => '/', |
| 75 | 'type' => 'upload', |
| 76 | 'options' => array('empty'), |
| 77 | 'root_element' => 'root', |
| 78 | 'path' => 'path', |
| 79 | 'imported' => 0, |
| 80 | 'created' => 0, |
| 81 | 'updated' => 0, |
| 82 | 'skipped' => 0, |
| 83 | 'deleted' => 0, |
| 84 | 'iteration' => 1 |
| 85 | ))->save(); |
| 86 | |
| 87 | if ( ! empty(PMXE_Plugin::$session) and PMXE_Plugin::$session->has_session() ) |
| 88 | { |
| 89 | PMXE_Plugin::$session->set('import_id', $newImport->id); |
| 90 | } |
| 91 | |
| 92 | $options = $export->options; |
| 93 | $options['import_id'] = $newImport->id; |
| 94 | |
| 95 | $export->set(array( |
| 96 | 'options' => $options |
| 97 | ))->save(); |
| 98 | } |
| 99 | else |
| 100 | { |
| 101 | global $wpdb; |
| 102 | $post = new PMXI_Post_List(); |
| 103 | $wpdb->query($wpdb->prepare('DELETE FROM ' . $post->getTable() . ' WHERE import_id = %s', $import->id)); |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | public static $templateOptions = array(); |
| 110 | public static function generateImportTemplate( & $export, $file_path = '', $foundPosts = 0, $link_to_import = true ) |
| 111 | { |
| 112 | $exportOptions = $export->options; |
| 113 | |
| 114 | $custom_type = (empty($exportOptions['cpt'])) ? 'post' : $exportOptions['cpt'][0]; |
| 115 | |
| 116 | // Do not create an import template for WooCommerce Refunds |
| 117 | if ( $export->options['export_to'] == 'xml' && in_array($export->options['xml_template_type'], array('custom', 'XmlGoogleMerchants')) ) return false; |
| 118 | |
| 119 | // Generate template for WP All Import |
| 120 | if ($exportOptions['is_generate_templates']) |
| 121 | { |
| 122 | self::$templateOptions = array( |
| 123 | 'type' => ( ! empty($exportOptions['cpt']) and $exportOptions['cpt'][0] == 'page') ? 'page' : 'post', |
| 124 | 'wizard_type' => 'new', |
| 125 | 'deligate' => 'wpallexport', |
| 126 | 'custom_type' => (XmlExportEngine::$is_user_export) ? 'import_users' : $custom_type, |
| 127 | 'status' => 'xpath', |
| 128 | 'is_multiple_page_parent' => 'no', |
| 129 | 'unique_key' => '', |
| 130 | 'acf' => array(), |
| 131 | 'fields' => array(), |
| 132 | 'is_multiple_field_value' => array(), |
| 133 | 'multiple_value' => array(), |
| 134 | 'fields_delimiter' => array(), |
| 135 | 'update_all_data' => 'no', |
| 136 | 'is_update_status' => 0, |
| 137 | 'is_update_title' => 0, |
| 138 | 'is_update_author' => 0, |
| 139 | 'is_update_slug' => 0, |
| 140 | 'is_update_content' => 0, |
| 141 | 'is_update_excerpt' => 0, |
| 142 | 'is_update_dates' => 0, |
| 143 | 'is_update_menu_order' => 0, |
| 144 | 'is_update_parent' => 0, |
| 145 | 'is_update_attachments' => 0, |
| 146 | 'is_update_acf' => 0, |
| 147 | 'is_update_comment_status' => 0, |
| 148 | 'import_img_tags' => 1, |
| 149 | 'update_acf_logic' => 'only', |
| 150 | 'acf_list' => '', |
| 151 | 'is_update_product_type' => 1, |
| 152 | 'is_update_attributes' => 0, |
| 153 | 'update_attributes_logic' => 'only', |
| 154 | 'attributes_list' => '', |
| 155 | 'is_update_images' => 0, |
| 156 | 'is_update_custom_fields' => 0, |
| 157 | 'update_custom_fields_logic' => 'only', |
| 158 | 'custom_fields_list' => '', |
| 159 | 'is_update_categories' => 0, |
| 160 | 'update_categories_logic' => 'only', |
| 161 | 'taxonomies_list' => '', |
| 162 | 'export_id' => $export->id |
| 163 | ); |
| 164 | |
| 165 | if ( in_array('product', $exportOptions['cpt']) ) |
| 166 | { |
| 167 | $default = array( |
| 168 | 'is_multiple_product_type' => 'yes', |
| 169 | 'multiple_product_type' => 'simple', |
| 170 | 'is_product_virtual' => 'no', |
| 171 | 'is_product_downloadable' => 'no', |
| 172 | 'is_product_enabled' => 'yes', |
| 173 | 'is_variation_enabled' => 'yes', |
| 174 | 'is_product_featured' => 'no', |
| 175 | 'is_product_visibility' => 'visible', |
| 176 | 'is_multiple_product_tax_status' => 'yes', |
| 177 | 'multiple_product_tax_status' => 'none', |
| 178 | 'is_multiple_product_tax_class' => 'yes', |
| 179 | 'is_product_manage_stock' => 'no', |
| 180 | 'product_stock_status' => 'auto', |
| 181 | 'product_allow_backorders' => 'no', |
| 182 | 'product_sold_individually' => 'no', |
| 183 | 'is_multiple_product_shipping_class' => 'yes', |
| 184 | 'is_multiple_grouping_product' => 'yes', |
| 185 | 'is_product_enable_reviews' => 'no', |
| 186 | 'single_sale_price_dates_from' => 'now', |
| 187 | 'single_sale_price_dates_to' => 'now', |
| 188 | 'product_files_delim' => ',', |
| 189 | 'product_files_names_delim' => ',', |
| 190 | 'matching_parent' => 'auto', |
| 191 | 'parent_indicator' => 'custom field', |
| 192 | 'missing_records_stock_status' => 0, |
| 193 | 'is_variable_sale_price_shedule' => 0, |
| 194 | 'is_variable_product_virtual' => 'no', |
| 195 | 'is_variable_product_manage_stock' => 'no', |
| 196 | 'is_multiple_variable_product_shipping_class' => 'yes', |
| 197 | 'is_multiple_variable_product_tax_class' => 'yes', |
| 198 | 'multiple_variable_product_tax_class' => 'parent', |
| 199 | 'variable_stock_status' => 'instock', |
| 200 | 'variable_allow_backorders' => 'no', |
| 201 | 'is_variable_product_downloadable' => 'no', |
| 202 | 'variable_product_files_delim' => ',', |
| 203 | 'variable_product_files_names_delim' => ',', |
| 204 | 'is_variable_product_enabled' => 'yes', |
| 205 | 'first_is_parent' => 'yes', |
| 206 | 'default_attributes_type' => 'first', |
| 207 | 'disable_sku_matching' => 1, |
| 208 | 'disable_prepare_price' => 1, |
| 209 | 'convert_decimal_separator' => 1, |
| 210 | 'grouping_indicator' => 'xpath', |
| 211 | 'is_update_product_type' => 1, |
| 212 | 'make_simple_product' => 1, |
| 213 | 'single_product_regular_price_adjust_type' => '%', |
| 214 | 'single_product_sale_price_adjust_type' => '%', |
| 215 | 'is_variation_product_manage_stock' => 'no', |
| 216 | 'variation_stock_status' => 'auto', |
| 217 | ); |
| 218 | |
| 219 | self::$templateOptions = array_replace_recursive(self::$templateOptions, $default); |
| 220 | |
| 221 | self::$templateOptions['_virtual'] = 1; |
| 222 | self::$templateOptions['_downloadable'] = 1; |
| 223 | self::$templateOptions['put_variation_image_to_gallery'] = 1; |
| 224 | self::$templateOptions['disable_auto_sku_generation'] = 1; |
| 225 | } |
| 226 | |
| 227 | if ( in_array('shop_order', $exportOptions['cpt']) ) |
| 228 | { |
| 229 | self::$templateOptions['update_all_data'] = 'no'; |
| 230 | self::$templateOptions['is_update_status'] = 0; |
| 231 | self::$templateOptions['is_update_dates'] = 0; |
| 232 | self::$templateOptions['is_update_excerpt'] = 0; |
| 233 | |
| 234 | // $default = PMWI_Plugin::get_default_import_options(); |
| 235 | // self::$templateOptions['pmwi_order'] = $default['pmwi_order']; |
| 236 | self::$templateOptions['pmwi_order'] = array(); |
| 237 | self::$templateOptions['pmwi_order']['is_update_billing_details'] = 0; |
| 238 | self::$templateOptions['pmwi_order']['is_update_shipping_details'] = 0; |
| 239 | self::$templateOptions['pmwi_order']['is_update_payment'] = 0; |
| 240 | self::$templateOptions['pmwi_order']['is_update_notes'] = 0; |
| 241 | self::$templateOptions['pmwi_order']['is_update_products'] = 0; |
| 242 | self::$templateOptions['pmwi_order']['is_update_fees'] = 0; |
| 243 | self::$templateOptions['pmwi_order']['is_update_coupons'] = 0; |
| 244 | self::$templateOptions['pmwi_order']['is_update_shipping'] = 0; |
| 245 | self::$templateOptions['pmwi_order']['is_update_taxes'] = 0; |
| 246 | self::$templateOptions['pmwi_order']['is_update_refunds'] = 0; |
| 247 | self::$templateOptions['pmwi_order']['is_update_total'] = 0; |
| 248 | self::$templateOptions['pmwi_order']['is_guest_matching'] = 1; |
| 249 | self::$templateOptions['pmwi_order']['status'] = 'wc-pending'; |
| 250 | self::$templateOptions['pmwi_order']['billing_source'] = 'existing'; |
| 251 | self::$templateOptions['pmwi_order']['billing_source_match_by'] = 'username'; |
| 252 | self::$templateOptions['pmwi_order']['shipping_source'] = 'guest'; |
| 253 | self::$templateOptions['pmwi_order']['copy_from_billing'] = 1; |
| 254 | self::$templateOptions['pmwi_order']['products_repeater_mode'] = 'csv'; |
| 255 | self::$templateOptions['pmwi_order']['products_repeater_mode_separator'] = '|'; |
| 256 | self::$templateOptions['pmwi_order']['products_source'] = 'existing'; |
| 257 | self::$templateOptions['pmwi_order']['fees_repeater_mode'] = 'csv'; |
| 258 | self::$templateOptions['pmwi_order']['fees_repeater_mode_separator'] = '|'; |
| 259 | self::$templateOptions['pmwi_order']['coupons_repeater_mode'] = 'csv'; |
| 260 | self::$templateOptions['pmwi_order']['coupons_repeater_mode_separator'] = '|'; |
| 261 | self::$templateOptions['pmwi_order']['shipping_repeater_mode'] = 'csv'; |
| 262 | self::$templateOptions['pmwi_order']['shipping_repeater_mode_separator'] = '|'; |
| 263 | self::$templateOptions['pmwi_order']['taxes_repeater_mode'] = 'csv'; |
| 264 | self::$templateOptions['pmwi_order']['taxes_repeater_mode_separator'] = '|'; |
| 265 | self::$templateOptions['pmwi_order']['order_total_logic'] = 'auto'; |
| 266 | self::$templateOptions['pmwi_order']['order_refund_date'] = 'now'; |
| 267 | self::$templateOptions['pmwi_order']['order_refund_issued_source'] = 'existing'; |
| 268 | self::$templateOptions['pmwi_order']['order_refund_issued_match_by'] = 'username'; |
| 269 | self::$templateOptions['pmwi_order']['notes_repeater_mode'] = 'csv'; |
| 270 | self::$templateOptions['pmwi_order']['notes_repeater_mode_separator'] = '|'; |
| 271 | } |
| 272 | |
| 273 | if ( XmlExportEngine::$is_user_export ) |
| 274 | { |
| 275 | self::$templateOptions['is_update_first_name'] = 0; |
| 276 | self::$templateOptions['is_update_last_name'] = 0; |
| 277 | self::$templateOptions['is_update_role'] = 0; |
| 278 | self::$templateOptions['is_update_nickname'] = 0; |
| 279 | self::$templateOptions['is_update_description'] = 0; |
| 280 | self::$templateOptions['is_update_login'] = 0; |
| 281 | self::$templateOptions['is_update_password'] = 0; |
| 282 | self::$templateOptions['is_update_nicename'] = 0; |
| 283 | self::$templateOptions['is_update_email'] = 0; |
| 284 | self::$templateOptions['is_update_registered'] = 0; |
| 285 | self::$templateOptions['is_update_display_name'] = 0; |
| 286 | self::$templateOptions['is_update_url'] = 0; |
| 287 | } |
| 288 | |
| 289 | if (XmlExportEngine::$is_taxonomy_export){ |
| 290 | self::$templateOptions['taxonomy_type'] = $exportOptions['taxonomy_to_export']; |
| 291 | } |
| 292 | |
| 293 | self::prepare_import_template( $exportOptions ); |
| 294 | |
| 295 | if ( in_array('product', $exportOptions['cpt']) ) |
| 296 | { |
| 297 | self::$templateOptions['single_page_parent'] = ''; |
| 298 | if ( ! empty($exportOptions['export_variations']) && $exportOptions['export_variations'] == XmlExportEngine::VARIABLE_PRODUCTS_EXPORT_VARIATION ){ |
| 299 | if ( $exportOptions['export_variations_title'] == XmlExportEngine::VARIATION_USE_PARENT_TITLE ){ |
| 300 | self::$templateOptions['matching_parent'] = 'first_is_variation'; |
| 301 | } |
| 302 | if ( $exportOptions['export_variations_title'] == XmlExportEngine::VARIATION_USE_DEFAULT_TITLE ) { |
| 303 | self::$templateOptions['matching_parent'] = 'first_is_parent_id'; |
| 304 | } |
| 305 | self::$templateOptions['create_new_records'] = 0; |
| 306 | self::$templateOptions['is_update_product_type'] = 0; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | $tpl_options = self::$templateOptions; |
| 311 | |
| 312 | if ( 'csv' == $exportOptions['export_to'] ) |
| 313 | { |
| 314 | $tpl_options['delimiter'] = $exportOptions['delimiter']; |
| 315 | $tpl_options['root_element'] = 'node'; |
| 316 | } |
| 317 | else |
| 318 | { |
| 319 | $tpl_options['root_element'] = $exportOptions['record_xml_tag']; |
| 320 | } |
| 321 | |
| 322 | $tpl_options['update_all_data'] = 'yes'; |
| 323 | $tpl_options['is_update_status'] = 1; |
| 324 | $tpl_options['is_update_title'] = 1; |
| 325 | $tpl_options['is_update_author'] = 1; |
| 326 | $tpl_options['is_update_slug'] = 1; |
| 327 | $tpl_options['is_update_content'] = 1; |
| 328 | $tpl_options['is_update_excerpt'] = 1; |
| 329 | $tpl_options['is_update_dates'] = 1; |
| 330 | $tpl_options['is_update_menu_order'] = 1; |
| 331 | $tpl_options['is_update_parent'] = 1; |
| 332 | $tpl_options['is_update_attachments'] = 1; |
| 333 | $tpl_options['is_update_acf'] = 1; |
| 334 | $tpl_options['update_acf_logic'] = 'full_update'; |
| 335 | $tpl_options['acf_list'] = ''; |
| 336 | $tpl_options['is_update_product_type'] = 1; |
| 337 | $tpl_options['is_update_attributes'] = 1; |
| 338 | $tpl_options['update_attributes_logic'] = 'full_update'; |
| 339 | $tpl_options['attributes_list'] = ''; |
| 340 | $tpl_options['is_update_images'] = 1; |
| 341 | $tpl_options['is_update_custom_fields'] = 1; |
| 342 | $tpl_options['update_custom_fields_logic'] = 'full_update'; |
| 343 | $tpl_options['custom_fields_list'] = ''; |
| 344 | $tpl_options['is_update_categories'] = 1; |
| 345 | $tpl_options['update_categories_logic'] = 'full_update'; |
| 346 | $tpl_options['taxonomies_list'] = ''; |
| 347 | |
| 348 | $tpl_data = array( |
| 349 | 'name' => $exportOptions['template_name'], |
| 350 | 'is_keep_linebreaks' => 1, |
| 351 | 'is_leave_html' => 0, |
| 352 | 'fix_characters' => 0, |
| 353 | 'options' => $tpl_options, |
| 354 | ); |
| 355 | |
| 356 | $exportOptions['tpl_data'] = $tpl_data; |
| 357 | |
| 358 | $export->set(array( |
| 359 | 'options' => $exportOptions |
| 360 | ))->save(); |
| 361 | |
| 362 | } |
| 363 | |
| 364 | $link_to_import and $export->options['is_generate_import'] and self::link_template_to_import( $export, $file_path, $foundPosts ); |
| 365 | } |
| 366 | |
| 367 | public static function link_template_to_import( & $export, $file_path, $foundPosts ) |
| 368 | { |
| 369 | |
| 370 | $exportOptions = $export->options; |
| 371 | |
| 372 | // associate exported posts with new import |
| 373 | if ( wp_all_export_is_compatible() ) |
| 374 | { |
| 375 | $options = self::$templateOptions + PMXI_Plugin::get_default_import_options(); |
| 376 | |
| 377 | $import = new PMXI_Import_Record(); |
| 378 | |
| 379 | $import->getById($exportOptions['import_id']); |
| 380 | |
| 381 | if ( ! $import->isEmpty() and $import->parent_import_id == 99999 ){ |
| 382 | |
| 383 | $xmlPath = $file_path; |
| 384 | |
| 385 | $root_element = ''; |
| 386 | |
| 387 | $historyPath = $file_path; |
| 388 | |
| 389 | if ( 'csv' == $exportOptions['export_to'] ) |
| 390 | { |
| 391 | $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure'); |
| 392 | |
| 393 | $options['delimiter'] = $exportOptions['delimiter']; |
| 394 | |
| 395 | include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php' ); |
| 396 | |
| 397 | $path_info = pathinfo($xmlPath); |
| 398 | |
| 399 | $path_parts = explode(DIRECTORY_SEPARATOR, $path_info['dirname']); |
| 400 | |
| 401 | $security_folder = array_pop($path_parts); |
| 402 | |
| 403 | $wp_uploads = wp_upload_dir(); |
| 404 | |
| 405 | $target = $is_secure_import ? $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::UPLOADS_DIRECTORY . DIRECTORY_SEPARATOR . $security_folder : $wp_uploads['path']; |
| 406 | |
| 407 | $csv = new PMXI_CsvParser( array( 'filename' => $xmlPath, 'targetDir' => $target ) ); |
| 408 | |
| 409 | if ( ! in_array($xmlPath, $exportOptions['attachment_list']) ) |
| 410 | { |
| 411 | $exportOptions['attachment_list'][] = $csv->xml_path; |
| 412 | } |
| 413 | |
| 414 | $historyPath = $csv->xml_path; |
| 415 | |
| 416 | $root_element = 'node'; |
| 417 | |
| 418 | } |
| 419 | else |
| 420 | { |
| 421 | $root_element = apply_filters('wp_all_export_record_xml_tag', $exportOptions['record_xml_tag'], $export->id); |
| 422 | } |
| 423 | |
| 424 | $import->set(array( |
| 425 | 'xpath' => '/' . $root_element, |
| 426 | 'type' => 'upload', |
| 427 | 'options' => $options, |
| 428 | 'root_element' => $root_element, |
| 429 | 'path' => $xmlPath, |
| 430 | 'name' => basename($xmlPath), |
| 431 | 'imported' => 0, |
| 432 | 'created' => 0, |
| 433 | 'updated' => 0, |
| 434 | 'skipped' => 0, |
| 435 | 'deleted' => 0, |
| 436 | 'iteration' => 1, |
| 437 | 'count' => $foundPosts |
| 438 | ))->save(); |
| 439 | |
| 440 | $history_file = new PMXI_File_Record(); |
| 441 | $history_file->set(array( |
| 442 | 'name' => $import->name, |
| 443 | 'import_id' => $import->id, |
| 444 | 'path' => $historyPath, |
| 445 | 'registered_on' => date('Y-m-d H:i:s') |
| 446 | ))->save(); |
| 447 | |
| 448 | $exportOptions['import_id'] = $import->id; |
| 449 | |
| 450 | $export->set(array( |
| 451 | 'options' => $exportOptions |
| 452 | ))->save(); |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | public static function prepare_import_template( $exportOptions ) |
| 458 | { |
| 459 | $options = $exportOptions; |
| 460 | |
| 461 | $is_xml_template = $options['export_to'] == 'xml'; |
| 462 | |
| 463 | $required_add_ons = array(); |
| 464 | |
| 465 | $cf_list = array(); |
| 466 | $attr_list = array(); |
| 467 | $taxs_list = array(); |
| 468 | $acf_list = array(); |
| 469 | |
| 470 | $implode_delimiter = ($options['delimiter'] == ',') ? '|' : ','; |
| 471 | |
| 472 | if ( ! empty($options['is_user_export']) ) self::$templateOptions['pmui']['import_users'] = 1; |
| 473 | |
| 474 | foreach ($options['ids'] as $ID => $value) |
| 475 | { |
| 476 | if (empty($options['cc_type'][$ID])) continue; |
| 477 | |
| 478 | if ($is_xml_template) |
| 479 | { |
| 480 | $element_name = (!empty($options['cc_name'][$ID])) ? str_replace(':', '_', preg_replace('/[^a-z0-9_:-]/i', '', $options['cc_name'][$ID])) : 'untitled_' . $ID; |
| 481 | } |
| 482 | else |
| 483 | { |
| 484 | $element_name = strtolower((!empty($options['cc_name'][$ID])) ? preg_replace('/[^a-z0-9_]/i', '', $options['cc_name'][$ID]) : 'untitled_' . $ID); |
| 485 | } |
| 486 | |
| 487 | if (empty($element_name)) $element_name = 'undefined' . $ID; |
| 488 | |
| 489 | $element_type = $options['cc_type'][$ID]; |
| 490 | |
| 491 | switch ($element_type) |
| 492 | { |
| 493 | case 'woo': |
| 494 | |
| 495 | if ( ! empty($options['cc_value'][$ID]) ) |
| 496 | { |
| 497 | if (empty($required_add_ons['PMWI_Plugin'])) |
| 498 | { |
| 499 | $required_add_ons['PMWI_Plugin'] = array( |
| 500 | 'name' => 'WooCommerce Add-On Pro', |
| 501 | 'paid' => true, |
| 502 | 'url' => 'http://www.wpallimport.com/woocommerce-product-import/?utm_source=export-plugin-free&utm_medium=upgrade-notice&utm_campaign=import-wooco-products-template' |
| 503 | ); |
| 504 | } |
| 505 | |
| 506 | XmlExportWooCommerce::prepare_import_template( $options, self::$templateOptions, $cf_list, $attr_list, $element_name, $options['cc_label'][$ID] ); |
| 507 | } |
| 508 | |
| 509 | break; |
| 510 | |
| 511 | case 'acf': |
| 512 | |
| 513 | if (empty($required_add_ons['PMAI_Plugin'])) |
| 514 | { |
| 515 | $required_add_ons['PMAI_Plugin'] = array( |
| 516 | 'name' => 'ACF Add-On Pro', |
| 517 | 'paid' => true, |
| 518 | 'url' => 'http://www.wpallimport.com/advanced-custom-fields/?utm_source=export-plugin-free&utm_medium=upgrade-notice&utm_campaign=import-acf-template' |
| 519 | ); |
| 520 | } |
| 521 | |
| 522 | $field_options = unserialize($options['cc_options'][$ID]); |
| 523 | |
| 524 | // add ACF group ID to the template options |
| 525 | if( ! in_array($field_options['group_id'], self::$templateOptions['acf'])){ |
| 526 | self::$templateOptions['acf'][$field_options['group_id']] = 1; |
| 527 | } |
| 528 | |
| 529 | self::$templateOptions['fields'][$field_options['key']] = XmlExportACF::prepare_import_template( $options, self::$templateOptions, $acf_list, $element_name, $field_options); |
| 530 | |
| 531 | break; |
| 532 | |
| 533 | default: |
| 534 | |
| 535 | $addons = new \Wpae\App\Service\Addons\AddonService(); |
| 536 | XmlExportCpt::prepare_import_template( $options, self::$templateOptions, $cf_list, $attr_list, $taxs_list, $element_name, $ID); |
| 537 | |
| 538 | XmlExportMediaGallery::prepare_import_template( $options, self::$templateOptions, $element_name, $ID); |
| 539 | |
| 540 | if($addons->isUserAddonActive()) { |
| 541 | XmlExportUser::prepare_import_template($options, self::$templateOptions, $element_name, $ID); |
| 542 | } |
| 543 | |
| 544 | XmlExportTaxonomy::prepare_import_template( $options, self::$templateOptions, $element_name, $ID); |
| 545 | |
| 546 | XmlExportWooCommerceOrder::prepare_import_template( $options, self::$templateOptions, $element_name, $ID); |
| 547 | |
| 548 | break; |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | if ( ! empty($cf_list) ) |
| 553 | { |
| 554 | self::$templateOptions['is_update_custom_fields'] = 1; |
| 555 | self::$templateOptions['custom_fields_list'] = $cf_list; |
| 556 | } |
| 557 | if ( ! empty($attr_list) ) |
| 558 | { |
| 559 | self::$templateOptions['is_update_attributes'] = 1; |
| 560 | self::$templateOptions['update_attributes_logic'] = 'only'; |
| 561 | self::$templateOptions['attributes_list'] = $attr_list; |
| 562 | self::$templateOptions['attributes_only_list'] = implode(',', $attr_list); |
| 563 | } |
| 564 | else{ |
| 565 | self::$templateOptions['is_update_attributes'] = 0; |
| 566 | } |
| 567 | if ( ! empty($taxs_list) ) |
| 568 | { |
| 569 | self::$templateOptions['is_update_categories'] = 1; |
| 570 | self::$templateOptions['taxonomies_list'] = $taxs_list; |
| 571 | } |
| 572 | if ( ! empty($acf_list) ) |
| 573 | { |
| 574 | self::$templateOptions['is_update_acf'] = 1; |
| 575 | self::$templateOptions['acf_list'] = $acf_list; |
| 576 | } |
| 577 | |
| 578 | self::$templateOptions['required_add_ons'] = $required_add_ons; |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | PMXE_Wpallimport::getInstance(); |