本文整理汇总了PHP中PMXI_Plugin::get_default_import_options方法的典型用法代码示例。如果您正苦于以下问题:PHP PMXI_Plugin::get_default_import_options方法的具体用法?PHP PMXI_Plugin::get_default_import_options怎么用?PHP PMXI_Plugin::get_default_import_options使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PMXI_Plugin
的用法示例。
在下文中一共展示了PMXI_Plugin::get_default_import_options方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* Perform import operation
* @param string $xml XML string to import
* @param callback[optional] $logger Method where progress messages are submmitted
* @return PMXI_Import_Record
* @chainable
*/
public function process($xml, $logger = NULL, $chunk = false, $is_cron = false, $xpath_prefix = '', $loop = 0)
{
add_filter('user_has_cap', array($this, '_filter_has_cap_unfiltered_html'));
kses_init();
// do not perform special filtering for imported content
kses_remove_filters();
$cxpath = $xpath_prefix . $this->xpath;
$this->options += PMXI_Plugin::get_default_import_options();
// make sure all options are defined
$avoid_pingbacks = PMXI_Plugin::getInstance()->getOption('pingbacks');
$cron_sleep = (int) PMXI_Plugin::getInstance()->getOption('cron_sleep');
if ($avoid_pingbacks and !defined('WP_IMPORTING')) {
define('WP_IMPORTING', true);
}
$postRecord = new PMXI_Post_Record();
$tmp_files = array();
// compose records to import
$records = array();
$is_import_complete = false;
try {
$chunk == 1 and $logger and call_user_func($logger, __('Composing titles...', 'wp_all_import_plugin'));
if (!empty($this->options['title'])) {
$titles = XmlImportParser::factory($xml, $cxpath, $this->options['title'], $file)->parse($records);
$tmp_files[] = $file;
} else {
$loop and $titles = array_fill(0, $loop, '');
}
$chunk == 1 and $logger and call_user_func($logger, __('Composing excerpts...', 'wp_all_import_plugin'));
$post_excerpt = array();
if (!empty($this->options['post_excerpt'])) {
$post_excerpt = XmlImportParser::factory($xml, $cxpath, $this->options['post_excerpt'], $file)->parse($records);
$tmp_files[] = $file;
} else {
count($titles) and $post_excerpt = array_fill(0, count($titles), '');
}
if ("xpath" == $this->options['status']) {
$chunk == 1 and $logger and call_user_func($logger, __('Composing statuses...', 'wp_all_import_plugin'));
$post_status = array();
if (!empty($this->options['status_xpath'])) {
$post_status = XmlImportParser::factory($xml, $cxpath, $this->options['status_xpath'], $file)->parse($records);
$tmp_files[] = $file;
} else {
count($titles) and $post_status = array_fill(0, count($titles), '');
}
}
if ("xpath" == $this->options['comment_status']) {
$chunk == 1 and $logger and call_user_func($logger, __('Composing comment statuses...', 'wp_all_import_plugin'));
$comment_status = array();
if (!empty($this->options['comment_status_xpath'])) {
$comment_status = XmlImportParser::factory($xml, $cxpath, $this->options['comment_status_xpath'], $file)->parse($records);
$tmp_files[] = $file;
} else {
count($titles) and $comment_status = array_fill(0, count($titles), 'open');
}
}
if ("xpath" == $this->options['ping_status']) {
$chunk == 1 and $logger and call_user_func($logger, __('Composing ping statuses...', 'wp_all_import_plugin'));
$ping_status = array();
if (!empty($this->options['ping_status_xpath'])) {
$ping_status = XmlImportParser::factory($xml, $cxpath, $this->options['ping_status_xpath'], $file)->parse($records);
$tmp_files[] = $file;
} else {
count($titles) and $ping_status = array_fill(0, count($titles), 'open');
}
}
if ("xpath" == $this->options['post_format']) {
$chunk == 1 and $logger and call_user_func($logger, __('Composing post formats...', 'wp_all_import_plugin'));
$post_format = array();
if (!empty($this->options['post_format_xpath'])) {
$post_format = XmlImportParser::factory($xml, $cxpath, $this->options['post_format_xpath'], $file)->parse($records);
$tmp_files[] = $file;
} else {
count($titles) and $post_format = array_fill(0, count($titles), 'open');
}
}
if ("no" == $this->options['is_multiple_page_template']) {
$chunk == 1 and $logger and call_user_func($logger, __('Composing page templates...', 'wp_all_import_plugin'));
$page_template = array();
if (!empty($this->options['single_page_template'])) {
$page_template = XmlImportParser::factory($xml, $cxpath, $this->options['single_page_template'], $file)->parse($records);
$tmp_files[] = $file;
} else {
count($titles) and $page_template = array_fill(0, count($titles), 'default');
}
}
if ($this->options['is_override_post_type'] and !empty($this->options['post_type_xpath'])) {
$chunk == 1 and $logger and call_user_func($logger, __('Composing post types...', 'wp_all_import_plugin'));
$post_type = array();
$post_type = XmlImportParser::factory($xml, $cxpath, $this->options['post_type_xpath'], $file)->parse($records);
$tmp_files[] = $file;
} else {
if ('post' == $this->options['type'] and '' != $this->options['custom_type']) {
$pType = $this->options['custom_type'];
//.........这里部分代码省略.........
示例2: confirm
/**
* Step #5: Confirm & Run Import
*/
public function confirm()
{
$default = PMXI_Plugin::get_default_import_options();
$this->data['source'] = PMXI_Plugin::$session->source;
$this->data['locfilePath'] = PMXI_Plugin::$session->filePath;
$this->data['count'] = PMXI_Plugin::$session->count;
$this->data['xpath'] = PMXI_Plugin::$session->xpath;
$this->data['isWizard'] = true;
$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"));
}
}
if ($this->isWizard and PMXI_Plugin::$session->options['custom_type'] != 'import_users') {
if (empty(PMXI_Plugin::$session->options['title'])) {
$this->warnings->add('form-validation', __('<strong>Warning:</strong> your title is blank.'));
}
if (empty(PMXI_Plugin::$session->options['content'])) {
$this->warnings->add('form-validation', __('<strong>Warning:</strong> your content is blank.'));
}
}
$this->data['post'] =& $DefaultOptions;
if ($this->input->post('is_confirmed')) {
check_admin_referer('confirm', '_wpnonce_confirm');
$continue = $this->input->post('is_continue', 'no');
if ($continue == 'yes') {
PMXI_Plugin::$session->set('action', 'continue');
PMXI_Plugin::$session->save_data();
}
if (!$this->errors->get_error_codes()) {
// no validation errors found
wp_redirect(add_query_arg('action', 'process', $this->baseUrl));
die;
}
}
$this->render();
}
示例3: update
/**
* Re-run import
*/
public function update()
{
$id = $this->input->get('id');
PMXI_Plugin::$session->clean_session($id);
$action_type = false;
$this->data['import'] = $item = new PMXI_Import_Record();
if (!$id or $item->getById($id)->isEmpty()) {
wp_redirect($this->baseUrl);
die;
}
$this->data['isWizard'] = false;
$default = PMXI_Plugin::get_default_import_options();
$DefaultOptions = $item->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"));
}
}
$this->data['post'] =& $DefaultOptions;
$this->data['source'] = array('path' => $item->path, 'root_element' => $item->root_element);
$this->data['xpath'] = $item->xpath;
$this->data['count'] = $item->count;
$history = new PMXI_File_List();
$history->setColumns('id', 'name', 'registered_on', 'path')->getBy(array('import_id' => $item->id), 'id DESC');
if ($history->count()) {
foreach ($history as $file) {
if (@file_exists($file['path'])) {
$this->data['locfilePath'] = $file['path'];
break;
}
}
}
$chunks = 0;
if ($this->input->post('is_confirmed') and check_admin_referer('confirm', '_wpnonce_confirm')) {
$continue = $this->input->post('is_continue', 'no');
// mark action type ad continue
if ($continue == 'yes') {
$action_type = 'continue';
}
$filePath = '';
// upload new file in case when import is not continue
if (empty(PMXI_Plugin::$session->chunk_number)) {
if ($item->type == 'upload') {
// retrieve already uploaded file
$uploader = new PMXI_Upload(trim($item->path), $this->errors, rtrim(str_replace(basename($item->path), '', $item->path), '/'));
$upload_result = $uploader->upload();
if ($upload_result instanceof WP_Error) {
$this->errors = $upload_result;
} else {
$filePath = $upload_result['filePath'];
}
}
if (empty($item->options['encoding'])) {
$currentOptions = $item->options;
$currentOptions['encoding'] = 'UTF-8';
$item->set(array('options' => $currentOptions))->update();
}
@set_time_limit(0);
$local_paths = !empty($local_paths) ? $local_paths : array($filePath);
foreach ($local_paths as $key => $path) {
if (!empty($action_type) and $action_type == 'continue') {
$chunks = $item->count;
} else {
$file = new PMXI_Chunk($path, array('element' => $item->root_element, 'encoding' => $item->options['encoding']));
while ($xml = $file->read()) {
if (!empty($xml)) {
PMXI_Import_Record::preprocessXml($xml);
$xml = "<?xml version=\"1.0\" encoding=\"" . $item->options['encoding'] . "\"?>" . "\n" . $xml;
$dom = new DOMDocument('1.0', !empty($item->options['encoding']) ? $item->options['encoding'] : 'UTF-8');
$old = libxml_use_internal_errors(true);
$dom->loadXML($xml);
// FIX: libxml xpath doesn't handle default namespace properly, so remove it upon XML load
libxml_use_internal_errors($old);
$xpath = new DOMXPath($dom);
if ($elements = @$xpath->query($item->xpath) and !empty($elements) and !empty($elements->length)) {
$chunks += $elements->length;
}
unset($dom, $xpath, $elements);
}
}
unset($file);
}
!$key and $filePath = $path;
}
if (empty($chunks)) {
$this->errors->add('form-validation', __('No matching elements found for Root element and XPath expression specified', 'wp_all_import_plugin'));
}
}
if ($chunks) {
// xml is valid
if (!PMXI_Plugin::is_ajax() and empty(PMXI_Plugin::$session->chunk_number)) {
// compose data to look like result of wizard steps
$sesson_data = array('filePath' => $filePath, 'source' => array('name' => $item->name, 'type' => $item->type, 'path' => $item->path, 'root_element' => $item->root_element), 'feed_type' => $item->feed_type, 'update_previous' => $item->id, 'parent_import_id' => $item->parent_import_id, 'xpath' => $item->xpath, 'options' => $item->options, 'encoding' => !empty($item->options['encoding']) ? $item->options['encoding'] : 'UTF-8', 'is_csv' => !empty($item->options['delimiter']) ? $item->options['delimiter'] : PMXI_Plugin::$is_csv, 'csv_path' => PMXI_Plugin::$csv_path, 'chunk_number' => 1, 'log' => '', 'warnings' => 0, 'errors' => 0, 'start_time' => 0, 'pointer' => 1, 'count' => isset($chunks) ? $chunks : 0, 'local_paths' => !empty($local_paths) ? $local_paths : array(), 'action' => (!empty($action_type) and $action_type == 'continue') ? 'continue' : 'update', 'nonce' => wp_create_nonce('import'));
foreach ($sesson_data as $key => $value) {
PMXI_Plugin::$session->set($key, $value);
}
PMXI_Plugin::$session->save_data();
//.........这里部分代码省略.........
示例4: options
/**
* 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
//.........这里部分代码省略.........
示例5: process
/**
* Perform import operation
* @param string $xml XML string to import
* @param callback[optional] $logger Method where progress messages are submmitted
* @return PMXI_Import_Record
* @chainable
*/
public function process($xml, $logger = NULL, $chunk = false, $is_cron = false, $xpath_prefix = '')
{
add_filter('user_has_cap', array($this, '_filter_has_cap_unfiltered_html'));
kses_init();
// do not perform special filtering for imported content
$cxpath = $xpath_prefix . $this->xpath;
$this->options += PMXI_Plugin::get_default_import_options();
// make sure all options are defined
$avoid_pingbacks = PMXI_Plugin::getInstance()->getOption('pingbacks');
if ($avoid_pingbacks and !defined('WP_IMPORTING')) {
define('WP_IMPORTING', true);
}
$postRecord = new PMXI_Post_Record();
$tmp_files = array();
// compose records to import
$records = array();
$is_import_complete = false;
try {
$chunk == 1 and $logger and call_user_func($logger, __('Composing titles...', 'pmxi_plugin'));
$titles = XmlImportParser::factory($xml, $cxpath, $this->template['title'], $file)->parse($records);
$tmp_files[] = $file;
$chunk == 1 and $logger and call_user_func($logger, __('Composing excerpts...', 'pmxi_plugin'));
$post_excerpt = array();
if (!empty($this->options['post_excerpt'])) {
$post_excerpt = XmlImportParser::factory($xml, $cxpath, $this->options['post_excerpt'], $file)->parse($records);
$tmp_files[] = $file;
} else {
count($titles) and $post_excerpt = array_fill(0, count($titles), '');
}
if ("xpath" == $this->options['status']) {
$chunk == 1 and $logger and call_user_func($logger, __('Composing statuses...', 'pmxi_plugin'));
$post_status = array();
if (!empty($this->options['status_xpath'])) {
$post_status = XmlImportParser::factory($xml, $cxpath, $this->options['status_xpath'], $file)->parse($records);
$tmp_files[] = $file;
} else {
count($titles) and $post_status = array_fill(0, count($titles), '');
}
}
$chunk == 1 and $logger and call_user_func($logger, __('Composing authors...', 'pmxi_plugin'));
$post_author = array();
$current_user = wp_get_current_user();
if (!empty($this->options['author'])) {
$post_author = XmlImportParser::factory($xml, $cxpath, $this->options['author'], $file)->parse($records);
$tmp_files[] = $file;
foreach ($post_author as $key => $author) {
$user = get_user_by('login', $author) or $user = get_user_by('slug', $author) or $user = get_user_by('email', $author) or ctype_digit($author) and $user = get_user_by('id', $author);
$post_author[$key] = !empty($user) ? $user->ID : $current_user->ID;
}
} else {
count($titles) and $post_author = array_fill(0, count($titles), $current_user->ID);
}
$chunk == 1 and $logger and call_user_func($logger, __('Composing slugs...', 'pmxi_plugin'));
$post_slug = array();
if (!empty($this->options['post_slug'])) {
$post_slug = XmlImportParser::factory($xml, $cxpath, $this->options['post_slug'], $file)->parse($records);
$tmp_files[] = $file;
} else {
count($titles) and $post_slug = array_fill(0, count($titles), '');
}
$chunk == 1 and $logger and call_user_func($logger, __('Composing contents...', 'pmxi_plugin'));
$contents = XmlImportParser::factory((!empty($this->template['is_keep_linebreaks']) and intval($this->template['is_keep_linebreaks'])) ? $xml : preg_replace('%\\r\\n?|\\n%', ' ', $xml), $cxpath, $this->template['content'], $file)->parse($records);
$tmp_files[] = $file;
$chunk == 1 and $logger and call_user_func($logger, __('Composing dates...', 'pmxi_plugin'));
if ('specific' == $this->options['date_type']) {
$dates = XmlImportParser::factory($xml, $cxpath, $this->options['date'], $file)->parse($records);
$tmp_files[] = $file;
$warned = array();
// used to prevent the same notice displaying several times
foreach ($dates as $i => $d) {
if ($d == 'now') {
$d = current_time('mysql');
}
// Replace 'now' with the WordPress local time to account for timezone offsets (WordPress references its local time during publishing rather than the server’s time so it should use that)
$time = strtotime($d);
if (FALSE === $time) {
in_array($d, $warned) or $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: unrecognized date format `%s`, assigning current date', 'pmxi_plugin'), $warned[] = $d));
$logger and PMXI_Plugin::$session['pmxi_import']['warnings'] = ++PMXI_Plugin::$session->data['pmxi_import']['warnings'];
$time = time();
}
$dates[$i] = date('Y-m-d H:i:s', $time);
}
} else {
$dates_start = XmlImportParser::factory($xml, $cxpath, $this->options['date_start'], $file)->parse($records);
$tmp_files[] = $file;
$dates_end = XmlImportParser::factory($xml, $cxpath, $this->options['date_end'], $file)->parse($records);
$tmp_files[] = $file;
$warned = array();
// used to prevent the same notice displaying several times
foreach ($dates_start as $i => $d) {
$time_start = strtotime($dates_start[$i]);
if (FALSE === $time_start) {
in_array($dates_start[$i], $warned) or $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: unrecognized date format `%s`, assigning current date', 'pmxi_plugin'), $warned[] = $dates_start[$i]));
//.........这里部分代码省略.........
示例6: link_template_to_import
public static function link_template_to_import(&$export, $file_path, $foundPosts)
{
$exportOptions = $export->options;
// associate exported posts with new import
if (wp_all_export_is_compatible()) {
$options = self::$templateOptions + PMXI_Plugin::get_default_import_options();
$import = new PMXI_Import_Record();
$import->getById($exportOptions['import_id']);
if (!$import->isEmpty() and $import->parent_import_id == 99999) {
$xmlPath = $file_path;
$root_element = '';
$historyPath = $file_path;
if ('csv' == $exportOptions['export_to']) {
$is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
$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);
$wp_uploads = wp_upload_dir();
$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));
if (!in_array($xmlPath, $exportOptions['attachment_list'])) {
$exportOptions['attachment_list'][] = $csv->xml_path;
}
$historyPath = $csv->xml_path;
$root_element = 'node';
} else {
$root_element = apply_filters('wp_all_export_record_xml_tag', $exportOptions['record_xml_tag'], $export->id);
}
$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' => $foundPosts))->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();
}
}
}
示例7: execute
//.........这里部分代码省略.........
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;
}
示例8: pmxe_wp_ajax_wpallexport
/**
* AJAX action export processing
*/
function pmxe_wp_ajax_wpallexport()
{
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'));
}
$input = new PMXE_Input();
$export_id = $input->get('id', 0);
if (empty($export_id)) {
$export_id = !empty(PMXE_Plugin::$session->update_previous) ? PMXE_Plugin::$session->update_previous : 0;
}
$wp_uploads = wp_upload_dir();
$export = new PMXE_Export_Record();
$export->getById($export_id);
if ($export->isEmpty()) {
exit(__('Export is not defined.', 'wp_all_export_plugin'));
}
$exportOptions = $export->options + PMXE_Plugin::get_default_import_options();
wp_reset_postdata();
XmlExportEngine::$exportOptions = $exportOptions;
XmlExportEngine::$is_user_export = $exportOptions['is_user_export'];
XmlExportEngine::$exportID = $export_id;
$posts_per_page = $exportOptions['records_per_iteration'];
if ('advanced' == $exportOptions['export_type']) {
if (XmlExportEngine::$is_user_export) {
exit(json_encode(array('html' => __('Upgrade to the professional edition of WP All Export to export users.', 'wp_all_export_plugin'))));
} else {
$exportQuery = eval('return new WP_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => ' . $export->exported . ', \'posts_per_page\' => ' . $posts_per_page . ' ));');
}
} else {
XmlExportEngine::$post_types = $exportOptions['cpt'];
if (!in_array('users', $exportOptions['cpt'])) {
$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));
} else {
exit(json_encode(array('html' => __('Upgrade to the professional edition of WP All Export to export users.', 'wp_all_export_plugin'))));
}
}
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) {
$attachment_list = $export->options['attachment_list'];
if (!empty($attachment_list)) {
foreach ($attachment_list as $attachment) {
if (!is_numeric($attachment)) {
@unlink($attachment);
}
}
}
$exportOptions['attachment_list'] = array();
$export->set(array('options' => $exportOptions))->save();
$is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
if ($is_secure_import and !empty($exportOptions['filepath'])) {
// if 'Create a new file each time export is run' disabled remove all previously generated source files
// if ( ! $exportOptions['creata_a_new_export_file'] or ! $export->iteration ){
// 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':
pmxe_export_xml($exportQuery, $exportOptions);
break;
case 'csv':
pmxe_export_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, '</' . $exportOptions['main_xml_tag'] . '>', FILE_APPEND);
}
$is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
if (!$is_secure_import) {
if (!$export->isEmpty()) {
$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');
if (empty($export->attch_id)) {
$attach_id = wp_insert_attachment($attachment_data, PMXE_Plugin::$session->file);
//.........这里部分代码省略.........