本文整理汇总了PHP中PMXI_Import_Record::isEmpty方法的典型用法代码示例。如果您正苦于以下问题:PHP PMXI_Import_Record::isEmpty方法的具体用法?PHP PMXI_Import_Record::isEmpty怎么用?PHP PMXI_Import_Record::isEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PMXI_Import_Record
的用法示例。
在下文中一共展示了PMXI_Import_Record::isEmpty方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pmxi_wp_ajax_delete_import
function pmxi_wp_ajax_delete_import()
{
if (!check_ajax_referer('wp_all_import_secure', 'security', false)) {
exit(json_encode(array('result' => false, 'msg' => __('Security check', 'wp_all_import_plugin'))));
}
if (!current_user_can('manage_options')) {
exit(json_encode(array('result' => false, 'msg' => __('Security check', 'wp_all_import_plugin'))));
}
$input = new PMXI_Input();
$post = $input->post(array('data' => ''));
$get = $input->get(array('iteration' => 1));
$params = array();
parse_str($post['data'], $params);
$response = array('result' => false, 'msg' => '', 'redirect' => add_query_arg('pmxi_nt', urlencode(__('Import deleted', 'wp_all_import_plugin')), $params['base_url']));
if (!empty($params['import_ids'])) {
foreach ($params['import_ids'] as $key => $id) {
$import = new PMXI_Import_Record();
$import->getById($id);
if (!$import->isEmpty()) {
if ((int) $get['iteration'] === 1) {
$import->set(array('deleted' => 0))->update();
}
$is_all_records_deleted = $import->deletePostsAjax(!$params['is_delete_posts'], $params['is_delete_images'], $params['is_delete_attachments']);
$response['result'] = empty($params['import_ids'][$key + 1]) ? $is_all_records_deleted : false;
$response['msg'] = sprintf(__('Import #%d - %d records deleted', 'wp_all_import_plugin'), $import->id, $import->deleted);
if ($is_all_records_deleted === true) {
$import->delete(!$params['is_delete_posts'], $params['is_delete_images'], $params['is_delete_attachments']);
}
}
}
}
exit(json_encode($response));
}
示例2: pmwi_pmxi_after_xml_import
function pmwi_pmxi_after_xml_import($import_id)
{
$import = new PMXI_Import_Record();
$import->getById($import_id);
if (!$import->isEmpty() and in_array($import->options['custom_type'], array('product', 'product_variation')) and $import->options['is_keep_former_posts'] == 'no' and ($import->options['update_all_data'] == 'yes' or $import->options['is_update_categories'])) {
$product_cats = get_terms('product_cat', array('hide_empty' => false, 'fields' => 'id=>parent'));
_wc_term_recount($product_cats, get_taxonomy('product_cat'), true, false);
$product_tags = get_terms('product_tag', array('hide_empty' => false, 'fields' => 'id=>parent'));
_wc_term_recount($product_tags, get_taxonomy('product_tag'), true, false);
}
}
示例3: __construct
/**
* data load initialize
*
* @param mixed $filename please look at the load() method
*
* @access public
* @see load()
* @return void
*/
public function __construct($options = array('filename' => null, 'xpath' => '', 'delimiter' => '', 'encoding' => '', 'xml_path' => '', 'targetDir' => false))
{
PMXI_Plugin::$csv_path = $options['filename'];
$this->xpath = !empty($options['xpath']) ? $options['xpath'] : (!empty($_POST['xpath']) ? $_POST['xpath'] : '/node');
if (!empty($options['delimiter'])) {
$this->delimiter = $options['delimiter'];
} else {
$input = new PMXI_Input();
$id = $input->get('id', 0);
if (!$id) {
$id = $input->get('import_id', 0);
}
if ($id) {
$import = new PMXI_Import_Record();
$import->getbyId($id);
if (!$import->isEmpty()) {
$this->delimiter = $import->options['delimiter'];
}
}
}
if (!empty($options['encoding'])) {
$this->csv_encoding = $options['encoding'];
$this->auto_encoding = false;
}
if (!empty($options['xml_path'])) {
$this->xml_path = $options['xml_path'];
}
@ini_set("display_errors", 0);
@ini_set('auto_detect_line_endings', true);
$file_params = self::analyse_file($options['filename'], 1);
$this->set_settings(array('delimiter' => $file_params['delimiter']['value'], 'eol' => $file_params['line_ending']['value']));
unset($file_params);
$wp_uploads = wp_upload_dir();
$this->targetDir = empty($options['targetDir']) ? wp_all_import_secure_file($wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::UPLOADS_DIRECTORY) : $options['targetDir'];
$this->load($options['filename']);
}
示例4: delete
/**
* @see parent::delete()
*/
public function delete()
{
$this->deletePosts();
if (!empty($this->options['import_id']) and wp_all_export_is_compatible()) {
$import = new PMXI_Import_Record();
$import->getById($this->options['import_id']);
if (!$import->isEmpty() and $import->parent_import_id == 99999) {
$import->delete();
}
}
$export_file_path = wp_all_export_get_absolute_path($this->options['filepath']);
if (@file_exists($export_file_path)) {
wp_all_export_remove_source($export_file_path);
}
if (!empty($this->attch_id)) {
wp_delete_attachment($this->attch_id, true);
}
$wp_uploads = wp_upload_dir();
$file_for_remote_access = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::UPLOADS_DIRECTORY . DIRECTORY_SEPARATOR . md5(PMXE_Plugin::getInstance()->getOption('cron_job_key') . $this->id) . '.' . $this->options['export_to'];
if (@file_exists($file_for_remote_access)) {
@unlink($file_for_remote_access);
}
return parent::delete();
}
示例5: pmxi_wp_loaded
function pmxi_wp_loaded()
{
@ini_set("max_input_time", PMXI_Plugin::getInstance()->getOption('max_input_time'));
@ini_set("max_execution_time", PMXI_Plugin::getInstance()->getOption('max_execution_time'));
$table = PMXI_Plugin::getInstance()->getTablePrefix() . 'imports';
global $wpdb;
$imports = $wpdb->get_results("SELECT `id`, `name`, `path` FROM {$table} WHERE `path` IS NULL", ARRAY_A);
if (!empty($imports)) {
$importRecord = new PMXI_Import_Record();
$importRecord->clear();
foreach ($imports as $imp) {
$importRecord->getById($imp['id']);
if (!$importRecord->isEmpty()) {
$importRecord->delete(true);
}
$importRecord->clear();
}
}
/* Check if cron is manualy, then execute import */
$cron_job_key = PMXI_Plugin::getInstance()->getOption('cron_job_key');
if (!empty($cron_job_key) and !empty($_GET['import_id']) and !empty($_GET['import_key']) and $_GET['import_key'] == $cron_job_key and !empty($_GET['action']) and in_array($_GET['action'], array('processing', 'trigger', 'pipe'))) {
$logger = create_function('$m', 'echo "<p>$m</p>\\n";');
$import = new PMXI_Import_Record();
$ids = explode(',', $_GET['import_id']);
if (!empty($ids) and is_array($ids)) {
foreach ($ids as $id) {
if (empty($id)) {
continue;
}
$import->getById($id);
if (!$import->isEmpty()) {
if (!in_array($import->type, array('url', 'ftp', 'file'))) {
$logger and call_user_func($logger, sprintf(__('Scheduling update is not working with "upload" import type. Import #%s.', 'wp_all_import_plugin'), $id));
}
switch ($_GET['action']) {
case 'trigger':
if ((int) $import->executing) {
$logger and call_user_func($logger, sprintf(__('Import #%s is currently in manually process. Request skipped.', 'wp_all_import_plugin'), $id));
} elseif (!$import->processing and !$import->triggered) {
$import->set(array('triggered' => 1, 'imported' => 0, 'created' => 0, 'updated' => 0, 'skipped' => 0, 'deleted' => 0, 'queue_chunk_number' => 0, 'last_activity' => date('Y-m-d H:i:s')))->update();
$history_log = new PMXI_History_Record();
$history_log->set(array('import_id' => $import->id, 'date' => date('Y-m-d H:i:s'), 'type' => 'trigger', 'summary' => __("triggered by cron", "wp_all_import_plugin")))->save();
$logger and call_user_func($logger, sprintf(__('#%s Cron job triggered.', 'wp_all_import_plugin'), $id));
} elseif ($import->processing and !$import->triggered) {
$logger and call_user_func($logger, sprintf(__('Import #%s currently in process. Request skipped.', 'wp_all_import_plugin'), $id));
} elseif (!$import->processing and $import->triggered) {
$logger and call_user_func($logger, sprintf(__('Import #%s already triggered. Request skipped.', 'wp_all_import_plugin'), $id));
}
break;
case 'processing':
if ($import->processing == 1 and time() - strtotime($import->registered_on) > (PMXI_Plugin::getInstance()->getOption('cron_processing_time_limit') ? PMXI_Plugin::getInstance()->getOption('cron_processing_time_limit') : 120)) {
// it means processor crashed, so it will reset processing to false, and terminate. Then next run it will work normally.
$import->set(array('processing' => 0))->update();
}
// start execution imports that is in the cron process
if (!(int) $import->triggered) {
$logger and call_user_func($logger, sprintf(__('Import #%s is not triggered. Request skipped.', 'wp_all_import_plugin'), $id));
} elseif ((int) $import->executing) {
$logger and call_user_func($logger, sprintf(__('Import #%s is currently in manually process. Request skipped.', 'wp_all_import_plugin'), $id));
} elseif ((int) $import->triggered and !(int) $import->processing) {
$log_storage = (int) PMXI_Plugin::getInstance()->getOption('log_storage');
// unlink previous logs
$by = array();
$by[] = array(array('import_id' => $id, 'type NOT LIKE' => 'trigger'), 'AND');
$historyLogs = new PMXI_History_List();
$historyLogs->setColumns('id', 'import_id', 'type', 'date')->getBy($by, 'id ASC');
if ($historyLogs->count() and $historyLogs->count() >= $log_storage) {
$logsToRemove = $historyLogs->count() - $log_storage;
foreach ($historyLogs as $i => $file) {
$historyRecord = new PMXI_History_Record();
$historyRecord->getBy('id', $file['id']);
if (!$historyRecord->isEmpty()) {
$historyRecord->delete();
}
// unlink history file only
if ($i == $logsToRemove) {
break;
}
}
}
$history_log = new PMXI_History_Record();
$history_log->set(array('import_id' => $import->id, 'date' => date('Y-m-d H:i:s'), 'type' => 'processing', 'summary' => __("cron processing", "wp_all_import_plugin")))->save();
if ($log_storage) {
$wp_uploads = wp_upload_dir();
$log_file = wp_all_import_secure_file($wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::LOGS_DIRECTORY, $history_log->id) . DIRECTORY_SEPARATOR . $history_log->id . '.html';
if (@file_exists($log_file)) {
wp_all_import_remove_source($log_file, false);
}
}
ob_start();
$import->set(array('canceled' => 0, 'failed' => 0))->execute($logger, true, $history_log->id);
$log_data = ob_get_clean();
if ($log_storage) {
$log = @fopen($log_file, 'a+');
@fwrite($log, $log_data);
@fclose($log);
}
if (!(int) $import->queue_chunk_number) {
$logger and call_user_func($logger, sprintf(__('Import #%s complete', 'wp_all_import_plugin'), $import->id));
} else {
//.........这里部分代码省略.........
示例6: feed
public function feed()
{
$nonce = !empty($_REQUEST['_wpnonce']) ? $_REQUEST['_wpnonce'] : '';
if (!wp_verify_nonce($nonce, '_wpnonce-download_feed')) {
die(__('Security check', 'wp_all_import_plugin'));
} else {
$import_id = $this->input->get('id');
$path = '';
$import = new PMXI_Import_Record();
$import->getbyId($import_id);
if (!$import->isEmpty()) {
$path = wp_all_import_get_absolute_path($import->path);
}
if (file_exists($path)) {
if (preg_match('%\\W(zip)$%i', trim(basename($path)))) {
PMXI_download::zip($path);
} elseif (preg_match('%\\W(xml)$%i', trim(basename($path)))) {
PMXI_download::xml($path);
} else {
PMXI_download::csv($path);
}
} else {
wp_redirect(add_query_arg(array('pmxi_nt' => urlencode(__('File does not exists.', 'wp_all_import_plugin'))), $this->baseUrl));
die;
}
}
}
示例7: get_xml
protected function get_xml($tagno = 0, $debug = false)
{
$xml = '';
$update_previous = new PMXI_Import_Record();
if (!empty(PMXI_Plugin::$session->update_previous)) {
$update_previous->getById(PMXI_Plugin::$session->update_previous);
}
$local_paths = empty(PMXI_Plugin::$session->local_paths) ? array() : PMXI_Plugin::$session->local_paths;
if (empty($local_paths) and !$update_previous->isEmpty()) {
$history_file = new PMXI_File_Record();
$history_file->getBy(array('import_id' => $update_previous->id), 'id DESC');
$local_paths = !$history_file->isEmpty() ? array(wp_all_import_get_absolute_path($history_file->path)) : array();
}
if (!empty($local_paths)) {
$loop = 0;
foreach ($local_paths as $key => $path) {
if (@file_exists($path)) {
$root_element = !$update_previous->isEmpty() ? $update_previous->root_element : PMXI_Plugin::$session->source['root_element'];
$file = new PMXI_Chunk($path, array('element' => $root_element, 'encoding' => PMXI_Plugin::$session->encoding));
while ($xml = $file->read()) {
if (!empty($xml)) {
PMXI_Import_Record::preprocessXml($xml);
$xml = "<?xml version=\"1.0\" encoding=\"" . PMXI_Plugin::$session->encoding . "\"?>" . "\n" . $xml;
if (PMXI_Plugin::$session->xpath) {
$dom = new DOMDocument('1.0', PMXI_Plugin::$session->encoding);
$old = libxml_use_internal_errors(true);
$dom->loadXML($xml);
libxml_use_internal_errors($old);
$xpath = new DOMXPath($dom);
if ($elements = $xpath->query(PMXI_Plugin::$session->xpath) and $elements->length) {
$this->data['dom'] = $dom;
$loop++;
if (!$tagno or $loop == $tagno) {
break;
}
}
} else {
break;
}
}
}
unset($file);
}
}
}
return $xml;
}
示例8: cleanup
public function cleanup()
{
$removedFiles = 0;
$wp_uploads = wp_upload_dir();
$dir = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::TEMP_DIRECTORY;
$cacheDir = PMXI_Plugin::ROOT_DIR . '/libraries/cache';
$files = array_diff(@scandir($dir), array('.', '..'));
$cacheFiles = @array_diff(@scandir($cacheDir), array('.', '..'));
$msg = __('Files not found', 'wp_all_import_plugin');
if (count($files) or count($cacheFiles)) {
wp_all_import_clear_directory($dir);
wp_all_import_clear_directory($cacheDir);
$msg = __('Clean Up has been successfully completed.', 'wp_all_import_plugin');
}
// clean logs files
$table = PMXI_Plugin::getInstance()->getTablePrefix() . 'history';
global $wpdb;
$histories = $wpdb->get_results("SELECT * FROM {$table}", ARRAY_A);
if (!empty($histories)) {
$importRecord = new PMXI_Import_Record();
$importRecord->clear();
foreach ($histories as $history) {
$importRecord->getById($history['import_id']);
if ($importRecord->isEmpty()) {
$historyRecord = new PMXI_History_Record();
$historyRecord->getById($history['id']);
if (!$historyRecord->isEmpty()) {
$historyRecord->delete();
}
}
$importRecord->clear();
}
}
// clean uploads folder
$table = PMXI_Plugin::getInstance()->getTablePrefix() . 'files';
$files = $wpdb->get_results("SELECT * FROM {$table}", ARRAY_A);
$required_dirs = array();
if (!empty($files)) {
$importRecord = new PMXI_Import_Record();
$importRecord->clear();
foreach ($files as $file) {
$importRecord->getById($file['import_id']);
if ($importRecord->isEmpty()) {
$fileRecord = new PMXI_File_Record();
$fileRecord->getById($file['id']);
if (!$fileRecord->isEmpty()) {
$fileRecord->delete();
}
} else {
$path_parts = pathinfo(wp_all_import_get_absolute_path($file['path']));
if (!empty($path_parts['dirname'])) {
$path_all_parts = explode('/', $path_parts['dirname']);
$dirname = array_pop($path_all_parts);
if (wp_all_import_isValidMd5($dirname)) {
$required_dirs[] = $path_parts['dirname'];
}
}
}
$importRecord->clear();
}
}
$uploads_dir = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::UPLOADS_DIRECTORY;
if (($dir = @opendir($uploads_dir . DIRECTORY_SEPARATOR)) !== false or ($dir = @opendir($uploads_dir)) !== false) {
while (($file = @readdir($dir)) !== false) {
$filePath = $uploads_dir . DIRECTORY_SEPARATOR . $file;
if (is_dir($filePath) and !in_array($filePath, $required_dirs) and !in_array($file, array('.', '..'))) {
wp_all_import_rmdir($filePath);
}
}
}
wp_redirect(add_query_arg('pmxi_nt', urlencode($msg), $this->baseUrl));
die;
}
示例9: process
/**
* Step #3: Export
*/
public function process()
{
@set_time_limit(0);
$export = $this->data['update_previous'];
if (!PMXE_Plugin::is_ajax()) {
if ("" == PMXE_Plugin::$session->friendly_name) {
$friendly_name = '';
$post_types = PMXE_Plugin::$session->get('cpt');
if (!empty($post_types)) {
if (!in_array('users', $post_types)) {
$post_type_details = get_post_type_object(array_shift($post_types));
$friendly_name = $post_type_details->labels->name . ' Export - ' . date("Y F d H:i");
} else {
$friendly_name = 'Users Export - ' . date("Y F d H:i");
}
} else {
$friendly_name = 'WP_Query Export - ' . date("Y F d H:i");
}
PMXE_Plugin::$session->set('friendly_name', $friendly_name);
}
PMXE_Plugin::$session->set('file', '');
PMXE_Plugin::$session->save_data();
$export->set(array('triggered' => 0, 'processing' => 0, 'exported' => 0, 'executing' => 1, 'canceled' => 0, 'options' => PMXE_Plugin::$session->get_clear_session_data(), 'friendly_name' => PMXE_Plugin::$session->friendly_name, 'scheduled' => PMXE_Plugin::$session->is_scheduled ? PMXE_Plugin::$session->scheduled_period : '', 'registered_on' => date('Y-m-d H:i:s'), 'last_activity' => date('Y-m-d H:i:s')))->save();
$options = $export->options;
if ($options['is_generate_import'] and wp_all_export_is_compatible()) {
$import = new PMXI_Import_Record();
if (!empty($options['import_id'])) {
$import->getById($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();
PMXE_Plugin::$session->set('import_id', $import->id);
$options['import_id'] = $import->id;
$export->set(array('options' => $options))->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();
PMXE_Plugin::$session->set('import_id', $newImport->id);
$options['import_id'] = $newImport->id;
$export->set(array('options' => $options))->save();
}
}
}
PMXE_Plugin::$session->set('update_previous', $export->id);
PMXE_Plugin::$session->save_data();
}
$this->render();
}
示例10: import
/**
*
* Fires after wp_insert_post/wp_update_post
*
*/
public function import($post_id, $data, $import, $articleData, $logger)
{
// return if this is a basic post ( not a translation )
if (empty($import['options']['wpml_addon']['matching_logic']) or empty($import['options']['wpml_addon']['import'])) {
return;
}
// search for post to translate
$parentImport = new PMXI_Import_Record();
$parentImport->getById($import['options']['wpml_addon']['import']);
if (!$parentImport->isEmpty()) {
// post is that must be translated
$parent_post_id = false;
$postRecord = new PMXI_Post_Record();
$postRecord->clear();
$postRecord->getBy(array('unique_key' => $data['unique_key'], 'import_id' => $import['options']['wpml_addon']['import']));
if (!$postRecord->isEmpty()) {
$parent_post_id = $postRecord->post_id;
}
if ($parent_post_id) {
$post_type = in_array(get_post_type($post_id), array('product', 'product_variation')) ? 'post_product' : 'post_' . get_post_type($post_id);
$trid = $this->wpml->get_element_trid($parent_post_id, $post_type);
if ($trid) {
global $wpdb;
// sync translation slug
$parent_post = get_post($parent_post_id);
if (!empty($parent_post) and $parent_post->post_title == $articleData['post_title']) {
$wpdb->update($wpdb->posts, array('post_name' => $parent_post->post_name), array('ID' => $post_id));
}
// create a translation
$tid = $this->wpml->set_element_language_details($post_id, $post_type, $trid, $import->options['wpml_addon']['lng'], $parentImport->options['wpml_addon']['lng']);
if (is_wp_error($tid)) {
$logger and call_user_func($logger, __('<b>ERROR</b>', 'wpml-all-import') . ': ' . $tid->get_error_message());
} else {
$logger and call_user_func($logger, sprintf(__('- Created `%s` translation for `%s`', 'wpml-all-import'), $import->options['wpml_addon']['lng'], $parent_post->post_title));
}
}
}
}
}
示例11: 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();
}
}
}
示例12: 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);
//.........这里部分代码省略.........
示例13: __construct
/**
* __construct
*
* Builds the Chunk object
*
* @param string $file The filename to work with
* @param array $options The options with which to parse the file
* @author Dom Hastings
* @access public
*/
public function __construct($file, $options = array(), $parser_type = false)
{
// merge the options together
$this->options = array_merge($this->options, is_array($options) ? $options : array());
$this->options['chunkSize'] *= PMXI_Plugin::getInstance()->getOption('chunk_size');
// set the filename
$this->file = $file;
$this->parser_type = empty($parser_type) ? 'xmlreader' : $parser_type;
$is_html = false;
$f = @fopen($file, "rb");
while (!@feof($f)) {
$chunk = @fread($f, 1024);
if (strpos($chunk, "<!DOCTYPE") === 0) {
$is_html = true;
}
break;
}
@fclose($f);
if ($is_html) {
$path = $this->get_file_path();
$this->is_404 = true;
$this->reader = new XMLReader();
@$this->reader->open($path);
@$this->reader->setParserProperty(XMLReader::VALIDATE, false);
return;
}
if (PMXI_Plugin::getInstance()->getOption('force_stream_reader')) {
$this->parser_type = 'xmlstreamer';
} else {
$input = new PMXI_Input();
$import_id = $input->get('id', 0);
if (empty($import_id)) {
$import_id = $input->get('import_id', 0);
}
if (!empty($import_id)) {
$this->parser_type = empty($parser_type) ? 'xmlreader' : $parser_type;
$import = new PMXI_Import_Record();
$import->getById($import_id);
if (!$import->isEmpty()) {
$this->parser_type = empty($import->options['xml_reader_engine']) ? 'xmlreader' : 'xmlstreamer';
}
} else {
$this->parser_type = empty($parser_type) ? get_option('wpai_parser_type', 'xmlreader') : $parser_type;
}
}
if (empty($this->options['element']) or $this->options['get_cloud']) {
$path = $this->get_file_path();
if ($this->parser_type == 'xmlreader') {
$reader = new XMLReader();
$reader->open($path);
$reader->setParserProperty(XMLReader::VALIDATE, false);
while (@$reader->read()) {
switch ($reader->nodeType) {
case XMLREADER::ELEMENT:
$localName = str_replace("_colon_", ":", $reader->localName);
if (array_key_exists(str_replace(":", "_", $localName), $this->cloud)) {
$this->cloud[str_replace(":", "_", $localName)]++;
} else {
$this->cloud[str_replace(":", "_", $localName)] = 1;
}
break;
default:
break;
}
}
unset($reader);
} else {
$CHUNK_SIZE = 1024;
$streamProvider = new Prewk\XmlStringStreamer\Stream\File($path, $CHUNK_SIZE);
$parseroptions = array("extractContainer" => false);
// Works like an XmlReader, and walks the XML tree node by node. Captures by node depth setting.
$parser = new Parser\StringWalker($parseroptions);
// Create the streamer
$streamer = new XmlStringStreamer($parser, $streamProvider);
while ($node = $streamer->getNode()) {
// $simpleXmlNode = simplexml_load_string($node);
// echo (string)$simpleXmlNode->firstName;
}
$this->cloud = $parser->cloud;
}
if (!empty($this->cloud) and empty($this->options['element'])) {
arsort($this->cloud);
$main_elements = array('node', 'product', 'job', 'deal', 'entry', 'item', 'property', 'listing', 'hotel', 'record', 'article', 'post', 'book', 'item_0');
foreach ($this->cloud as $element_name => $value) {
if (in_array(strtolower($element_name), $main_elements)) {
$this->options['element'] = $element_name;
break;
}
}
if (empty($this->options['element'])) {
//.........这里部分代码省略.........
示例14: pmai_wp_ajax_get_acf
function pmai_wp_ajax_get_acf()
{
if (!check_ajax_referer('wp_all_import_secure', 'security', false)) {
exit(json_encode(array('html' => __('Security check', 'wp_all_import_plugin'))));
}
if (!current_user_can('manage_options')) {
exit(json_encode(array('html' => __('Security check', 'wp_all_import_plugin'))));
}
global $acf;
$version = $acf ? $acf->settings['version'] : false;
ob_start();
$acf_groups = PMXI_Plugin::$session->acf_groups;
$acf_obj = false;
if (!empty($acf_groups)) {
foreach ($acf_groups as $key => $group) {
if ($group['ID'] == $_GET['acf']) {
$acf_obj = $group;
break;
}
}
}
$import = new PMXI_Import_Record();
if (!empty($_GET['id'])) {
$import->getById($_GET['id']);
}
$is_loaded_template = !empty(PMXI_Plugin::$session->is_loaded_template) ? PMXI_Plugin::$session->is_loaded_template : false;
if ($is_loaded_template) {
$default = PMAI_Plugin::get_default_import_options();
$template = new PMXI_Template_Record();
if (!$template->getById($is_loaded_template)->isEmpty()) {
$options = (!empty($template->options) ? $template->options : array()) + $default;
}
} else {
if (!$import->isEmpty()) {
$options = $import->options;
} else {
$options = PMXI_Plugin::$session->options;
}
}
?>
<div class="postbox acf_postbox default acf_signle_group rad4" rel="<?php
echo $acf_obj['ID'];
?>
">
<h3 class="hndle" style="margin-top:0;"><span><?php
echo $acf_obj['title'];
?>
</span></h3>
<div class="inside">
<?php
if ($version and version_compare($version, '5.0.0') >= 0) {
if (is_numeric($acf_obj['ID'])) {
$acf_fields = get_posts(array('posts_per_page' => -1, 'post_type' => 'acf-field', 'post_parent' => $_GET['acf'], 'post_status' => 'publish', 'orderby' => 'menu_order', 'order' => 'ASC'));
if (!empty($acf_fields)) {
foreach ($acf_fields as $field) {
$fieldData = !empty($field->post_content) ? unserialize($field->post_content) : array();
$fieldData['ID'] = $field->ID;
$fieldData['id'] = $field->ID;
$fieldData['label'] = $field->post_title;
$fieldData['key'] = $field->post_name;
if (empty($fieldData['name'])) {
$fieldData['name'] = $field->post_excerpt;
}
echo pmai_render_field($fieldData, !empty($options) ? $options : array());
}
}
} else {
$fields = acf_local()->fields;
if (!empty($fields)) {
foreach ($fields as $key => $field) {
if ($field['parent'] == $acf_obj['key']) {
$fieldData = $field;
$fieldData['id'] = uniqid();
$fieldData['label'] = $field['label'];
$fieldData['key'] = $field['key'];
echo pmai_render_field($fieldData, !empty($options) ? $options : array());
}
}
}
}
} else {
if (is_numeric($acf_obj['ID'])) {
$fields = array();
foreach (get_post_meta($acf_obj['ID'], '') as $cur_meta_key => $cur_meta_val) {
if (strpos($cur_meta_key, 'field_') !== 0) {
continue;
}
$fields[] = !empty($cur_meta_val[0]) ? unserialize($cur_meta_val[0]) : array();
}
if (count($fields)) {
$sortArray = array();
foreach ($fields as $field) {
foreach ($field as $key => $value) {
if (!isset($sortArray[$key])) {
$sortArray[$key] = array();
}
$sortArray[$key][] = $value;
}
}
$orderby = "order_no";
//.........这里部分代码省略.........