VariableProductTitle
8 years ago
.gitkeep
8 years ago
WpaeInvalidPhpException.php
8 years ago
WpaeInvalidStringException.php
8 years ago
WpaeMethodNotFoundException.php
8 years ago
WpaePhpInterpreterErrorHandler.php
8 years ago
WpaeString.php
8 years ago
WpaeTooMuchRecursionException.php
8 years ago
WpaeXmlProcessor.php
8 years ago
XmlCsvExport.php
8 years ago
XmlExportACF.php
8 years ago
XmlExportComment.php
8 years ago
XmlExportCpt.php
8 years ago
XmlExportEngine.php
8 years ago
XmlExportFiltering.php
8 years ago
XmlExportMediaGallery.php
8 years ago
XmlExportTaxonomy.php
8 years ago
XmlExportUser.php
8 years ago
XmlExportWooCommerce.php
8 years ago
XmlExportWooCommerceCoupon.php
8 years ago
XmlExportWooCommerceOrder.php
8 years ago
XmlGoogleMerchants.php
8 years ago
XmlSpec.php
8 years ago
XmlExportCpt.php
659 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | use Wpae\App\Service\VariationOptions\VariationOptionsFactory; |
| 5 | |
| 6 | final class XmlExportCpt |
| 7 | { |
| 8 | public static function prepare_data( $entry, $exportOptions, |
| 9 | $xmlWriter = false, &$acfs, &$woo, &$woo_order, $implode_delimiter, $preview, $is_item_data = false, $subID = false ) |
| 10 | { |
| 11 | $variationOptionsFactory = new VariationOptionsFactory(); |
| 12 | $variationOptions = $variationOptionsFactory->createVariationOptions(PMXE_EDITION); |
| 13 | $entry = $variationOptions->preprocessPost($entry); |
| 14 | |
| 15 | $article = array(); |
| 16 | |
| 17 | // associate exported post with import |
| 18 | if ( ! $is_item_data and wp_all_export_is_compatible() && $exportOptions['is_generate_import'] && $exportOptions['import_id']) |
| 19 | { |
| 20 | $postRecord = new PMXI_Post_Record(); |
| 21 | $postRecord->clear(); |
| 22 | $postRecord->getBy(array( |
| 23 | 'post_id' => $entry->ID, |
| 24 | 'import_id' => $exportOptions['import_id'], |
| 25 | )); |
| 26 | |
| 27 | if ($postRecord->isEmpty()){ |
| 28 | $postRecord->set(array( |
| 29 | 'post_id' => $entry->ID, |
| 30 | 'import_id' => $exportOptions['import_id'], |
| 31 | 'unique_key' => $entry->ID, |
| 32 | 'product_key' => $entry->ID |
| 33 | ))->save(); |
| 34 | } |
| 35 | unset($postRecord); |
| 36 | } |
| 37 | |
| 38 | $is_xml_export = false; |
| 39 | |
| 40 | if ( ! empty($xmlWriter) && $exportOptions['export_to'] == XmlExportEngine::EXPORT_TYPE_XML && !in_array($exportOptions['xml_template_type'], array('custom', 'XmlGoogleMerchants')) ){ |
| 41 | $is_xml_export = true; |
| 42 | } |
| 43 | |
| 44 | foreach ($exportOptions['ids'] as $ID => $value) |
| 45 | { |
| 46 | $pType = $entry->post_type; |
| 47 | |
| 48 | if ( $is_item_data and $subID != $ID ) continue; |
| 49 | |
| 50 | // skip shop order items data |
| 51 | if ( $pType == "shop_order" and strpos($exportOptions['cc_label'][$ID], "item_data__") !== false and ! $is_item_data ) continue; |
| 52 | |
| 53 | $fieldName = apply_filters('wp_all_export_field_name', wp_all_export_parse_field_name($exportOptions['cc_name'][$ID]), XmlExportEngine::$exportID); |
| 54 | $fieldValue = str_replace("item_data__", "", $exportOptions['cc_value'][$ID]); |
| 55 | $fieldLabel = str_replace("item_data__", "", $exportOptions['cc_label'][$ID]); |
| 56 | $fieldSql = $exportOptions['cc_sql'][$ID]; |
| 57 | $fieldPhp = $exportOptions['cc_php'][$ID]; |
| 58 | $fieldCode = $exportOptions['cc_code'][$ID]; |
| 59 | $fieldType = $exportOptions['cc_type'][$ID]; |
| 60 | $fieldOptions = $exportOptions['cc_options'][$ID]; |
| 61 | $fieldSettings = empty($exportOptions['cc_settings'][$ID]) ? $fieldOptions : $exportOptions['cc_settings'][$ID]; |
| 62 | |
| 63 | if ( empty($fieldName) or empty($fieldType) or ! is_numeric($ID) ) continue; |
| 64 | |
| 65 | $element_name = ( ! empty($fieldName) ) ? $fieldName : 'untitled_' . $ID; |
| 66 | $element_name_ns = ''; |
| 67 | |
| 68 | if ( $is_xml_export ) |
| 69 | { |
| 70 | $element_name = ( ! empty($fieldName) ) ? preg_replace('/[^a-z0-9_:-]/i', '', $fieldName) : 'untitled_' . $ID; |
| 71 | |
| 72 | if (strpos($element_name, ":") !== false) { |
| 73 | $element_name_parts = explode(":", $element_name); |
| 74 | $element_name_ns = (empty($element_name_parts[0])) ? '' : $element_name_parts[0]; |
| 75 | $element_name = (empty($element_name_parts[1])) ? 'untitled_' . $ID : preg_replace('/[^a-z0-9_-]/i', '', $element_name_parts[1]); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | $fieldSnipped = ( ! empty($fieldPhp ) and ! empty($fieldCode)) ? $fieldCode : false; |
| 80 | |
| 81 | switch ($fieldType) |
| 82 | { |
| 83 | case 'id': |
| 84 | // For ID columns make first element in lowercase for Excel export |
| 85 | if ($element_name == 'ID' && !$ID && isset($exportOptions['export_to']) && $exportOptions['export_to'] == 'csv' && isset($exportOptions['export_to_sheet']) && $exportOptions['export_to_sheet'] != 'csv'){ |
| 86 | $element_name = 'id'; |
| 87 | } |
| 88 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_post_id', pmxe_filter($entry->ID, $fieldSnipped), $entry->ID)); |
| 89 | break; |
| 90 | case 'permalink': |
| 91 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_post_guid', pmxe_filter(get_permalink(), $fieldSnipped), $entry->ID)); |
| 92 | break; |
| 93 | case 'post_type': |
| 94 | if ($entry->post_type == 'product_variation') $pType = 'product'; |
| 95 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_post_type', pmxe_filter($pType, $fieldSnipped), $entry->ID)); |
| 96 | break; |
| 97 | case 'title': |
| 98 | $val = apply_filters('pmxe_post_title', pmxe_filter($entry->post_title, $fieldSnipped)); |
| 99 | wp_all_export_write_article( $article, $element_name, ($preview) ? trim(preg_replace('~[\r\n]+~', ' ', htmlspecialchars($val))) : $val, $entry->ID); |
| 100 | break; |
| 101 | case 'content': |
| 102 | $postContent = $entry->post_content; |
| 103 | |
| 104 | if($exportOptions['export_to'] == XmlExportEngine::EXPORT_TYPE_XML && $exportOptions['xml_template_type'] == 'custom') { |
| 105 | $postContent = str_replace('[', '**OPENSHORTCODE**', $postContent); |
| 106 | $postContent = str_replace(']', '**CLOSESHORTCODE**', $postContent); |
| 107 | } |
| 108 | |
| 109 | $val = apply_filters('pmxe_post_content', pmxe_filter($postContent, $fieldSnipped), $entry->ID); |
| 110 | wp_all_export_write_article( $article, $element_name, ($preview) ? trim(preg_replace('~[\r\n]+~', ' ', htmlspecialchars($val))) : $val); |
| 111 | break; |
| 112 | |
| 113 | // Media Attachments |
| 114 | case 'attachments': |
| 115 | case 'attachment_id': |
| 116 | case 'attachment_url': |
| 117 | case 'attachment_filename': |
| 118 | case 'attachment_path': |
| 119 | case 'attachment_title': |
| 120 | case 'attachment_caption': |
| 121 | case 'attachment_description': |
| 122 | case 'attachment_alt': |
| 123 | |
| 124 | XmlExportMediaGallery::getInstance($entry->ID); |
| 125 | |
| 126 | $attachment_data = XmlExportMediaGallery::get_attachments($fieldType); |
| 127 | |
| 128 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_' . $fieldType, pmxe_filter( implode($implode_delimiter, $attachment_data), $fieldSnipped), $entry->ID) ); |
| 129 | |
| 130 | break; |
| 131 | |
| 132 | // Media Images |
| 133 | case 'media': |
| 134 | case 'image_id': |
| 135 | case 'image_url': |
| 136 | case 'image_filename': |
| 137 | case 'image_path': |
| 138 | case 'image_title': |
| 139 | case 'image_caption': |
| 140 | case 'image_description': |
| 141 | case 'image_alt': |
| 142 | |
| 143 | $field_options = json_decode($fieldOptions, true); |
| 144 | |
| 145 | XmlExportMediaGallery::getInstance($entry->ID); |
| 146 | |
| 147 | $images_data = XmlExportMediaGallery::get_images($fieldType, $field_options); |
| 148 | |
| 149 | $images_separator = empty($field_options['image_separator']) ? $implode_delimiter : $field_options['image_separator']; |
| 150 | |
| 151 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_' . $fieldType, pmxe_filter( implode($images_separator, $images_data), $fieldSnipped), $entry->ID) ); |
| 152 | |
| 153 | break; |
| 154 | |
| 155 | case 'date': |
| 156 | $post_date = prepare_date_field_value($fieldSettings, get_post_time('U', true, $entry->ID), "Ymd"); |
| 157 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_post_date', pmxe_filter($post_date, $fieldSnipped), $entry->ID) ); |
| 158 | break; |
| 159 | case 'post_modified': |
| 160 | $post_date = prepare_date_field_value($fieldSettings, get_post_modified_time('U', true, $entry->ID), "Ymd"); |
| 161 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_post_modified_date', pmxe_filter($post_date, $fieldSnipped), $entry->ID) ); |
| 162 | break; |
| 163 | case 'parent': |
| 164 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_post_parent', pmxe_filter($entry->post_parent, $fieldSnipped), $entry->ID) ); |
| 165 | break; |
| 166 | case 'parent_slug': |
| 167 | $val = ''; |
| 168 | if ( $entry->post_parent != 0 ) { |
| 169 | $pages = get_post_ancestors( $entry->ID ); |
| 170 | $slugs = array(); |
| 171 | if ( !empty( $pages ) ) { |
| 172 | foreach( $pages as $page ) { |
| 173 | $the_post = get_post( $page ); |
| 174 | $slugs[] = $the_post->post_name; |
| 175 | } |
| 176 | $val = implode( "/", array_reverse( $slugs ) ); |
| 177 | } else { |
| 178 | $the_post = get_post( $entry->ID ); |
| 179 | $val = $the_post->post_name; |
| 180 | } |
| 181 | } |
| 182 | else{ |
| 183 | $val = $entry->post_parent; |
| 184 | } |
| 185 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_post_parent_slug', pmxe_filter($val, $fieldSnipped), $entry->ID) ); |
| 186 | break; |
| 187 | case 'comment_status': |
| 188 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_comment_status', pmxe_filter($entry->comment_status, $fieldSnipped), $entry->ID) ); |
| 189 | break; |
| 190 | case 'ping_status': |
| 191 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_ping_status', pmxe_filter($entry->ping_status, $fieldSnipped), $entry->ID) ); |
| 192 | break; |
| 193 | case 'template': |
| 194 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_post_template', pmxe_filter(get_post_meta($entry->ID, '_wp_page_template', true), $fieldSnipped), $entry->ID) ); |
| 195 | break; |
| 196 | case 'order': |
| 197 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_menu_order', pmxe_filter($entry->menu_order, $fieldSnipped), $entry->ID) ); |
| 198 | break; |
| 199 | case 'status': |
| 200 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_post_status', pmxe_filter($entry->post_status, $fieldSnipped), $entry->ID) ); |
| 201 | break; |
| 202 | case 'format': |
| 203 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_post_format', pmxe_filter(get_post_format($entry->ID), $fieldSnipped), $entry->ID) ); |
| 204 | break; |
| 205 | case 'author': |
| 206 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_post_author', pmxe_filter($entry->post_author, $fieldSnipped), $entry->ID) ); |
| 207 | break; |
| 208 | case 'slug': |
| 209 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_post_slug', pmxe_filter($entry->post_name, $fieldSnipped), $entry->ID) ); |
| 210 | break; |
| 211 | case 'excerpt': |
| 212 | $val = apply_filters('pmxe_post_excerpt', pmxe_filter($entry->post_excerpt, $fieldSnipped), $entry->ID); |
| 213 | wp_all_export_write_article( $article, $element_name, ($preview) ? trim(preg_replace('~[\r\n]+~', ' ', htmlspecialchars($val))) : $val ); |
| 214 | break; |
| 215 | case 'cf': |
| 216 | if ( ! empty($fieldValue) ) { |
| 217 | |
| 218 | $val = ""; |
| 219 | $cur_meta_values = get_post_meta($entry->ID, $fieldValue); |
| 220 | |
| 221 | if ( ! empty($cur_meta_values) and is_array($cur_meta_values)) { |
| 222 | foreach ($cur_meta_values as $key => $cur_meta_value) { |
| 223 | if (empty($val)) { |
| 224 | $val = maybe_serialize($cur_meta_value); |
| 225 | } |
| 226 | else { |
| 227 | $val = $val . $implode_delimiter . maybe_serialize($cur_meta_value); |
| 228 | } |
| 229 | } |
| 230 | wp_all_export_write_article( $article, $element_name, pmxe_filter($val, $fieldSnipped) ); |
| 231 | } |
| 232 | |
| 233 | if ( empty($cur_meta_values)) { |
| 234 | if ( empty($article[$element_name])) { |
| 235 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_custom_field', pmxe_filter('', $fieldSnipped), $fieldValue, $entry->ID) ); |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | break; |
| 240 | |
| 241 | case 'acf': |
| 242 | |
| 243 | if ( ! empty($fieldLabel) and class_exists( 'acf' ) ){ |
| 244 | |
| 245 | global $acf; |
| 246 | |
| 247 | $field_options = unserialize($fieldOptions); |
| 248 | |
| 249 | if ( ! $is_xml_export ) |
| 250 | { |
| 251 | switch ($field_options['type']) { |
| 252 | case 'textarea': |
| 253 | case 'oembed': |
| 254 | case 'wysiwyg': |
| 255 | case 'wp_wysiwyg': |
| 256 | case 'date_time_picker': |
| 257 | case 'date_picker': |
| 258 | |
| 259 | $field_value = get_field($fieldLabel, $entry->ID, false); |
| 260 | |
| 261 | break; |
| 262 | |
| 263 | default: |
| 264 | |
| 265 | $field_value = get_field($fieldLabel, $entry->ID); |
| 266 | |
| 267 | break; |
| 268 | } |
| 269 | } |
| 270 | else { |
| 271 | $field_value = get_field($fieldLabel, $entry->ID); |
| 272 | } |
| 273 | |
| 274 | XmlExportACF::export_acf_field( |
| 275 | $field_value, |
| 276 | $exportOptions, |
| 277 | $ID, |
| 278 | $entry->ID, |
| 279 | $article, |
| 280 | $xmlWriter, |
| 281 | $acfs, |
| 282 | $element_name, |
| 283 | $element_name_ns, |
| 284 | $fieldSnipped, |
| 285 | $field_options['group_id'], |
| 286 | $preview |
| 287 | ); |
| 288 | } |
| 289 | |
| 290 | break; |
| 291 | |
| 292 | case 'woo': |
| 293 | |
| 294 | if ( $is_xml_export ) { |
| 295 | XmlExportEngine::$woo_export->export_xml($xmlWriter, $entry, $exportOptions, $ID); |
| 296 | } |
| 297 | else { |
| 298 | XmlExportEngine::$woo_export->export_csv($article, $woo, $entry, $exportOptions, $ID); |
| 299 | } |
| 300 | |
| 301 | break; |
| 302 | |
| 303 | case 'woo_order': |
| 304 | |
| 305 | if ( $is_xml_export ) { |
| 306 | XmlExportEngine::$woo_order_export->export_xml($xmlWriter, $entry, $exportOptions, $ID, $preview); |
| 307 | } |
| 308 | else { |
| 309 | XmlExportEngine::$woo_order_export->export_csv($article, $woo_order, $entry, $exportOptions, $ID, $preview); |
| 310 | } |
| 311 | |
| 312 | break; |
| 313 | |
| 314 | case 'attr': |
| 315 | |
| 316 | if ( ! empty($fieldValue)) { |
| 317 | if ( $entry->post_type != 'product_variation' ) { |
| 318 | $txes_list = get_the_terms($entry->ID, $fieldValue); |
| 319 | if ( ! is_wp_error($txes_list) and ! empty($txes_list)) { |
| 320 | $attr_new = array(); |
| 321 | foreach ($txes_list as $t) { |
| 322 | $attr_new[] = $t->name; |
| 323 | } |
| 324 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_woo_attribute', pmxe_filter(implode($implode_delimiter, $attr_new), $fieldSnipped), $entry->ID, $fieldValue) ); |
| 325 | } else { |
| 326 | // Write empty value (so the functions are still applied) |
| 327 | wp_all_export_write_article( $article, $element_name, pmxe_filter('', $fieldSnipped)); |
| 328 | } |
| 329 | } |
| 330 | else { |
| 331 | $attribute_pa = apply_filters('pmxe_woo_attribute', get_post_meta($entry->ID, 'attribute_' . $fieldValue, true), $entry->ID, $fieldValue); |
| 332 | $term = get_term_by('slug', $attribute_pa, $fieldValue); |
| 333 | if ($term and !is_wp_error($term)){ |
| 334 | $attribute_pa = $term->name; |
| 335 | } |
| 336 | wp_all_export_write_article( $article, $element_name, $attribute_pa ); |
| 337 | } |
| 338 | |
| 339 | // if ( ! in_array($element_name, $attributes)) $attributes[] = $element_name; |
| 340 | } |
| 341 | break; |
| 342 | |
| 343 | case 'cats': |
| 344 | |
| 345 | if ( ! empty($fieldValue) ) |
| 346 | { |
| 347 | |
| 348 | // get categories from parent product in case when variation exported |
| 349 | if ($fieldLabel != 'product_shipping_class'){ |
| 350 | // get categories from parent product in case when variation exported |
| 351 | $entry_id = ( $entry->post_type == 'product_variation' ) ? $entry->post_parent : $entry->ID; |
| 352 | } |
| 353 | else{ |
| 354 | $entry_id = $entry->ID; |
| 355 | } |
| 356 | |
| 357 | // switch to post language if WPML installed |
| 358 | if ( class_exists('SitePress') ){ |
| 359 | $post_type = get_post_type($entry_id); |
| 360 | $post_type = apply_filters( 'wpml_element_type', $post_type ); |
| 361 | $post_language_details = apply_filters('wpml_element_language_details', |
| 362 | null, |
| 363 | array( |
| 364 | 'element_id' => $entry_id, |
| 365 | 'element_type' => $post_type |
| 366 | ) |
| 367 | ); |
| 368 | $language_code = empty($post_language_details->language_code) ? '' : $post_language_details->language_code; |
| 369 | $current_language = apply_filters('wpml_current_language', null); |
| 370 | do_action( 'wpml_switch_language', $language_code ); |
| 371 | } |
| 372 | |
| 373 | $txes_list = get_the_terms($entry_id, $fieldValue); |
| 374 | |
| 375 | $hierarchy_groups = array(); |
| 376 | |
| 377 | if ( ! is_wp_error($txes_list) and ! empty($txes_list) ) |
| 378 | { |
| 379 | $txes_ids = array(); |
| 380 | |
| 381 | foreach ($txes_list as $t) { |
| 382 | $txes_ids[] = $t->term_id; |
| 383 | } |
| 384 | |
| 385 | foreach ($txes_list as $t) { |
| 386 | if ( wp_all_export_check_children_assign($t->term_id, $fieldValue, $txes_ids) ){ |
| 387 | $ancestors = get_ancestors( $t->term_id, $fieldValue ); |
| 388 | if (count($ancestors) > 0){ |
| 389 | $hierarchy_group = array(); |
| 390 | for ( $i = count($ancestors) - 1; $i >= 0; $i-- ) { |
| 391 | $term = get_term_by('id', $ancestors[$i], $fieldValue); |
| 392 | if ($term){ |
| 393 | $hierarchy_group[] = $term->name; |
| 394 | } |
| 395 | } |
| 396 | $hierarchy_group[] = $t->name; |
| 397 | $hierarchy_groups[] = implode('>', $hierarchy_group); |
| 398 | } |
| 399 | else{ |
| 400 | $hierarchy_groups[] = $t->name; |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | // if ( empty($hierarchy_groups) ) $hierarchy_groups = ''; |
| 406 | |
| 407 | } |
| 408 | |
| 409 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_post_taxonomy', pmxe_filter(implode($implode_delimiter, $hierarchy_groups), $fieldSnipped), $entry->ID) ); |
| 410 | |
| 411 | // if ( ! in_array($element_name, $taxes)) $taxes[] = $element_name; |
| 412 | |
| 413 | if ($fieldLabel == 'product_type'){ |
| 414 | |
| 415 | if ( $entry->post_type == 'product_variation' ) $article[$element_name] = 'variable'; |
| 416 | |
| 417 | } |
| 418 | |
| 419 | // swith to current language if WPML installed |
| 420 | if ( class_exists('SitePress') ){ |
| 421 | do_action( 'wpml_switch_language', $current_language ); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | break; |
| 426 | |
| 427 | case 'sql': |
| 428 | |
| 429 | if ( ! empty($fieldSql) ) |
| 430 | { |
| 431 | global $wpdb; |
| 432 | $val = $wpdb->get_var( $wpdb->prepare( stripcslashes(str_replace("%%ID%%", "%d", $fieldSql)), $entry->ID )); |
| 433 | if ( ! empty($fieldPhp) and !empty($fieldCode) ) |
| 434 | { |
| 435 | // if shortcode defined |
| 436 | if (strpos($fieldCode, '[') === 0) { |
| 437 | $val = do_shortcode(str_replace("%%VALUE%%", $val, $fieldCode)); |
| 438 | } |
| 439 | else { |
| 440 | $val = eval('return ' . stripcslashes(str_replace("%%VALUE%%", $val, $fieldCode)) . ';'); |
| 441 | } |
| 442 | } |
| 443 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_sql_field', $val, $element_name, $entry->ID) ); |
| 444 | } |
| 445 | break; |
| 446 | |
| 447 | case 'wpml_trid': |
| 448 | |
| 449 | $post_type = get_post_type($entry->ID); |
| 450 | |
| 451 | $post_type = apply_filters( 'wpml_element_type', $post_type ); |
| 452 | |
| 453 | $post_language_details = apply_filters('wpml_element_language_details', |
| 454 | null, |
| 455 | array( |
| 456 | 'element_id' => $entry->ID, |
| 457 | 'element_type' => $post_type |
| 458 | ) |
| 459 | ); |
| 460 | |
| 461 | $trid = empty($post_language_details->trid) ? '' : $post_language_details->trid; |
| 462 | |
| 463 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_trid_field', $trid, $element_name, $entry->ID) ); |
| 464 | |
| 465 | break; |
| 466 | |
| 467 | case 'wpml_lang': |
| 468 | |
| 469 | $post_type = get_post_type($entry->ID); |
| 470 | |
| 471 | $post_type = apply_filters( 'wpml_element_type', $post_type ); |
| 472 | |
| 473 | $post_language_details = apply_filters('wpml_element_language_details', |
| 474 | null, |
| 475 | array( |
| 476 | 'element_id' => $entry->ID, |
| 477 | 'element_type' => $post_type |
| 478 | ) |
| 479 | ); |
| 480 | |
| 481 | $language_code = empty($post_language_details->language_code) ? '' : $post_language_details->language_code; |
| 482 | |
| 483 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_trid_field', $language_code, $element_name, $entry->ID) ); |
| 484 | |
| 485 | break; |
| 486 | |
| 487 | default: |
| 488 | # code... |
| 489 | break; |
| 490 | } |
| 491 | |
| 492 | if ( $is_xml_export and isset($article[$element_name]) ) { |
| 493 | $element_name_in_file = XmlCsvExport::_get_valid_header_name( $element_name ); |
| 494 | |
| 495 | $xmlWriter = apply_filters('wp_all_export_add_before_element', $xmlWriter, $element_name_in_file, XmlExportEngine::$exportID, $entry->ID); |
| 496 | |
| 497 | $xmlWriter->beginElement($element_name_ns, $element_name_in_file, null); |
| 498 | $xmlWriter->writeData($article[$element_name], $element_name_in_file); |
| 499 | $xmlWriter->closeElement(); |
| 500 | |
| 501 | $xmlWriter = apply_filters('wp_all_export_add_after_element', $xmlWriter, $element_name_in_file, XmlExportEngine::$exportID, $entry->ID); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | return $article; |
| 506 | } |
| 507 | |
| 508 | public static function prepare_import_template( $exportOptions, &$templateOptions, &$cf_list, &$attr_list, &$taxs_list, $element_name, $ID) |
| 509 | { |
| 510 | $options = $exportOptions; |
| 511 | |
| 512 | $element_type = $options['cc_type'][$ID]; |
| 513 | |
| 514 | $is_xml_template = $options['export_to'] == 'xml'; |
| 515 | |
| 516 | $implode_delimiter = XmlExportEngine::$implode; |
| 517 | |
| 518 | switch ($element_type) |
| 519 | { |
| 520 | case 'id': |
| 521 | if ($element_name == 'ID' && !$ID && $exportOptions['export_to'] == 'csv' && $exportOptions['export_to_sheet'] != 'csv'){ |
| 522 | $element_name = 'id'; |
| 523 | } |
| 524 | $templateOptions['unique_key'] = '{'. $element_name .'[1]}'; |
| 525 | $templateOptions['tmp_unique_key'] = '{'. $element_name .'[1]}'; |
| 526 | $templateOptions['single_product_id'] = '{'. $element_name .'[1]}'; |
| 527 | break; |
| 528 | case 'title': |
| 529 | $templateOptions[$element_type] = '{'. $element_name .'[1]}'; |
| 530 | $templateOptions['is_update_' . $options['cc_type'][$ID]] = 1; |
| 531 | $templateOptions['single_product_id_first_is_variation'] = '{'. $element_name .'[1]}'; |
| 532 | break; |
| 533 | case 'content': |
| 534 | case 'author': |
| 535 | $templateOptions[$element_type] = '{'. $element_name .'[1]}'; |
| 536 | $templateOptions['is_update_' . $options['cc_type'][$ID]] = 1; |
| 537 | break; |
| 538 | case 'slug': |
| 539 | $templateOptions['post_slug'] = '{'. $element_name .'[1]}'; |
| 540 | $templateOptions['is_update_' . $options['cc_type'][$ID]] = 1; |
| 541 | break; |
| 542 | case 'parent_slug': |
| 543 | $templateOptions['is_multiple_page_parent'] = 'no'; |
| 544 | $templateOptions['single_page_parent'] = '{' . $element_name . '[1]}'; |
| 545 | $templateOptions['is_update_parent'] = 1; |
| 546 | break; |
| 547 | case 'parent': |
| 548 | $templateOptions['single_product_parent_id'] = '{' . $element_name . '[1]}'; |
| 549 | $templateOptions['single_product_id_first_is_parent_id'] = '{' . $element_name . '[1]}'; |
| 550 | break; |
| 551 | case 'excerpt': |
| 552 | $templateOptions['post_excerpt'] = '{'. $element_name .'[1]}'; |
| 553 | $templateOptions['is_update_' . $options['cc_type'][$ID]] = 1; |
| 554 | break; |
| 555 | case 'status': |
| 556 | $templateOptions['status_xpath'] = '{'. $element_name .'[1]}'; |
| 557 | $templateOptions['is_update_status'] = 1; |
| 558 | break; |
| 559 | case 'date': |
| 560 | $templateOptions[$element_type] = '{'. $element_name .'[1]}'; |
| 561 | $templateOptions['is_update_dates'] = 1; |
| 562 | break; |
| 563 | case 'order': |
| 564 | $templateOptions[$element_type] = '{'. $element_name .'[1]}'; |
| 565 | $templateOptions['is_update_menu_order'] = 1; |
| 566 | $templateOptions['single_product_menu_order'] = '{'. $element_name .'[1]}'; |
| 567 | break; |
| 568 | case 'post_type': |
| 569 | |
| 570 | if ( empty($options['cpt']) ) |
| 571 | { |
| 572 | $templateOptions['is_override_post_type'] = 1; |
| 573 | $templateOptions['post_type_xpath'] = '{'. $element_name .'[1]}'; |
| 574 | } |
| 575 | break; |
| 576 | |
| 577 | case 'cf': |
| 578 | |
| 579 | if ( ! empty($options['cc_value'][$ID]) ) |
| 580 | { |
| 581 | $exclude_cf = array('_thumbnail_id'); |
| 582 | |
| 583 | if (strpos($options['cc_value'][$ID], 'attribute_') === 0 and ! in_array($options['cc_value'][$ID], $attr_list)) |
| 584 | { |
| 585 | $templateOptions['attribute_name'][] = str_replace('attribute_', '', $options['cc_value'][$ID]); |
| 586 | $templateOptions['attribute_value'][] = '{'. $element_name .'[1]}'; |
| 587 | $templateOptions['in_variations'][] = "1"; |
| 588 | $templateOptions['is_visible'][] = "1"; |
| 589 | $templateOptions['is_taxonomy'][] = "0"; |
| 590 | $templateOptions['create_taxonomy_in_not_exists'][] = "0"; |
| 591 | $attr_list[] = $options['cc_value'][$ID]; |
| 592 | } |
| 593 | elseif ( ! in_array($options['cc_value'][$ID], $cf_list) and ! in_array($options['cc_value'][$ID], $exclude_cf) ) |
| 594 | { |
| 595 | $cf_list[] = $options['cc_value'][$ID]; |
| 596 | |
| 597 | $templateOptions['custom_name'][] = $options['cc_value'][$ID]; |
| 598 | $templateOptions['custom_value'][] = '{'. $element_name .'[1]}'; |
| 599 | $templateOptions['custom_format'][] = 0; |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | break; |
| 604 | |
| 605 | case 'attr': |
| 606 | |
| 607 | if ( ! empty($options['cc_value'][$ID]) and ! in_array($options['cc_value'][$ID], $attr_list) ) |
| 608 | { |
| 609 | $templateOptions['attribute_name'][] = str_replace('pa_', '', $options['cc_value'][$ID]); |
| 610 | $templateOptions['attribute_value'][] = '{'. $element_name .'[1]}'; |
| 611 | $templateOptions['in_variations'][] = "1"; |
| 612 | $templateOptions['is_visible'][] = "1"; |
| 613 | $templateOptions['is_taxonomy'][] = "1"; |
| 614 | $templateOptions['create_taxonomy_in_not_exists'][] = "1"; |
| 615 | $attr_list[] = $options['cc_value'][$ID]; |
| 616 | } |
| 617 | |
| 618 | break; |
| 619 | case 'cats': |
| 620 | if ( ! empty($options['cc_value'][$ID]) ) |
| 621 | { |
| 622 | switch ($options['cc_label'][$ID]) |
| 623 | { |
| 624 | case 'product_type': |
| 625 | $templateOptions['is_multiple_product_type'] = 'no'; |
| 626 | $templateOptions['single_product_type'] = '{'. $element_name .'[1]}'; |
| 627 | break; |
| 628 | case 'product_shipping_class': |
| 629 | $templateOptions['is_multiple_product_shipping_class'] = 'no'; |
| 630 | $templateOptions['single_product_shipping_class'] = '{'. $element_name .'[1]}'; |
| 631 | break; |
| 632 | default: |
| 633 | $taxonomy = $options['cc_value'][$ID]; |
| 634 | $templateOptions['tax_assing'][$taxonomy] = 1; |
| 635 | |
| 636 | if (is_taxonomy_hierarchical($taxonomy)) |
| 637 | { |
| 638 | $templateOptions['tax_logic'][$taxonomy] = 'hierarchical'; |
| 639 | $templateOptions['tax_hierarchical_logic_entire'][$taxonomy] = 1; |
| 640 | $templateOptions['multiple_term_assing'][$taxonomy] = 1; |
| 641 | $templateOptions['tax_hierarchical_delim'][$taxonomy] = '>'; |
| 642 | $templateOptions['is_tax_hierarchical_group_delim'][$taxonomy] = 1; |
| 643 | $templateOptions['tax_hierarchical_group_delim'][$taxonomy] = $is_xml_template ? '|' : $implode_delimiter; |
| 644 | $templateOptions['tax_hierarchical_xpath'][$taxonomy] = array('{'. $element_name .'[1]}'); |
| 645 | } |
| 646 | else{ |
| 647 | $templateOptions['tax_logic'][$taxonomy] = 'multiple'; |
| 648 | $templateOptions['multiple_term_assing'][$taxonomy] = 1; |
| 649 | $templateOptions['tax_multiple_xpath'][$taxonomy] = '{'. $element_name .'[1]}'; |
| 650 | $templateOptions['tax_multiple_delim'][$taxonomy] = $is_xml_template ? '|' : $implode_delimiter; |
| 651 | } |
| 652 | $taxs_list[] = $taxonomy; |
| 653 | break; |
| 654 | } |
| 655 | } |
| 656 | break; |
| 657 | } |
| 658 | } |
| 659 | } |