Beispiel #1
0
 /**
  * Step #3: Choose template
  */
 public function template()
 {
     $template = new PMXI_Template_Record();
     $default = PMXI_Plugin::get_default_import_options();
     if ($this->isWizard) {
         $this->data['source_type'] = PMXI_Plugin::$session->source['type'];
         $DefaultOptions = (isset(PMXI_Plugin::$session->options) ? PMXI_Plugin::$session->options : array()) + $default;
         foreach (PMXI_Admin_Addons::get_active_addons() as $class) {
             if (class_exists($class)) {
                 $DefaultOptions += call_user_func(array($class, "get_default_import_options"));
             }
         }
         $DefaultOptions['wizard_type'] = PMXI_Plugin::$session->wizard_type;
         $DefaultOptions['custom_type'] = PMXI_Plugin::$session->custom_type;
         $DefaultOptions['delimiter'] = PMXI_Plugin::$session->is_csv;
         $post = $this->input->post(apply_filters('pmxi_options_options', $DefaultOptions, $this->isWizard));
     } else {
         $this->data['source_type'] = $this->data['import']->type;
         $DefaultOptions = is_array($this->data['import']->options) ? $this->data['import']->options + $default : $default;
         foreach (PMXI_Admin_Addons::get_active_addons() as $class) {
             if (class_exists($class)) {
                 $DefaultOptions += call_user_func(array($class, "get_default_import_options"));
             }
         }
         $source = array('name' => $this->data['import']->name, 'type' => $this->data['import']->type, 'path' => wp_all_import_get_relative_path($this->data['import']->path), 'root_element' => $this->data['import']->root_element);
         PMXI_Plugin::$session->set('source', $source);
         $post = $this->input->post(apply_filters('pmxi_options_options', $DefaultOptions, $this->isWizard));
     }
     $this->data['post'] =& $post;
     PMXI_Plugin::$session->set('options', $post);
     PMXI_Plugin::$session->set('is_loaded_template', '');
     if ($load_template = $this->input->post('load_template')) {
         // init form with template selected
         if (!$template->getById($load_template)->isEmpty()) {
             $template_options = $template->options;
             $template_options['type'] = $post['type'];
             $template_options['custom_type'] = $post['custom_type'];
             $template_options['wizard_type'] = $post['wizard_type'];
             $template_options['delimiter'] = $post['delimiter'];
             if ($this->isWizard and $post['wizard_type'] == 'new') {
                 $template_options['create_new_records'] = 1;
             }
             $this->data['post'] = $template_options;
             PMXI_Plugin::$session->set('is_loaded_template', $load_template);
             PMXI_Plugin::$session->set('options', $template_options);
         }
     } elseif ($this->input->post('is_submitted')) {
         // save template submission
         check_admin_referer('template', '_wpnonce_template');
         if (!empty($post['title'])) {
             $this->_validate_template($post['title'], 'Post title');
         } else {
             $this->warnings->add('1', __('<strong>Warning:</strong> your title is blank.', 'wp_all_import_plugin'));
         }
         if (!empty($post['content'])) {
             $this->_validate_template($post['content'], 'Post content');
         } else {
             $this->warnings->add('2', __('<strong>Warning:</strong> your content is blank.', 'wp_all_import_plugin'));
         }
         if (!$this->errors->get_error_codes()) {
             // Attributes fields logic
             $post = apply_filters('pmxi_save_options', $post);
             // validate post excerpt
             if (!empty($post['post_excerpt'])) {
                 $this->_validate_template($post['post_excerpt'], __('Excerpt', 'wp_all_import_plugin'));
             }
             // validate images
             if ($post['download_images'] == 'yes') {
                 if (!empty($post['download_featured_image'])) {
                     $this->_validate_template($post['download_featured_image'], __('Images', 'wp_all_import_plugin'));
                 }
             } else {
                 if (!empty($post['featured_image'])) {
                     $this->_validate_template($post['featured_image'], __('Images', 'wp_all_import_plugin'));
                 }
             }
             // validate images meta data
             foreach (array('title', 'caption', 'alt', 'decription') as $section) {
                 if ($post['set_image_meta_' . $section]) {
                     if (!empty($post['image_meta_' . $section])) {
                         $this->_validate_template($post['image_meta_' . $section], __('Images meta ' . $section, 'wp_all_import_plugin'));
                     }
                 }
             }
             // remove entires where both custom_name and custom_value are empty
             $not_empty = array_flip(array_values(array_merge(array_keys(array_filter($post['custom_name'], 'strlen')), array_keys(array_filter($post['custom_value'], 'strlen')))));
             $post['custom_name'] = array_intersect_key($post['custom_name'], $not_empty);
             $post['custom_value'] = array_intersect_key($post['custom_value'], $not_empty);
             // validate
             if (array_keys(array_filter($post['custom_name'], 'strlen')) != array_keys(array_filter($post['custom_value'], 'strlen')) and !count(array_filter($post['custom_format']))) {
                 $this->errors->add('form-validation', __('Both name and value must be set for all custom parameters', 'wp_all_import_plugin'));
             } else {
                 foreach ($post['custom_name'] as $custom_name) {
                     $this->_validate_template($custom_name, __('Custom Field Name', 'wp_all_import_plugin'));
                 }
                 foreach ($post['custom_value'] as $key => $custom_value) {
                     if (empty($post['custom_format'][$key])) {
                         $this->_validate_template($custom_value, __('Custom Field Value', 'wp_all_import_plugin'));
                     }
                 }
             }
             if ($post['type'] == "post" and $post['custom_type'] == "product" and class_exists('PMWI_Plugin')) {
                 // remove entires where both custom_name and custom_value are empty
                 $not_empty = array_flip(array_values(array_merge(array_keys(array_filter($post['attribute_name'], 'strlen')), array_keys(array_filter($post['attribute_value'], 'strlen')))));
                 $post['attribute_name'] = array_intersect_key($post['attribute_name'], $not_empty);
                 $post['attribute_value'] = array_intersect_key($post['attribute_value'], $not_empty);
                 // validate
                 if (array_keys(array_filter($post['attribute_name'], 'strlen')) != array_keys(array_filter($post['attribute_value'], 'strlen'))) {
                     $this->errors->add('form-validation', __('Both name and value must be set for all woocommerce attributes', 'wp_all_import_plugin'));
                 } else {
                     foreach ($post['attribute_name'] as $attribute_name) {
                         $this->_validate_template($attribute_name, __('Attribute Field Name', 'wp_all_import_plugin'));
                     }
                     foreach ($post['attribute_value'] as $custom_value) {
                         $this->_validate_template($custom_value, __('Attribute Field Value', 'wp_all_import_plugin'));
                     }
                 }
             }
             /*if ('page' == $post['type'] and ! preg_match('%^(-?\d+)?$%', $post['order'])) {
             			$this->errors->add('form-validation', __('Order must be an integer number', 'wp_all_import_plugin'));
             		}*/
             if ('post' == $post['type']) {
                 /*'' == $post['categories'] or $this->_validate_template($post['categories'], __('Categories', 'wp_all_import_plugin'));*/
                 '' == $post['tags'] or $this->_validate_template($post['tags'], __('Tags', 'wp_all_import_plugin'));
             }
             if ('specific' == $post['date_type']) {
                 '' == $post['date'] or $this->_validate_template($post['date'], __('Date', 'wp_all_import_plugin'));
             } else {
                 '' == $post['date_start'] or $this->_validate_template($post['date_start'], __('Start Date', 'wp_all_import_plugin'));
                 '' == $post['date_end'] or $this->_validate_template($post['date_end'], __('Start Date', 'wp_all_import_plugin'));
             }
             /*if ('' == $post['tags_delim']) {
             			$this->errors->add('form-validation', __('Tag list delimiter must cannot be empty', 'wp_all_import_plugin'));
             		}*/
             $this->errors = apply_filters('pmxi_options_validation', $this->errors, $post, $this->data['import']);
             if (!$this->errors->get_error_codes()) {
                 // no validation errors found
                 // assign some defaults
                 '' !== $post['date'] or $post['date'] = 'now';
                 '' !== $post['date_start'] or $post['date_start'] = 'now';
                 '' !== $post['date_end'] or $post['date_end'] = 'now';
                 if (!empty($post['name']) and !empty($post['save_template_as'])) {
                     // save template in database
                     $template->getByName($post['name'])->set(array('name' => $post['name'], 'is_keep_linebreaks' => $post['is_keep_linebreaks'], 'is_leave_html' => $post['is_leave_html'], 'fix_characters' => $post['fix_characters'], 'options' => $post))->save();
                     PMXI_Plugin::$session->set('saved_template', $template->id);
                 }
                 if ($this->isWizard) {
                     PMXI_Plugin::$session->set('options', $post);
                     PMXI_Plugin::$session->save_data();
                     wp_redirect(add_query_arg('action', 'options', $this->baseUrl));
                     die;
                 } else {
                     $this->data['import']->set(array('options' => $post, 'settings_update_on' => date('Y-m-d H:i:s')))->update();
                     $args = array('page' => 'pmxi-admin-manage', 'pmxi_nt' => urlencode(__('Template updated', 'wp_all_import_plugin')));
                     if ($this->warnings->get_error_codes()) {
                         $args['warnings'] = implode(',', $this->warnings->get_error_codes());
                     }
                     wp_redirect(add_query_arg($args + array_intersect_key($_GET, array_flip($this->baseUrlParamNames)), admin_url('admin.php')));
                     die;
                 }
             }
         }
     }
     PMXI_Plugin::$session->save_data();
     if (!in_array($post['custom_type'], array('import_users'))) {
         global $wpdb;
         // Get all meta keys for requested post type
         $this->data['meta_keys'] = array();
         $hide_fields = array('_wp_page_template', '_edit_lock', '_edit_last', '_wp_trash_meta_status', '_wp_trash_meta_time');
         $records = get_posts(array('post_type' => $post['custom_type']));
         if (!empty($records)) {
             foreach ($records as $record) {
                 $record_meta = get_post_meta($record->ID, '');
                 if (!empty($record_meta)) {
                     foreach ($record_meta as $record_meta_key => $record_meta_value) {
                         if (!in_array($record_meta_key, $this->data['meta_keys']) and !in_array($record_meta_key, $hide_fields)) {
                             $this->data['meta_keys'][] = $record_meta_key;
                         }
                     }
                 }
             }
         }
         // Get existing product attributes
         $existing_attributes = $wpdb->get_results("SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '_product_attributes' LIMIT 0 , 50");
         $this->data['existing_attributes'] = array();
         if (!empty($existing_attributes)) {
             foreach ($existing_attributes as $key => $existing_attribute) {
                 $existing_attribute = maybe_unserialize($existing_attribute->meta_value);
                 if (!empty($existing_attribute) and is_array($existing_attribute)) {
                     foreach ($existing_attribute as $key => $value) {
                         if (strpos($key, "pa_") === false and !in_array($key, $this->data['existing_attributes'])) {
                             $this->data['existing_attributes'][] = $key;
                         }
                     }
                 }
             }
         }
     } else {
         // Get All meta keys in the system
         $this->data['meta_keys'] = array();
         $meta_keys = new PMXI_Model_List();
         $meta_keys->setTable(PMXI_Plugin::getInstance()->getWPPrefix() . 'usermeta');
         $meta_keys->setColumns('umeta_id', 'meta_key')->getBy(NULL, "umeta_id", NULL, NULL, "meta_key");
         $hide_fields = array('first_name', 'last_name', 'nickname', 'description', PMXI_Plugin::getInstance()->getWPPrefix() . 'capabilities');
         if (!empty($meta_keys) and $meta_keys->count()) {
             foreach ($meta_keys as $meta_key) {
                 if (in_array($meta_key['meta_key'], $hide_fields) or strpos($meta_key['meta_key'], '_wp') === 0) {
                     continue;
                 }
                 $this->data['meta_keys'][] = $meta_key['meta_key'];
             }
         }
     }
     if (user_can_richedit()) {
         wp_enqueue_script('editor');
     }
     wp_enqueue_script('word-count');
     add_thickbox();
     wp_enqueue_script('media-upload');
     wp_enqueue_script('quicktags');
     $this->render();
 }
Beispiel #2
0
 /**
  * Step #4: Options
  */
 public function options()
 {
     $default = PMXI_Plugin::get_default_import_options();
     if ($this->isWizard) {
         $this->data['source_type'] = PMXI_Plugin::$session->data['pmxi_import']['source']['type'];
         $default['unique_key'] = PMXI_Plugin::$session->data['pmxi_import']['template']['title'];
         $keys_black_list = array('programurl');
         // auto searching ID element
         if (!empty($this->data['dom'])) {
             $this->find_unique_key($this->data['dom']->documentElement);
             if (!empty($this->_unique_key)) {
                 foreach ($keys_black_list as $key => $value) {
                     $default['unique_key'] = str_replace('{' . $value . '[1]}', "", $default['unique_key']);
                 }
                 foreach ($this->_unique_key as $key) {
                     if (stripos($key, 'id') !== false) {
                         $default['unique_key'] .= ' - {' . $key . '[1]}';
                         break;
                     }
                 }
                 foreach ($this->_unique_key as $key) {
                     if (stripos($key, 'url') !== false or stripos($key, 'sku') !== false or stripos($key, 'ref') !== false) {
                         if (!in_array($key, $keys_black_list)) {
                             $default['unique_key'] .= ' - {' . $key . '[1]}';
                             break;
                         }
                     }
                 }
             }
         }
         $DefaultOptions = (isset(PMXI_Plugin::$session->data['pmxi_import']['options']) ? PMXI_Plugin::$session->data['pmxi_import']['options'] : array()) + $default;
         foreach (PMXI_Admin_Addons::get_active_addons() as $class) {
             if (class_exists($class)) {
                 $DefaultOptions += call_user_func(array($class, "get_default_import_options"));
             }
         }
         $post = $this->input->post(apply_filters('pmxi_options_options', $DefaultOptions, $this->isWizard));
     } else {
         $this->data['source_type'] = $this->data['import']->type;
         $DefaultOptions = $this->data['import']->options + $default;
         foreach (PMXI_Admin_Addons::get_active_addons() as $class) {
             if (class_exists($class)) {
                 $DefaultOptions += call_user_func(array($class, "get_default_import_options"));
             }
         }
         $post = $this->input->post(apply_filters('pmxi_options_options', $DefaultOptions, $this->isWizard));
     }
     $this->data['post'] =& $post;
     // Get All meta keys in the system
     $this->data['meta_keys'] = $keys = new PMXI_Model_List();
     $keys->setTable(PMXI_Plugin::getInstance()->getWPPrefix() . 'postmeta');
     $keys->setColumns('meta_id', 'meta_key')->getBy(NULL, "meta_id", NULL, NULL, "meta_key");
     global $wpdb;
     $existing_attributes = $wpdb->get_results("SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '_product_attributes'");
     $this->data['existing_attributes'] = array();
     if (!empty($existing_attributes)) {
         foreach ($existing_attributes as $key => $existing_attribute) {
             $existing_attribute = maybe_unserialize($existing_attribute->meta_value);
             if (!empty($existing_attribute) and is_array($existing_attribute)) {
                 foreach ($existing_attribute as $key => $value) {
                     if (strpos($key, "pa_") === false and !in_array($key, $this->data['existing_attributes'])) {
                         $this->data['existing_attributes'][] = $key;
                     }
                 }
             }
         }
     }
     $load_template = $this->input->post('load_template');
     if ($load_template) {
         // init form with template selected
         PMXI_Plugin::$session['pmxi_import']['is_loaded_template'] = $load_template;
         $template = new PMXI_Template_Record();
         if (!$template->getById($load_template)->isEmpty()) {
             $post = (!empty($template->options) ? $template->options : array()) + $default;
         }
     }
     $this->data['get'] = $this->input->get(array('pmxi-cpt' => !empty($post['custom_type']) ? $post['custom_type'] : $post['type']));
     if ($load_template == -1) {
         PMXI_Plugin::$session['pmxi_import']['is_loaded_template'] = 0;
         $post = $default;
     } elseif ($this->input->post('is_submitted')) {
         check_admin_referer('options', '_wpnonce_options');
         // Categories/taxonomies logic
         if ($post['update_categories_logic'] == 'only') {
             $post['taxonomies_list'] = explode(",", $post['taxonomies_only_list']);
         } elseif ($post['update_categories_logic'] == 'all_except') {
             $post['taxonomies_list'] = explode(",", $post['taxonomies_except_list']);
         }
         // Custom fields logic
         if ($post['update_custom_fields_logic'] == 'only') {
             $post['custom_fields_list'] = explode(",", $post['custom_fields_only_list']);
         } elseif ($post['update_custom_fields_logic'] == 'all_except') {
             $post['custom_fields_list'] = explode(",", $post['custom_fields_except_list']);
         }
         // Attributes fields logic
         $post = apply_filters('pmxi_save_options', $post);
         // remove entires where both custom_name and custom_value are empty
         $not_empty = array_flip(array_values(array_merge(array_keys(array_filter($post['custom_name'], 'strlen')), array_keys(array_filter($post['custom_value'], 'strlen')))));
         $post['custom_name'] = array_intersect_key($post['custom_name'], $not_empty);
         $post['custom_value'] = array_intersect_key($post['custom_value'], $not_empty);
         // validate
         if (array_keys(array_filter($post['custom_name'], 'strlen')) != array_keys(array_filter($post['custom_value'], 'strlen')) and !count(array_filter($post['custom_format']))) {
             $this->errors->add('form-validation', __('Both name and value must be set for all custom parameters', 'pmxi_plugin'));
         } else {
             foreach ($post['custom_name'] as $custom_name) {
                 $this->_validate_template($custom_name, __('Custom Field Name', 'pmxi_plugin'));
             }
             foreach ($post['custom_value'] as $key => $custom_value) {
                 if (empty($post['custom_format'][$key])) {
                     $this->_validate_template($custom_value, __('Custom Field Value', 'pmxi_plugin'));
                 }
             }
         }
         if ($post['type'] == "post" and $post['custom_type'] == "product" and class_exists('PMWI_Plugin')) {
             // remove entires where both custom_name and custom_value are empty
             $not_empty = array_flip(array_values(array_merge(array_keys(array_filter($post['attribute_name'], 'strlen')), array_keys(array_filter($post['attribute_value'], 'strlen')))));
             $post['attribute_name'] = array_intersect_key($post['attribute_name'], $not_empty);
             $post['attribute_value'] = array_intersect_key($post['attribute_value'], $not_empty);
             // validate
             if (array_keys(array_filter($post['attribute_name'], 'strlen')) != array_keys(array_filter($post['attribute_value'], 'strlen'))) {
                 $this->errors->add('form-validation', __('Both name and value must be set for all woocommerce attributes', 'pmxi_plugin'));
             } else {
                 foreach ($post['attribute_name'] as $attribute_name) {
                     $this->_validate_template($attribute_name, __('Attribute Field Name', 'pmxi_plugin'));
                 }
                 foreach ($post['attribute_value'] as $custom_value) {
                     $this->_validate_template($custom_value, __('Attribute Field Value', 'pmxi_plugin'));
                 }
             }
         }
         if ('page' == $post['type'] and !preg_match('%^(-?\\d+)?$%', $post['order'])) {
             $this->errors->add('form-validation', __('Order must be an integer number', 'pmxi_plugin'));
         }
         if ('post' == $post['type']) {
             /*'' == $post['categories'] or $this->_validate_template($post['categories'], __('Categories', 'pmxi_plugin'));*/
             '' == $post['tags'] or $this->_validate_template($post['tags'], __('Tags', 'pmxi_plugin'));
         }
         if ('specific' == $post['date_type']) {
             '' == $post['date'] or $this->_validate_template($post['date'], __('Date', 'pmxi_plugin'));
         } else {
             '' == $post['date_start'] or $this->_validate_template($post['date_start'], __('Start Date', 'pmxi_plugin'));
             '' == $post['date_end'] or $this->_validate_template($post['date_end'], __('Start Date', 'pmxi_plugin'));
         }
         if ('' == $post['tags_delim']) {
             $this->errors->add('form-validation', __('Tag list delimiter must cannot be empty', 'pmxi_plugin'));
         }
         if ($post['is_import_specified']) {
             if (empty($post['import_specified'])) {
                 $this->errors->add('form-validation', __('Records to import must be specified or uncheck `Import only specified records` option to process all records', 'pmxi_plugin'));
             } else {
                 $chanks = preg_split('% *, *%', $post['import_specified']);
                 foreach ($chanks as $chank) {
                     if (!preg_match('%^([1-9]\\d*)( *- *([1-9]\\d*))?$%', $chank, $mtch)) {
                         $this->errors->add('form-validation', __('Wrong format of `Import only specified records` value', 'pmxi_plugin'));
                         break;
                     } elseif (isset($mtch[3]) and intval($mtch[3]) > PMXI_Plugin::$session->data['pmxi_import']['count']) {
                         $this->errors->add('form-validation', __('One of the numbers in `Import only specified records` value exceeds record quantity in XML file', 'pmxi_plugin'));
                         break;
                     }
                 }
             }
         }
         if ('' == $post['unique_key']) {
             $this->errors->add('form-validation', __('Expression for `Post Unique Key` must be set, use the same expression as specified for post title if you are not sure what to put there', 'pmxi_plugin'));
         } else {
             $this->_validate_template($post['unique_key'], __('Post Unique Key', 'pmxi_plugin'));
         }
         if ('manual' == $post['duplicate_matching'] and 'custom field' == $post['duplicate_indicator']) {
             if ('' == $post['custom_duplicate_name']) {
                 $this->errors->add('form-validation', __('Custom field name must be specified.', 'pmxi_plugin'));
             }
             if ('' == $post['custom_duplicate_value']) {
                 $this->errors->add('form-validation', __('Custom field value must be specified.', 'pmxi_plugin'));
             }
         }
         $this->errors = apply_filters('pmxi_options_validation', $this->errors, $post, $this->data['import']);
         if (!$this->errors->get_error_codes()) {
             // no validation errors found
             // assign some defaults
             '' !== $post['date'] or $post['date'] = 'now';
             '' !== $post['date_start'] or $post['date_start'] = 'now';
             '' !== $post['date_end'] or $post['date_end'] = 'now';
             if ($this->input->post('name')) {
                 // save template in database
                 $template = new PMXI_Template_Record();
                 $template->getByName($this->input->post('name'))->set(array('name' => $this->input->post('name'), 'options' => $post))->save();
             }
             if ($this->isWizard) {
                 PMXI_Plugin::$session['pmxi_import']['options'] = $post;
                 pmxi_session_commit();
                 if (!$this->input->post('save_only')) {
                     wp_redirect(add_query_arg('action', 'process', $this->baseUrl));
                     die;
                 } else {
                     $import = $this->data['update_previous'];
                     $is_update = !$import->isEmpty();
                     $import->set(PMXI_Plugin::$session->data['pmxi_import']['source'] + array('xpath' => PMXI_Plugin::$session->data['pmxi_import']['xpath'], 'template' => PMXI_Plugin::$session->data['pmxi_import']['template'], 'options' => PMXI_Plugin::$session->data['pmxi_import']['options'], 'count' => PMXI_Plugin::$session->data['pmxi_import']['count'], 'friendly_name' => $this->data['post']['friendly_name']))->save();
                     $history_file = new PMXI_File_Record();
                     $history_file->set(array('name' => $import->name, 'import_id' => $import->id, 'path' => PMXI_Plugin::$session->data['pmxi_import']['filePath'], 'contents' => $this->get_xml(), 'registered_on' => date('Y-m-d H:i:s')))->save();
                     pmxi_session_unset();
                     wp_redirect(add_query_arg(array('page' => 'pmxi-admin-manage', 'pmlc_nt' => urlencode($is_update ? __('Import updated', 'pmxi_plugin') : __('Import created', 'pmxi_plugin'))), admin_url('admin.php')));
                     die;
                 }
             } else {
                 $this->data['import']->set('options', $post)->set(array('scheduled' => '', 'friendly_name' => $this->data['post']['friendly_name']))->save();
                 wp_redirect(add_query_arg(array('page' => 'pmxi-admin-manage', 'pmlc_nt' => urlencode(__('Options updated', 'pmxi_plugin'))) + array_intersect_key($_GET, array_flip($this->baseUrlParamNames)), admin_url('admin.php')));
                 die;
             }
         }
     }
     !empty($post['custom_name']) or $post['custom_name'] = array('') and $post['custom_value'] = array('');
     if ($post['type'] == "product" and class_exists('PMWI_Plugin')) {
         !empty($post['attribute_name']) or $post['attribute_name'] = array('') and $post['attribute_value'] = array('');
     }
     pmxi_session_commit();
     $this->render();
 }
Beispiel #3
0
 public function get_template()
 {
     $nonce = !empty($_REQUEST['_wpnonce']) ? $_REQUEST['_wpnonce'] : '';
     if (!wp_verify_nonce($nonce, '_wpnonce-download_template')) {
         die(__('Security check', 'wp_all_export_plugin'));
     } else {
         $id = $this->input->get('id');
         $export = new PMXE_Export_Record();
         $filepath = '';
         $export_data = array();
         if (!$export->getById($id)->isEmpty()) {
             $template = new PMXI_Template_Record();
             if (!empty($export->options['template_name'])) {
                 $template->getByName($export->options['template_name']);
                 if (!$template->isEmpty()) {
                     $export_data[] = $template->toArray(TRUE);
                     $uploads = wp_upload_dir();
                     $targetDir = $uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::TEMP_DIRECTORY;
                     $export_file_name = "templates_" . uniqid() . ".txt";
                     file_put_contents($targetDir . DIRECTORY_SEPARATOR . $export_file_name, json_encode($export_data));
                     PMXI_download::csv($targetDir . DIRECTORY_SEPARATOR . $export_file_name);
                 }
             }
         }
     }
 }
Beispiel #4
0
 /**
  * Import all files matched by path
  * @param callback[optional] $logger Method where progress messages are submmitted
  * @return PMXI_Import_Record
  * @chainable
  */
 public function execute($logger = NULL, $cron = false)
 {
     $this->set('registered_on', date('Y-m-d H:i:s'))->save();
     // update registered_on to indicated that job has been exectured even if no files are going to be imported by the rest of the method
     $wp_uploads = wp_upload_dir();
     $this->set(array('processing' => 1))->update();
     // lock cron requests
     wp_reset_postdata();
     XmlExportEngine::$exportOptions = $this->options;
     XmlExportEngine::$is_user_export = $this->options['is_user_export'];
     if ('advanced' == $this->options['export_type']) {
         if (XmlExportEngine::$is_user_export) {
             $exportQuery = eval('return new WP_User_Query(array(' . $this->options['wp_query'] . ', \'orderby\' => \'ID\', \'order\' => \'ASC\', \'offset\' => ' . $this->exported . ', \'number\' => ' . $this->options['records_per_iteration'] . '));');
         } else {
             $exportQuery = eval('return new WP_Query(array(' . $this->options['wp_query'] . ', \'orderby\' => \'ID\', \'order\' => \'ASC\', \'offset\' => ' . $this->exported . ', \'posts_per_page\' => ' . $this->options['records_per_iteration'] . '));');
         }
     } else {
         XmlExportEngine::$post_types = $this->options['cpt'];
         if (!in_array('users', $this->options['cpt'])) {
             add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
             add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
             $exportQuery = new WP_Query(array('post_type' => $this->options['cpt'], 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'offset' => $this->exported, 'posts_per_page' => $this->options['records_per_iteration']));
             remove_filter('posts_join', 'wp_all_export_posts_join');
             remove_filter('posts_where', 'wp_all_export_posts_where');
         } else {
             add_action('pre_user_query', 'wp_all_export_pre_user_query', 10, 1);
             $exportQuery = new WP_User_Query(array('orderby' => 'ID', 'order' => 'ASC', 'number' => $this->options['records_per_iteration'], 'offset' => $this->exported));
             remove_action('pre_user_query', 'wp_all_export_pre_user_query');
         }
     }
     XmlExportEngine::$exportQuery = $exportQuery;
     $file_path = false;
     $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
     if ($this->exported == 0) {
         $import = new PMXI_Import_Record();
         $import->getById($this->options['import_id']);
         if ($import->isEmpty()) {
             $import->set(array('parent_import_id' => 99999, 'xpath' => '/', 'type' => 'upload', 'options' => array('empty'), 'root_element' => 'root', 'path' => 'path', 'imported' => 0, 'created' => 0, 'updated' => 0, 'skipped' => 0, 'deleted' => 0, 'iteration' => 1))->save();
             $exportOptions = $this->options;
             $exportOptions['import_id'] = $import->id;
             $this->set(array('options' => $exportOptions))->save();
         } else {
             if ($import->parent_import_id != 99999) {
                 $newImport = new PMXI_Import_Record();
                 $newImport->set(array('parent_import_id' => 99999, 'xpath' => '/', 'type' => 'upload', 'options' => array('empty'), 'root_element' => 'root', 'path' => 'path', 'imported' => 0, 'created' => 0, 'updated' => 0, 'skipped' => 0, 'deleted' => 0, 'iteration' => 1))->save();
                 $exportOptions = $this->options;
                 $exportOptions['import_id'] = $newImport->id;
                 $this->set(array('options' => $exportOptions))->save();
             }
         }
         if (!empty($this->attch_id)) {
             wp_delete_attachment($this->attch_id, true);
         }
         $target = $is_secure_import ? wp_all_export_secure_file($wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::UPLOADS_DIRECTORY) : $wp_uploads['path'];
         $file_path = $target . DIRECTORY_SEPARATOR . time() . '.' . $this->options['export_to'];
         if (!$is_secure_import) {
             $wp_filetype = wp_check_filetype(basename($file_path), null);
             $attachment_data = array('guid' => $wp_uploads['baseurl'] . '/' . _wp_relative_upload_path($file_path), 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($file_path)), 'post_content' => '', 'post_status' => 'inherit');
             $attach_id = wp_insert_attachment($attachment_data, $file_path);
             $this->set(array('attch_id' => $attach_id))->save();
         } else {
             wp_all_export_remove_source(wp_all_export_get_absolute_path($this->options['filepath']));
             $exportOptions = $this->options;
             $exportOptions['filepath'] = $file_path;
             $this->set(array('options' => $exportOptions))->save();
         }
     } else {
         if (!$is_secure_import) {
             $file_path = str_replace($wp_uploads['baseurl'], $wp_uploads['basedir'], wp_get_attachment_url($this->attch_id));
         } else {
             $file_path = wp_all_export_get_absolute_path($this->options['filepath']);
         }
     }
     $foundPosts = !XmlExportEngine::$is_user_export ? $exportQuery->found_posts : $exportQuery->get_total();
     $postCount = !XmlExportEngine::$is_user_export ? $exportQuery->post_count : count($exportQuery->get_results());
     // if posts still exists then export them
     if ($postCount) {
         switch ($this->options['export_to']) {
             case 'xml':
                 if (!XmlExportEngine::$is_user_export) {
                     $exported_to_file = pmxe_export_xml($exportQuery, $this->options, false, $cron, $file_path);
                 } else {
                     $exported_to_file = pmxe_export_users_xml($exportQuery, $this->options, false, $cron, $file_path);
                 }
                 break;
             case 'csv':
                 if (!XmlExportEngine::$is_user_export) {
                     $exported_to_file = pmxe_export_csv($exportQuery, $this->options, false, $cron, $file_path, $this->exported);
                 } else {
                     $exported_to_file = pmxe_export_users_csv($exportQuery, $this->options, false, $cron, $file_path, $this->exported);
                 }
                 break;
             default:
                 # code...
                 break;
         }
         wp_reset_postdata();
         $this->set(array('exported' => $this->exported + $postCount, 'last_activity' => date('Y-m-d H:i:s'), 'processing' => 0))->save();
     } else {
         wp_reset_postdata();
         if (file_exists($file_path)) {
             if ($this->options['export_to'] == 'xml') {
                 file_put_contents($file_path, '</data>', FILE_APPEND);
             }
             if (wp_all_export_is_compatible() and ($this->options['is_generate_templates'] or $this->options['is_generate_import'])) {
                 $custom_type = empty($exportOptions['cpt']) ? 'post' : $exportOptions['cpt'][0];
                 $templateOptions = array('type' => (!empty($exportOptions['cpt']) and $exportOptions['cpt'][0] == 'page') ? 'page' : 'post', 'wizard_type' => 'new', 'deligate' => 'wpallexport', 'custom_type' => XmlExportEngine::$is_user_export ? 'import_users' : $custom_type, 'status' => 'xpath', 'is_multiple_page_parent' => 'no', 'unique_key' => '', 'acf' => array(), 'fields' => array(), 'is_multiple_field_value' => array(), 'multiple_value' => array(), 'fields_delimiter' => array(), 'update_all_data' => 'no', 'is_update_status' => 0, 'is_update_title' => 0, 'is_update_author' => 0, 'is_update_slug' => 0, 'is_update_content' => 0, 'is_update_excerpt' => 0, 'is_update_dates' => 0, 'is_update_menu_order' => 0, 'is_update_parent' => 0, 'is_update_attachments' => 0, 'is_update_acf' => 0, 'update_acf_logic' => 'only', 'acf_list' => '', 'is_update_product_type' => 1, 'is_update_attributes' => 0, 'update_attributes_logic' => 'only', 'attributes_list' => '', 'is_update_images' => 0, 'is_update_custom_fields' => 0, 'update_custom_fields_logic' => 'only', 'custom_fields_list' => '', 'is_update_categories' => 0, 'update_categories_logic' => 'only', 'taxonomies_list' => '', 'export_id' => $this->id);
                 if (in_array('product', $this->options['cpt'])) {
                     $templateOptions['_virtual'] = 1;
                     $templateOptions['_downloadable'] = 1;
                 }
                 if (XmlExportEngine::$is_user_export) {
                     $templateOptions['is_update_first_name'] = 0;
                     $templateOptions['is_update_last_name'] = 0;
                     $templateOptions['is_update_role'] = 0;
                     $templateOptions['is_update_nickname'] = 0;
                     $templateOptions['is_update_description'] = 0;
                     $templateOptions['is_update_login'] = 0;
                     $templateOptions['is_update_password'] = 0;
                     $templateOptions['is_update_nicename'] = 0;
                     $templateOptions['is_update_email'] = 0;
                     $templateOptions['is_update_registered'] = 0;
                     $templateOptions['is_update_display_name'] = 0;
                     $templateOptions['is_update_url'] = 0;
                 }
                 if ('xml' == $this->options['export_to']) {
                     wp_all_export_prepare_template_xml($this->options, $templateOptions);
                 } else {
                     wp_all_export_prepare_template_csv($this->options, $templateOptions);
                 }
                 $options = $templateOptions + PMXI_Plugin::get_default_import_options();
                 if ($this->options['is_generate_templates']) {
                     $template = new PMXI_Template_Record();
                     $tpl_data = array('name' => $this->options['template_name'], 'is_keep_linebreaks' => 0, 'is_leave_html' => 0, 'fix_characters' => 0, 'options' => $options);
                     if (!empty($this->options['template_name'])) {
                         // save template in database
                         $template->getByName($this->options['template_name'])->set($tpl_data)->save();
                     }
                 }
                 if ($this->options['is_generate_import']) {
                     $import = new PMXI_Import_Record();
                     $import->getById($this->options['import_id']);
                     if (!$import->isEmpty() and $import->parent_import_id == 99999) {
                         $xmlPath = $file_path;
                         $root_element = '';
                         if ('csv' == $this->options['export_to']) {
                             $options['delimiter'] = $this->options['delimiter'];
                             include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php';
                             $path_parts = pathinfo($xmlPath);
                             $path_parts_arr = explode(DIRECTORY_SEPARATOR, $path_parts['dirname']);
                             $target = $is_secure_import ? $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::UPLOADS_DIRECTORY . DIRECTORY_SEPARATOR . array_pop($path_parts_arr) : $wp_uploads['path'];
                             $csv = new PMXI_CsvParser(array('filename' => $xmlPath, 'targetDir' => $target));
                             $xmlPath = $csv->xml_path;
                             $root_element = 'node';
                         } else {
                             $root_element = 'post';
                         }
                         $import->set(array('xpath' => '/' . $root_element, 'type' => 'upload', 'options' => $options, 'root_element' => $root_element, 'path' => $xmlPath, 'name' => basename($xmlPath), 'imported' => 0, 'created' => 0, 'updated' => 0, 'skipped' => 0, 'deleted' => 0, 'count' => $exportQuery->found_posts))->save();
                         $history_file = new PMXI_File_Record();
                         $history_file->set(array('name' => $import->name, 'import_id' => $import->id, 'path' => $xmlPath, 'registered_on' => date('Y-m-d H:i:s')))->save();
                         $exportOptions = $this->options;
                         $exportOptions['import_id'] = $import->id;
                         $this->set(array('options' => $exportOptions))->save();
                     }
                 }
             }
             // update export file for remove access
             # 1 meg at a time, you can adjust this.
             $to_dirname = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::CRON_DIRECTORY . DIRECTORY_SEPARATOR . md5(PMXE_Plugin::getInstance()->getOption('cron_job_key') . $this->id);
             if (!@is_dir($to_dirname)) {
                 wp_mkdir_p($to_dirname);
             }
             if (!@file_exists($to_dirname . DIRECTORY_SEPARATOR . 'index.php')) {
                 @touch($to_dirname . DIRECTORY_SEPARATOR . 'index.php');
             }
             $to = $to_dirname . DIRECTORY_SEPARATOR . (!empty($this->friendly_name) ? sanitize_file_name($this->friendly_name) : 'feed') . '.' . $this->options['export_to'];
             $buffer_size = 1048576;
             $fin = @fopen($file_path, "rb");
             $fout = @fopen($to, "w");
             while (!@feof($fin)) {
                 @fwrite($fout, @fread($fin, $buffer_size));
             }
             @fclose($fin);
             @fclose($fout);
             if ($this->options['is_scheduled'] and "" != $this->options['scheduled_email']) {
                 add_filter('wp_mail_content_type', array($this, 'set_html_content_type'));
                 $headers = 'From: ' . get_bloginfo('name') . ' <' . get_bloginfo('admin_email') . '>' . "\r\n";
                 $message = '<p>Export ' . $this->options['friendly_name'] . ' has been completed. You can find exported file in attachments.</p>';
                 wp_mail($this->options['scheduled_email'], __("WP All Export", "pmxe_plugin"), $message, $headers, array($file_path));
                 remove_filter('wp_mail_content_type', array($this, 'set_html_content_type'));
             }
         }
         $this->set(array('processing' => 0, 'triggered' => 0, 'canceled' => 0, 'registered_on' => date('Y-m-d H:i:s')))->update();
     }
     return $this;
 }
Beispiel #5
0
/**
*	AJAX action export processing
*/
function pmxe_wp_ajax_export()
{
    if (!check_ajax_referer('wp_all_export_secure', 'security', false)) {
        exit(__('Security check', 'wp_all_export_plugin'));
    }
    if (!current_user_can('manage_options')) {
        exit(__('Security check', 'wp_all_export_plugin'));
    }
    $wp_uploads = wp_upload_dir();
    $export = new PMXE_Export_Record();
    $export->getById(PMXE_Plugin::$session->update_previous);
    $exportOptions = (PMXE_Plugin::$session->has_session() ? PMXE_Plugin::$session->get_clear_session_data() : array()) + PMXE_Plugin::get_default_import_options();
    wp_reset_postdata();
    XmlExportEngine::$exportOptions = $exportOptions;
    XmlExportEngine::$is_user_export = $exportOptions['is_user_export'];
    $posts_per_page = $exportOptions['records_per_iteration'];
    if ('advanced' == $exportOptions['export_type']) {
        if (XmlExportEngine::$is_user_export) {
            $exportQuery = eval('return new WP_User_Query(array(' . $exportOptions['wp_query'] . ', \'orderby\' => \'ID\', \'order\' => \'ASC\', \'offset\' => ' . $export->exported . ', \'number\' => ' . $posts_per_page . ' ));');
        } else {
            $exportQuery = eval('return new WP_Query(array(' . $exportOptions['wp_query'] . ', \'orderby\' => \'ID\', \'order\' => \'ASC\', \'offset\' => ' . $export->exported . ', \'posts_per_page\' => ' . $posts_per_page . ' ));');
        }
    } else {
        XmlExportEngine::$post_types = $exportOptions['cpt'];
        if (!in_array('users', $exportOptions['cpt'])) {
            add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
            add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
            $exportQuery = new WP_Query(array('post_type' => $exportOptions['cpt'], 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'offset' => $export->exported, 'posts_per_page' => $posts_per_page));
            remove_filter('posts_where', 'wp_all_export_posts_where');
            remove_filter('posts_join', 'wp_all_export_posts_join');
        } else {
            add_action('pre_user_query', 'wp_all_export_pre_user_query', 10, 1);
            $exportQuery = new WP_User_Query(array('orderby' => 'ID', 'order' => 'ASC', 'number' => $posts_per_page, 'offset' => $export->exported));
            remove_action('pre_user_query', 'wp_all_export_pre_user_query');
        }
    }
    XmlExportEngine::$exportQuery = $exportQuery;
    $foundPosts = !XmlExportEngine::$is_user_export ? $exportQuery->found_posts : $exportQuery->get_total();
    $postCount = !XmlExportEngine::$is_user_export ? $exportQuery->post_count : count($exportQuery->get_results());
    if (!$export->exported) {
        if (!empty($export->attch_id)) {
            wp_delete_attachment($export->attch_id, true);
        }
        $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
        if ($is_secure_import and !empty($exportOptions['filepath'])) {
            wp_all_export_remove_source(wp_all_export_get_absolute_path($exportOptions['filepath']));
            $exportOptions['filepath'] = '';
        }
        PMXE_Plugin::$session->set('count', $foundPosts);
        PMXE_Plugin::$session->save_data();
    }
    // if posts still exists then export them
    if ($postCount) {
        switch ($exportOptions['export_to']) {
            case 'xml':
                if (!XmlExportEngine::$is_user_export) {
                    pmxe_export_xml($exportQuery, $exportOptions);
                } else {
                    pmxe_export_users_xml($exportQuery, $exportOptions);
                }
                break;
            case 'csv':
                if (!XmlExportEngine::$is_user_export) {
                    pmxe_export_csv($exportQuery, $exportOptions);
                } else {
                    pmxe_export_users_csv($exportQuery, $exportOptions);
                }
                break;
            default:
                # code...
                break;
        }
        wp_reset_postdata();
    }
    if ($postCount) {
        $export->set(array('exported' => $export->exported + $postCount))->save();
    }
    if ($posts_per_page != -1 and $postCount) {
        wp_send_json(array('exported' => $export->exported, 'percentage' => ceil($export->exported / $foundPosts * 100), 'done' => false, 'records_per_request' => $exportOptions['records_per_iteration']));
    } else {
        wp_reset_postdata();
        if (file_exists(PMXE_Plugin::$session->file)) {
            if ($exportOptions['export_to'] == 'xml') {
                file_put_contents(PMXE_Plugin::$session->file, '</data>', FILE_APPEND);
            }
            $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
            if (!$is_secure_import) {
                $wp_filetype = wp_check_filetype(basename(PMXE_Plugin::$session->file), null);
                $attachment_data = array('guid' => $wp_uploads['baseurl'] . '/' . _wp_relative_upload_path(PMXE_Plugin::$session->file), 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename(PMXE_Plugin::$session->file)), 'post_content' => '', 'post_status' => 'inherit');
                $attach_id = wp_insert_attachment($attachment_data, PMXE_Plugin::$session->file);
                if (!$export->isEmpty()) {
                    $export->set(array('attch_id' => $attach_id))->save();
                }
            } else {
                $exportOptions['filepath'] = wp_all_export_get_relative_path(PMXE_Plugin::$session->file);
                if (!$export->isEmpty()) {
                    $export->set(array('options' => $exportOptions))->save();
                }
            }
            if (wp_all_export_is_compatible() and ($exportOptions['is_generate_templates'] or $exportOptions['is_generate_import'])) {
                $custom_type = empty($exportOptions['cpt']) ? 'post' : $exportOptions['cpt'][0];
                $templateOptions = array('type' => (!empty($exportOptions['cpt']) and $exportOptions['cpt'][0] == 'page') ? 'page' : 'post', 'wizard_type' => 'new', 'deligate' => 'wpallexport', 'custom_type' => XmlExportEngine::$is_user_export ? 'import_users' : $custom_type, 'status' => 'xpath', 'is_multiple_page_parent' => 'no', 'unique_key' => '', 'acf' => array(), 'fields' => array(), 'is_multiple_field_value' => array(), 'multiple_value' => array(), 'fields_delimiter' => array(), 'update_all_data' => 'no', 'is_update_status' => 0, 'is_update_title' => 0, 'is_update_author' => 0, 'is_update_slug' => 0, 'is_update_content' => 0, 'is_update_excerpt' => 0, 'is_update_dates' => 0, 'is_update_menu_order' => 0, 'is_update_parent' => 0, 'is_update_attachments' => 0, 'is_update_acf' => 0, 'update_acf_logic' => 'only', 'acf_list' => '', 'is_update_product_type' => 0, 'is_update_attributes' => 0, 'update_attributes_logic' => 'only', 'attributes_list' => '', 'is_update_images' => 0, 'is_update_custom_fields' => 0, 'update_custom_fields_logic' => 'only', 'custom_fields_list' => '', 'is_update_categories' => 0, 'update_categories_logic' => 'only', 'taxonomies_list' => '', 'export_id' => $export->id);
                if (in_array('product', $exportOptions['cpt'])) {
                    $templateOptions['_virtual'] = 1;
                    $templateOptions['_downloadable'] = 1;
                }
                if (XmlExportEngine::$is_user_export) {
                    $templateOptions['is_update_first_name'] = 0;
                    $templateOptions['is_update_last_name'] = 0;
                    $templateOptions['is_update_role'] = 0;
                    $templateOptions['is_update_nickname'] = 0;
                    $templateOptions['is_update_description'] = 0;
                    $templateOptions['is_update_login'] = 0;
                    $templateOptions['is_update_password'] = 0;
                    $templateOptions['is_update_nicename'] = 0;
                    $templateOptions['is_update_email'] = 0;
                    $templateOptions['is_update_registered'] = 0;
                    $templateOptions['is_update_display_name'] = 0;
                    $templateOptions['is_update_url'] = 0;
                }
                if ('xml' == $exportOptions['export_to']) {
                    wp_all_export_prepare_template_xml($exportOptions, $templateOptions);
                } else {
                    wp_all_export_prepare_template_csv($exportOptions, $templateOptions);
                }
                $options = $templateOptions + PMXI_Plugin::get_default_import_options();
                if ($exportOptions['is_generate_templates']) {
                    $template = new PMXI_Template_Record();
                    $tpl_options = $options;
                    if ('csv' == $exportOptions['export_to']) {
                        $tpl_options['delimiter'] = $exportOptions['delimiter'];
                    }
                    $tpl_options['update_all_data'] = 'yes';
                    $tpl_options['is_update_status'] = 1;
                    $tpl_options['is_update_title'] = 1;
                    $tpl_options['is_update_author'] = 1;
                    $tpl_options['is_update_slug'] = 1;
                    $tpl_options['is_update_content'] = 1;
                    $tpl_options['is_update_excerpt'] = 1;
                    $tpl_options['is_update_dates'] = 1;
                    $tpl_options['is_update_menu_order'] = 1;
                    $tpl_options['is_update_parent'] = 1;
                    $tpl_options['is_update_attachments'] = 1;
                    $tpl_options['is_update_acf'] = 1;
                    $tpl_options['update_acf_logic'] = 'full_update';
                    $tpl_options['acf_list'] = '';
                    $tpl_options['is_update_product_type'] = 1;
                    $tpl_options['is_update_attributes'] = 1;
                    $tpl_options['update_attributes_logic'] = 'full_update';
                    $tpl_options['attributes_list'] = '';
                    $tpl_options['is_update_images'] = 1;
                    $tpl_options['is_update_custom_fields'] = 1;
                    $tpl_options['update_custom_fields_logic'] = 'full_update';
                    $tpl_options['custom_fields_list'] = '';
                    $tpl_options['is_update_categories'] = 1;
                    $tpl_options['update_categories_logic'] = 'full_update';
                    $tpl_options['taxonomies_list'] = '';
                    $tpl_data = array('name' => $exportOptions['template_name'], 'is_keep_linebreaks' => 0, 'is_leave_html' => 0, 'fix_characters' => 0, 'options' => $tpl_options);
                    if (!empty($exportOptions['template_name'])) {
                        // save template in database
                        $template->getByName($exportOptions['template_name'])->set($tpl_data)->save();
                    }
                }
                // associate exported posts with new import
                if ($exportOptions['is_generate_import']) {
                    $import = new PMXI_Import_Record();
                    $import->getById($exportOptions['import_id']);
                    if (!$import->isEmpty() and $import->parent_import_id == 99999) {
                        $xmlPath = PMXE_Plugin::$session->file;
                        $root_element = '';
                        $historyPath = PMXE_Plugin::$session->file;
                        if ('csv' == $exportOptions['export_to']) {
                            $options['delimiter'] = $exportOptions['delimiter'];
                            include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php';
                            $path_info = pathinfo($xmlPath);
                            $path_parts = explode(DIRECTORY_SEPARATOR, $path_info['dirname']);
                            $security_folder = array_pop($path_parts);
                            $target = $is_secure_import ? $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::UPLOADS_DIRECTORY . DIRECTORY_SEPARATOR . $security_folder : $wp_uploads['path'];
                            $csv = new PMXI_CsvParser(array('filename' => $xmlPath, 'targetDir' => $target));
                            $historyPath = $csv->xml_path;
                            $root_element = 'node';
                        } else {
                            $root_element = 'post';
                        }
                        $import->set(array('xpath' => '/' . $root_element, 'type' => 'upload', 'options' => $options, 'root_element' => $root_element, 'path' => $xmlPath, 'name' => basename($xmlPath), 'imported' => 0, 'created' => 0, 'updated' => 0, 'skipped' => 0, 'deleted' => 0, 'iteration' => 1, 'count' => PMXE_Plugin::$session->count))->save();
                        $history_file = new PMXI_File_Record();
                        $history_file->set(array('name' => $import->name, 'import_id' => $import->id, 'path' => $historyPath, 'registered_on' => date('Y-m-d H:i:s')))->save();
                        $exportOptions['import_id'] = $import->id;
                        $export->set(array('options' => $exportOptions))->save();
                    }
                }
            }
        }
        $export->set(array('executing' => 0, 'canceled' => 0))->save();
        wp_send_json(array('exported' => $export->exported, 'percentage' => 100, 'done' => true, 'records_per_request' => $exportOptions['records_per_iteration'], 'file' => PMXE_Plugin::$session->file));
    }
}
Beispiel #6
0
										<a href="<?php 
                        echo add_query_arg(array('page' => 'pmxi-admin-import', 'id' => $item['options']['import_id'], 'deligate' => 'wpallexport'), remove_query_arg('page', $this->baseUrl));
                        ?>
"><?php 
                        _e("Import with WP All Import", "wp_all_export_plugin");
                        ?>
</a>
									<?php 
                    }
                    ?>
			
									<?php 
                    if (wp_all_export_is_compatible() and (empty($item['options']['cpt']) or !in_array('shop_order', $item['options']['cpt']))) {
                        $template = new PMXI_Template_Record();
                        if (!empty($item['options']['template_name'])) {
                            $template->getByName($item['options']['template_name']);
                            if (!$template->isEmpty()) {
                                ?>
													<br/>
													<a href="<?php 
                                echo add_query_arg(array('id' => $item['id'], 'action' => 'templates'), $this->baseUrl);
                                ?>
"><?php 
                                _e('Download Import Templates', 'wp_all_export_plugin');
                                ?>
</a>
													<?php 
                            }
                        }
                    }
                    ?>