function pmxi_wp_ajax_auto_detect_sf() { if (!check_ajax_referer('wp_all_import_secure', 'security', false)) { exit(json_encode(array('result' => array(), 'msg' => __('Security check', 'wp_all_import_plugin')))); } if (!current_user_can(PMXI_Plugin::$capabilities)) { exit(json_encode(array('result' => array(), 'msg' => __('Security check', 'wp_all_import_plugin')))); } $input = new PMXI_Input(); $fieldName = $input->post('name', ''); $post_type = $input->post('post_type', 'post'); global $wpdb; $result = array(); if ($fieldName) { if ($post_type == 'import_users') { $values = $wpdb->get_results("\n\t\t\t\tSELECT DISTINCT usermeta.meta_value\n\t\t\t\tFROM " . $wpdb->usermeta . " as usermeta\n\t\t\t\tWHERE usermeta.meta_key='" . $fieldName . "'\n\t\t\t", ARRAY_A); } else { $values = $wpdb->get_results("\n\t\t\t\tSELECT DISTINCT postmeta.meta_value\n\t\t\t\tFROM " . $wpdb->postmeta . " as postmeta\n\t\t\t\tWHERE postmeta.meta_key='" . $fieldName . "'\n\t\t\t", ARRAY_A); } if (!empty($values)) { foreach ($values as $key => $value) { if (!empty($value['meta_value']) and is_serialized($value['meta_value'])) { $v = unserialize($value['meta_value']); if (!empty($v) and is_array($v)) { foreach ($v as $skey => $svalue) { $result[] = array('key' => $skey, 'val' => maybe_serialize($svalue)); } break; } } } } } exit(json_encode(array('result' => $result))); }
function pmxi_wp_ajax_auto_detect_sf() { $input = new PMXI_Input(); $fieldName = $input->post('name', ''); $post_type = $input->post('post_type', 'post'); global $wpdb; $result = array(); if ($fieldName) { if ($post_type == 'import_users') { $values = $wpdb->get_results("\n\t\t\t\tSELECT DISTINCT usermeta.meta_value\n\t\t\t\tFROM " . $wpdb->usermeta . " as usermeta\n\t\t\t\tWHERE usermeta.meta_key='" . $fieldName . "'\n\t\t\t", ARRAY_A); } else { $values = $wpdb->get_results("\n\t\t\t\tSELECT DISTINCT postmeta.meta_value\n\t\t\t\tFROM " . $wpdb->postmeta . " as postmeta\n\t\t\t\tWHERE postmeta.meta_key='" . $fieldName . "'\n\t\t\t", ARRAY_A); } if (!empty($values)) { foreach ($values as $key => $value) { if (!empty($value['meta_value']) and is_serialized($value['meta_value'])) { $v = unserialize($value['meta_value']); if (!empty($v) and is_array($v)) { foreach ($v as $skey => $svalue) { $result[] = array('key' => $skey, 'val' => maybe_serialize($svalue)); } break; } } } } } exit(json_encode(array('result' => $result))); }
function pmxi_wp_ajax_save_import_functions() { 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')))); } $uploads = wp_upload_dir(); $functions = $uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_IMPORT_UPLOADS_BASE_DIRECTORY . DIRECTORY_SEPARATOR . 'functions.php'; $input = new PMXI_Input(); $post = $input->post('data', ''); $response = wp_remote_post('http://phpcodechecker.com/api', array('body' => array('code' => $post))); if (is_wp_error($response)) { $error_message = $response->get_error_message(); exit(json_encode(array('result' => false, 'msg' => $error_message))); die; } else { $body = json_decode(wp_remote_retrieve_body($response), true); if ($body['errors'] === 'TRUE') { exit(json_encode(array('result' => false, 'msg' => $body['syntax']['message']))); die; } elseif ($body['errors'] === 'FALSE') { if (strpos($post, "<?php") === false || strpos($post, "?>") === false) { exit(json_encode(array('result' => false, 'msg' => __('PHP code must be wrapped in "<?php" and "?>"', 'wp_all_import_plugin')))); die; } else { file_put_contents($functions, $post); } } } exit(json_encode(array('result' => true, 'msg' => __('File has been successfully updated.', 'wp_all_import_plugin')))); die; }
function pmxi_wp_ajax_nested_merge() { if (!check_ajax_referer('wp_all_import_secure', 'security', false)) { exit(json_encode(array('success' => false, 'msg' => __('Security check', 'wp_all_import_plugin')))); } if (!current_user_can(PMXI_Plugin::$capabilities)) { exit(json_encode(array('success' => false, 'msg' => __('Security check', 'wp_all_import_plugin')))); } $input = new PMXI_Input(); $post = $input->post(array('filePath' => '')); PMXI_Plugin::$session = PMXI_Session::get_instance(); /*$nested_file = array( 'file' => $filePath, 'source' => $realPath, 'xpath' => $customXpath, 'root_element' => $root_element, 'main_xml_field' => $main_xml_field, 'child_xml_field' => $child_xml_field ); */ $nested_files = empty(PMXI_Plugin::$session->options['nested_files']) ? array() : json_decode(PMXI_Plugin::$session->options['nested_files'], true); $nested_files[] = $post['filePath']; $options = PMXI_Plugin::$session->options; $options['nested_files'] = json_encode($nested_files); PMXI_Plugin::$session->set('options', $options); PMXI_Plugin::$session->save_data(); exit(json_encode(array('success' => true, 'nested_files' => $nested_files))); die; }
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)); }
function pmxi_wp_ajax_auto_detect_cf() { if (!check_ajax_referer('wp_all_import_secure', 'security', false)) { exit(json_encode(array('result' => array(), 'msg' => __('Security check', 'wp_all_import_plugin')))); } if (!current_user_can(PMXI_Plugin::$capabilities)) { exit(json_encode(array('result' => array(), 'msg' => __('Security check', 'wp_all_import_plugin')))); } $input = new PMXI_Input(); $fields = $input->post('fields', array()); $post_type = $input->post('post_type', 'post'); global $wpdb; $ignoreFields = array('_visibility', '_stock_status', '_downloadable', '_virtual', '_regular_price', '_sale_price', '_purchase_note', '_featured', '_weight', '_length', '_width', '_height', '_sku', '_sale_price_dates_from', '_sale_price_dates_to', '_price', '_sold_individually', '_manage_stock', '_stock', '_upsell_ids', '_crosssell_ids', '_downloadable_files', '_download_limit', '_download_expiry', '_download_type', '_product_url', '_button_text', '_backorders', '_tax_status', '_tax_class', '_product_image_gallery', '_default_attributes', 'total_sales', '_product_attributes', '_product_version', '_thumbnail_id', '_is_first_variation_created', '_regular_price_tmp', '_sale_price_tmp', '_price_tmp', '_stock_tmp'); $result = array(); if ($fields) { is_array($fields) or $fields = array($fields); foreach ($fields as $field) { if ($post_type == 'import_users') { $values = $wpdb->get_results("\n\t\t\t\t\tSELECT DISTINCT usermeta.meta_value\n\t\t\t\t\tFROM " . $wpdb->usermeta . " as usermeta\n\t\t\t\t\tWHERE usermeta.meta_key='" . $field . "'\n\t\t\t\t", ARRAY_A); } else { $values = $wpdb->get_results("\n\t\t\t\t\tSELECT DISTINCT postmeta.meta_value\n\t\t\t\t\tFROM " . $wpdb->postmeta . " as postmeta\n\t\t\t\t\tWHERE postmeta.meta_key='" . $field . "'\n\t\t\t\t", ARRAY_A); } if (!empty($values)) { foreach ($values as $key => $value) { if (!empty($value['meta_value']) and !empty($field) and !in_array($field, $ignoreFields) and strpos($field, '_max_') !== 0 and strpos($field, '_min_') !== 0) { $result[] = array('key' => $field, 'val' => $value['meta_value'], 'is_serialized' => is_serialized($value['meta_value'])); break; } } } } } if (empty($result)) { $custom_type = get_post_type_object($post_type); $msg = sprintf(__('No Custom Fields are present in your database for %s', 'wp_all_import_plugin'), $custom_type->labels->name); } elseif (count($result) === 1) { $msg = sprintf(__('%s field was automatically detected.', 'wp_all_import_plugin'), count($result)); } else { $msg = sprintf(__('%s fields were automatically detected.', 'wp_all_import_plugin'), count($result)); } exit(json_encode(array('result' => $result, 'msg' => $msg))); }
function pmxi_wp_ajax_auto_detect_cf() { if (!check_ajax_referer('wp_all_import_secure', 'security', false)) { exit(json_encode(array('result' => array(), 'msg' => __('Security check', 'wp_all_import_plugin')))); } if (!current_user_can('manage_options')) { exit(json_encode(array('result' => array(), 'msg' => __('Security check', 'wp_all_import_plugin')))); } $input = new PMXI_Input(); $fields = $input->post('fields', array()); $post_type = $input->post('post_type', 'post'); global $wpdb; $ignoreFields = array('_thumbnail_id', '_product_image_gallery', '_default_attributes', '_product_attributes'); $result = array(); if ($fields) { is_array($fields) or $fields = array($fields); foreach ($fields as $field) { if ($post_type == 'import_users') { $values = $wpdb->get_results("\n\t\t\t\t\tSELECT DISTINCT usermeta.meta_value\n\t\t\t\t\tFROM " . $wpdb->usermeta . " as usermeta\n\t\t\t\t\tWHERE usermeta.meta_key='" . $field . "'\n\t\t\t\t", ARRAY_A); } else { $values = $wpdb->get_results("\n\t\t\t\t\tSELECT DISTINCT postmeta.meta_value\n\t\t\t\t\tFROM " . $wpdb->postmeta . " as postmeta\n\t\t\t\t\tWHERE postmeta.meta_key='" . $field . "'\n\t\t\t\t", ARRAY_A); } if (!empty($values)) { foreach ($values as $key => $value) { if (!empty($value['meta_value']) and !empty($field) and !in_array($field, $ignoreFields)) { $result[] = array('key' => $field, 'val' => $value['meta_value'], 'is_serialized' => is_serialized($value['meta_value'])); break; } } } } } if (empty($result)) { $custom_type = get_post_type_object($post_type); $msg = sprintf(__('No Custom Fields are present in your database for %s', 'wp_all_import_plugin'), $custom_type->labels->name); } elseif (count($result) === 1) { $msg = sprintf(__('%s field was automatically detected.', 'wp_all_import_plugin'), count($result)); } else { $msg = sprintf(__('%s fields were automatically detected.', 'wp_all_import_plugin'), count($result)); } exit(json_encode(array('result' => $result, 'msg' => $msg))); }
function pmxi_wp_ajax_unmerge_file() { if (!check_ajax_referer('wp_all_import_secure', 'security', false)) { exit(json_encode(array('success' => false, 'msg' => __('Security check', 'wp_all_import_plugin')))); } if (!current_user_can('manage_options')) { exit(json_encode(array('success' => false, 'msg' => __('Security check', 'wp_all_import_plugin')))); } $input = new PMXI_Input(); $post = $input->post(array('source' => '')); PMXI_Plugin::$session = PMXI_Session::get_instance(); if (!empty(PMXI_Plugin::$session->options['nested_files']) and !empty($post['source'])) { $nested_files = json_decode(PMXI_Plugin::$session->options['nested_files'], true); unset($nested_files[$post['source']]); $options = PMXI_Plugin::$session->options; $options['nested_files'] = json_encode($nested_files); PMXI_Plugin::$session->set('options', $options); PMXI_Plugin::$session->save_data(); exit(json_encode(array('success' => true, 'nested_files' => $nested_files))); die; } exit(json_encode(array('success' => false))); die; }
function helper_current_field_values($default = array()) { if (empty($default)) { $options = array('mapping' => array(), 'xpaths' => array()); foreach ($this->fields as $field_slug => $field_params) { $options[$field_slug] = ''; if (!empty($field_params['enum_values'])) { foreach ($field_params['enum_values'] as $key => $value) { $options[$field_slug] = is_numeric($key) ? (int) $key : $key; break; } } } $default = array($this->slug => $options); } $input = new PMXI_Input(); $id = $input->get('id'); $import = new PMXI_Import_Record(); if (!$id or $import->getById($id)->isEmpty()) { // specified import is not found $post = $input->post($default); } else { $post = $input->post($import->options + $default); } $is_loaded_template = !empty(PMXI_Plugin::$session->is_loaded_template) ? PMXI_Plugin::$session->is_loaded_template : false; $load_options = $input->post('load_template'); if ($load_options) { // init form with template selected $template = new PMXI_Template_Record(); if (!$template->getById($is_loaded_template)->isEmpty()) { $post = (!empty($template->options) ? $template->options : array()) + $default; } } elseif ($load_options == -1) { $post = $default; } return $post; }
function pmxi_wp_ajax_get_bundle_post_type() { if (!check_ajax_referer('wp_all_import_secure', 'security', false)) { exit(json_encode(array('success' => false, 'errors' => '<div class="error inline"><p>' . __('Security check', 'wp_all_import_plugin') . '</p></div>'))); } if (!current_user_can(PMXI_Plugin::$capabilities)) { exit(json_encode(array('success' => false, 'errors' => '<div class="error inline"><p>' . __('Security check', 'wp_all_import_plugin') . '</p></div>'))); } $input = new PMXI_Input(); $post = $input->post(array('file' => '')); $response = array('post_type' => false, 'notice' => false); if (preg_match('%\\W(zip)$%i', trim($post['file']))) { if (!class_exists('PclZip')) { include_once PMXI_Plugin::ROOT_DIR . '/libraries/pclzip.lib.php'; } $uploads = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::FILES_DIRECTORY . DIRECTORY_SEPARATOR; $archive = new PclZip($uploads . $post['file']); $tmp_dir = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::TEMP_DIRECTORY . DIRECTORY_SEPARATOR . md5(time()); @wp_mkdir_p($tmp_dir); $v_result_list = $archive->extract(PCLZIP_OPT_PATH, $tmp_dir, PCLZIP_OPT_REPLACE_NEWER); if ($v_result_list) { foreach ($v_result_list as $unzipped_file) { if ($unzipped_file['status'] == 'ok' and preg_match('%\\W(xml|csv|txt|dat|psv|json|xls|xlsx)$%i', trim($unzipped_file['stored_filename'])) and strpos($unzipped_file['stored_filename'], 'readme.txt') === false) { if (strpos(basename($unzipped_file['stored_filename']), 'WP All Import Template') === 0 || strpos(basename($unzipped_file['stored_filename']), 'templates_') === 0) { $templates = file_get_contents($unzipped_file['filename']); $decodedTemplates = json_decode($templates, true); $templateOptions = empty($decodedTemplates[0]) ? current($decodedTemplates) : $decodedTemplates; $options = empty($templateOptions[0]['options']) ? false : maybe_unserialize($templateOptions[0]['options']); $response['post_type'] = !empty($options) ? $options['custom_type'] : false; } } } } wp_all_import_rmdir($tmp_dir); if (!empty($response['post_type'])) { switch ($response['post_type']) { case 'product': case 'shop_order': if (!class_exists('WooCommerce')) { $response['notice'] = __('<p class="wpallimport-bundle-notice">The import bundle you are using requires WooCommerce.</p><a class="upgrade_link" href="https://wordpress.org/plugins/woocommerce/" target="_blank">Get WooCommerce</a>.', 'wp_all_import_plugin'); } else { if (!defined('PMWI_EDITION')) { $response['notice'] = __('<p class="wpallimport-bundle-notice">The import bundle you are using requires the Pro version of the WooCommerce Add-On.</p><a href="http://www.wpallimport.com/checkout/?edd_action=add_to_cart&download_id=1529&edd_options%5Bprice_id%5D=1" class="upgrade_link" target="_blank">Purchase the WooCommerce Add-On</a>.', 'wp_all_import_plugin'); } elseif (PMWI_EDITION != 'paid') { $response['notice'] = __('<p class="wpallimport-bundle-notice">The import bundle you are using requires the Pro version of the WooCommerce Add-On, but you have the free version installed.</p><a href="http://www.wpallimport.com/checkout/?edd_action=add_to_cart&download_id=1529&edd_options%5Bprice_id%5D=1" target="_blank" class="upgrade_link">Purchase the WooCommerce Add-On</a>.', 'wp_all_import_plugin'); } } break; case 'import_users': if (!class_exists('PMUI_Plugin')) { $response['notice'] = __('<p class="wpallimport-bundle-notice">The import bundle you are using requires the User Import Add-On.</p><a href="http://www.wpallimport.com/checkout/?edd_action=add_to_cart&download_id=1921&edd_options%5Bprice_id%5D=1" target="_blank" class="upgrade_link">Purchase the User Import Add-On</a>.', 'wp_all_import_plugin'); } break; default: # code... break; } } } exit(json_encode($response)); }
/** * Constructor */ public function __construct() { $remove = array_diff(array_keys($_GET), $this->baseUrlParamNames); $p_url = parse_url(site_url()); $url = $p_url['scheme'] . '://' . $p_url['host']; if (!empty($_POST['is_settings_submitted'])) { // save settings form $input = new PMXI_Input(); $post = $input->post(array('port' => '')); PMXI_Plugin::getInstance()->updateOption($post); } $port = PMXI_Plugin::getInstance()->getOption('port'); if (!empty($port) and is_numeric($port)) { $url .= ':' . $port; } if ($remove) { $this->baseUrl = $url . remove_query_arg($remove); } else { $this->baseUrl = $url . $_SERVER['REQUEST_URI']; } parent::__construct(); // add special filter for url fields $this->input->addFilter(create_function('$str', 'return "http://" == $str || "ftp://" == $str ? "" : $str;')); // enqueue required sripts and styles global $wp_styles; if (!is_a($wp_styles, 'WP_Styles')) { $wp_styles = new WP_Styles(); } wp_enqueue_style('jquery-ui', WP_ALL_IMPORT_ROOT_URL . '/static/js/jquery/css/redmond/jquery-ui.css'); wp_enqueue_style('jquery-tipsy', WP_ALL_IMPORT_ROOT_URL . '/static/js/jquery/css/smoothness/jquery.tipsy.css'); wp_enqueue_style('pmxi-admin-style', WP_ALL_IMPORT_ROOT_URL . '/static/css/admin.css', array(), PMXI_VERSION); wp_enqueue_style('pmxi-admin-style-ie', WP_ALL_IMPORT_ROOT_URL . '/static/css/admin-ie.css'); wp_enqueue_style('jquery-select2', WP_ALL_IMPORT_ROOT_URL . '/static/js/jquery/css/select2/select2.css'); wp_enqueue_style('jquery-select2', WP_ALL_IMPORT_ROOT_URL . '/static/js/jquery/css/select2/select2-bootstrap.css'); add_editor_style(WP_ALL_IMPORT_ROOT_URL . '/static/css/custom-editor-style.css'); wp_enqueue_style('jquery-codemirror', WP_ALL_IMPORT_ROOT_URL . '/static/codemirror/codemirror.css', array(), PMXI_VERSION); $wp_styles->add_data('pmxi-admin-style-ie', 'conditional', 'lte IE 7'); wp_enqueue_style('wp-pointer'); if (version_compare(get_bloginfo('version'), '3.8-RC1') >= 0) { wp_enqueue_style('pmxi-admin-style-wp-3.8', WP_ALL_IMPORT_ROOT_URL . '/static/css/admin-wp-3.8.css'); } if (version_compare(get_bloginfo('version'), '4.0-beta3') >= 0) { wp_enqueue_style('pmxi-admin-style-wp-3.8', WP_ALL_IMPORT_ROOT_URL . '/static/css/admin-wp-4.0.css'); } $scheme_color = get_user_option('admin_color') and is_file(PMXI_Plugin::ROOT_DIR . '/static/css/admin-colors-' . $scheme_color . '.css') or $scheme_color = 'fresh'; if (is_file(PMXI_Plugin::ROOT_DIR . '/static/css/admin-colors-' . $scheme_color . '.css')) { wp_enqueue_style('pmxi-admin-style-color', WP_ALL_IMPORT_ROOT_URL . '/static/css/admin-colors-' . $scheme_color . '.css'); } wp_enqueue_script('jquery-ui-datepicker', WP_ALL_IMPORT_ROOT_URL . '/static/js/jquery/ui.datepicker.js', 'jquery-ui-core'); //wp_enqueue_script('wp-all-import-autocomplete', WP_ALL_IMPORT_ROOT_URL . '/static/js/jquery/ui.autocomplete.js', array('jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-position')); wp_enqueue_script('jquery-tipsy', WP_ALL_IMPORT_ROOT_URL . '/static/js/jquery/jquery.tipsy.js', 'jquery'); wp_enqueue_script('jquery-nestable', WP_ALL_IMPORT_ROOT_URL . '/static/js/jquery/jquery.mjs.nestedSortable.js', array('jquery', 'jquery-ui-dialog', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-tabs', 'jquery-ui-progressbar')); wp_enqueue_script('jquery-moment', WP_ALL_IMPORT_ROOT_URL . '/static/js/jquery/moment.js', 'jquery'); wp_enqueue_script('jquery-select2', WP_ALL_IMPORT_ROOT_URL . '/static/js/jquery/select2.min.js', 'jquery'); wp_enqueue_script('jquery-ddslick', WP_ALL_IMPORT_ROOT_URL . '/static/js/jquery/jquery.ddslick.min.js', 'jquery'); wp_enqueue_script('jquery-contextmenu', WP_ALL_IMPORT_ROOT_URL . '/static/js/jquery/jquery.ui-contextmenu.min.js', array('jquery', 'jquery-ui-menu')); wp_enqueue_script('jquery-codemirror', WP_ALL_IMPORT_ROOT_URL . '/static/codemirror/codemirror.js', array(), PMXI_VERSION); wp_enqueue_script('jquery-codemirror-matchbrackets', WP_ALL_IMPORT_ROOT_URL . '/static/codemirror/matchbrackets.js', array('jquery-codemirror'), PMXI_VERSION); wp_enqueue_script('jquery-codemirror-htmlmixed', WP_ALL_IMPORT_ROOT_URL . '/static/codemirror/htmlmixed.js', array('jquery-codemirror-matchbrackets'), PMXI_VERSION); wp_enqueue_script('jquery-codemirror-xml', WP_ALL_IMPORT_ROOT_URL . '/static/codemirror/xml.js', array('jquery-codemirror-htmlmixed'), PMXI_VERSION); wp_enqueue_script('jquery-codemirror-javascript', WP_ALL_IMPORT_ROOT_URL . '/static/codemirror/javascript.js', array('jquery-codemirror-xml'), PMXI_VERSION); wp_enqueue_script('jquery-codemirror-clike', WP_ALL_IMPORT_ROOT_URL . '/static/codemirror/clike.js', array('jquery-codemirror-javascript'), PMXI_VERSION); wp_enqueue_script('jquery-codemirror-php', WP_ALL_IMPORT_ROOT_URL . '/static/codemirror/php.js', array('jquery-codemirror-clike'), PMXI_VERSION); wp_enqueue_script('wp-pointer'); /* load plupload scripts */ wp_deregister_script('swfupload-all'); wp_deregister_script('swfupload-handlers'); wp_enqueue_script('swfupload-handlers', site_url() . "/wp-includes/js/swfupload/handlers.js", array('jquery'), '2201-20100523'); wp_enqueue_script('jquery-browserplus-min', WP_ALL_IMPORT_ROOT_URL . '/static/js/jquery/browserplus-min.js', array('jquery')); wp_enqueue_script('full-plupload', WP_ALL_IMPORT_ROOT_URL . '/static/js/plupload/plupload.full.js', array('jquery-browserplus-min')); wp_enqueue_script('jquery-plupload', WP_ALL_IMPORT_ROOT_URL . '/static/js/plupload/wplupload.js', array('full-plupload', 'jquery')); wp_enqueue_script('pmxi-admin-script', WP_ALL_IMPORT_ROOT_URL . '/static/js/admin.js', array('jquery', 'jquery-ui-dialog', 'jquery-ui-datepicker', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-position', 'jquery-ui-autocomplete'), PMXI_VERSION); }
function pmxi_wp_ajax_upload_resource() { if (!check_ajax_referer('wp_all_import_secure', 'security', false)) { exit(json_encode(array('success' => false, 'errors' => '<div class="error inline"><p>' . __('Security check', 'wp_all_import_plugin') . '</p></div>'))); } if (!current_user_can('manage_options')) { exit(json_encode(array('success' => false, 'errors' => '<div class="error inline"><p>' . __('Security check', 'wp_all_import_plugin') . '</p></div>'))); } $input = new PMXI_Input(); $post = $input->post(array('type' => '', 'file' => '')); $response = array('success' => true, 'errors' => false, 'upload_result' => '', 'filesize' => 0); if ($post['type'] == 'url') { $filesXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<data><node></node></data>"; $files = XmlImportParser::factory($filesXML, '/data/node', $post['file'], $file)->parse(); $tmp_files[] = $file; foreach ($tmp_files as $tmp_file) { // remove all temporary files created @unlink($tmp_file); } $file_to_import = $post['file']; if (!empty($files) and is_array($files)) { $file_to_import = array_shift($files); } $errors = new WP_Error(); $uploader = new PMXI_Upload(trim($file_to_import), $errors); $upload_result = $uploader->url('', $post['file']); if ($upload_result instanceof WP_Error) { $errors = $upload_result; $msgs = $errors->get_error_messages(); ob_start(); ?> <?php foreach ($msgs as $msg) { ?> <div class="error inline"><p><?php echo $msg; ?> </p></div> <?php } ?> <?php $response = array('success' => false, 'errors' => ob_get_clean()); } else { // validate XML $file = new PMXI_Chunk($upload_result['filePath'], array('element' => $upload_result['root_element'])); $is_valid = true; if (!empty($file->options['element'])) { $defaultXpath = "/" . $file->options['element']; } else { $is_valid = false; } if ($is_valid) { while ($xml = $file->read()) { if (!empty($xml)) { PMXI_Import_Record::preprocessXml($xml); $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . $xml; $dom = new DOMDocument('1.0', 'UTF-8'); $old = libxml_use_internal_errors(true); $dom->loadXML($xml); libxml_use_internal_errors($old); $xpath = new DOMXPath($dom); if ($elements = $xpath->query($defaultXpath) and $elements->length) { break; } } /*else { $is_valid = false; break; }*/ } if (empty($xml)) { $is_valid = false; } } unset($file); if (!$is_valid) { ob_start(); ?> <div class="error inline"><p><?php _e('Please confirm you are importing a valid feed.<br/> Often, feed providers distribute feeds with invalid data, improperly wrapped HTML, line breaks where they should not be, faulty character encodings, syntax errors in the XML, and other issues.<br/><br/>WP All Import has checks in place to automatically fix some of the most common problems, but we can’t catch every single one.<br/><br/>It is also possible that there is a bug in WP All Import, and the problem is not with the feed.<br/><br/>If you need assistance, please contact support – <a href="mailto:support@wpallimport.com">support@wpallimport.com</a> – with your XML/CSV file. We will identify the problem and release a bug fix if necessary.', 'wp_all_import_plugin'); ?> </p></div> <?php $response = array('success' => false, 'errors' => ob_get_clean()); } else { $response['upload_result'] = $upload_result; $response['filesize'] = filesize($upload_result['filePath']); } } } exit(json_encode($response)); }
function pmxi_wp_ajax_test_images() { if (!check_ajax_referer('wp_all_import_secure', 'security', false)) { exit(json_encode(array('result' => array(), 'failed_msgs' => array(__('Security check', 'wp_all_import_plugin'))))); } if (!current_user_can('manage_options')) { exit(json_encode(array('result' => array(), 'failed_msgs' => array(__('Security check', 'wp_all_import_plugin'))))); } $input = new PMXI_Input(); $post = $input->post(array('download' => 'yes', 'imgs' => array())); $result = array(); $wp_uploads = wp_upload_dir(); $imgs_basedir = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::FILES_DIRECTORY . DIRECTORY_SEPARATOR; $targetDir = $wp_uploads['path']; $success_images = 0; $success_msg = ''; $failed_msgs = array(); if (!@is_writable($targetDir)) { $failed_msgs[] = sprintf(__('Uploads folder `%s` is not writable.', 'wp_all_import_plugin'), $targetDir); } else { if ('no' == $post['download']) { if (!empty($post['imgs'])) { foreach ($post['imgs'] as $img) { if (preg_match('%^(http|https|ftp|ftps)%i', $img)) { $failed_msgs[] = sprintf(__('Use image name instead of URL `%s`.', 'wp_all_import_plugin'), $img); continue; } if (@file_exists($imgs_basedir . $img)) { if (@is_readable($imgs_basedir . $img)) { $success_images++; } else { $failed_msgs[] = sprintf(__('File `%s` isn\'t readable'), preg_replace('%.*/wp-content%', '/wp-content', $imgs_basedir . $img)); } } else { $failed_msgs[] = sprintf(__('File `%s` doesn\'t exist'), preg_replace('%.*/wp-content%', '/wp-content', $imgs_basedir . $img)); } } } if ((int) $success_images === 1) { $success_msg = sprintf(__('%d image was successfully retrieved from `%s`', 'wp_all_import_plugin'), $success_images, preg_replace('%.*/wp-content%', '/wp-content', $wp_uploads['basedir']) . DIRECTORY_SEPARATOR . PMXI_Plugin::FILES_DIRECTORY); } elseif ((int) $success_images > 1) { $success_msg = sprintf(__('%d images were successfully retrieved from `%s`', 'wp_all_import_plugin'), $success_images, preg_replace('%.*/wp-content%', '/wp-content', $wp_uploads['basedir']) . DIRECTORY_SEPARATOR . PMXI_Plugin::FILES_DIRECTORY); } } else { $start = time(); if (!empty($post['imgs'])) { foreach ($post['imgs'] as $img) { if (!preg_match('%^(http|https|ftp|ftps)%i', $img)) { $failed_msgs[] = sprintf(__('URL `%s` is not valid.', 'wp_all_import_plugin'), $img); continue; } $image_name = wp_unique_filename($targetDir, 'test'); $image_filepath = $targetDir . '/' . $image_name; $url = str_replace(" ", "%20", trim($img)); $request = get_file_curl($url, $image_filepath); if ((is_wp_error($request) or $request === false) and !@file_put_contents($image_filepath, @file_get_contents($img))) { $failed_msgs[] = is_wp_error($request) ? $request->get_error_message() : sprintf(__('File `%s` cannot be saved locally', 'wp_all_import_plugin'), $img); } elseif (!($image_info = @getimagesize($image_filepath)) or !in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) { $failed_msgs[] = sprintf(__('File `%s` is not a valid image.', 'wp_all_import_plugin'), $img); } else { $success_images++; } @unlink($image_filepath); } } $time = time() - $start; if ((int) $success_images === 1) { $success_msg = sprintf(__('%d image was successfully downloaded in %s seconds', 'wp_all_import_plugin'), $success_images, number_format($time, 2)); } elseif ((int) $success_images > 1) { $success_msg = sprintf(__('%d images were successfully downloaded in %s seconds', 'wp_all_import_plugin'), $success_images, number_format($time, 2)); } } } exit(json_encode(array('success_images' => $success_images, 'success_msg' => $success_msg, 'failed_msgs' => $failed_msgs))); die; }
function pmxi_wp_ajax_test_images() { if (!check_ajax_referer('wp_all_import_secure', 'security', false)) { exit(json_encode(array('result' => array(), 'failed_msgs' => array(__('Security check', 'wp_all_import_plugin'))))); } if (!current_user_can(PMXI_Plugin::$capabilities)) { exit(json_encode(array('result' => array(), 'failed_msgs' => array(__('Security check', 'wp_all_import_plugin'))))); } $input = new PMXI_Input(); $post = $input->post(array('download' => 'yes', 'imgs' => array())); $result = array(); $wp_uploads = wp_upload_dir(); $imgs_basedir = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::FILES_DIRECTORY . DIRECTORY_SEPARATOR; $targetDir = $wp_uploads['path']; $success_images = 0; $success_msg = ''; $failed_msgs = array(); if (!@is_writable($targetDir)) { $failed_msgs[] = sprintf(__('Uploads folder `%s` is not writable.', 'wp_all_import_plugin'), $targetDir); } else { switch ($post['download']) { // Use images currently uploaded in wp-content/uploads/wpallimport/files/ case 'no': if (!empty($post['imgs'])) { foreach ($post['imgs'] as $img) { if (preg_match('%^(http|https|ftp|ftps)%i', $img)) { $failed_msgs[] = sprintf(__('Use image name instead of URL `%s`.', 'wp_all_import_plugin'), $img); continue; } if (@file_exists($imgs_basedir . $img)) { if (@is_readable($imgs_basedir . $img)) { $success_images++; } else { $failed_msgs[] = sprintf(__('File `%s` isn\'t readable', 'wp_all_import_plugin'), preg_replace('%.*/wp-content%', '/wp-content', $imgs_basedir . $img)); } } else { $failed_msgs[] = sprintf(__('File `%s` doesn\'t exist', 'wp_all_import_plugin'), preg_replace('%.*/wp-content%', '/wp-content', $imgs_basedir . $img)); } } } if ((int) $success_images === 1) { $success_msg = sprintf(__('%d image was successfully retrieved from `%s`', 'wp_all_import_plugin'), $success_images, preg_replace('%.*/wp-content%', '/wp-content', $wp_uploads['basedir']) . DIRECTORY_SEPARATOR . PMXI_Plugin::FILES_DIRECTORY); } elseif ((int) $success_images > 1) { $success_msg = sprintf(__('%d images were successfully retrieved from `%s`', 'wp_all_import_plugin'), $success_images, preg_replace('%.*/wp-content%', '/wp-content', $wp_uploads['basedir']) . DIRECTORY_SEPARATOR . PMXI_Plugin::FILES_DIRECTORY); } break; // Use images currently in Media Library // Use images currently in Media Library case 'gallery': if (!empty($post['imgs'])) { global $wpdb; foreach ($post['imgs'] as $img) { $bn = wp_all_import_sanitize_filename(basename($img)); $img_ext = pmxi_getExtensionFromStr($img); $default_extension = pmxi_getExtension($bn); $image_name = apply_filters("wp_all_import_image_filename", urldecode(sanitize_file_name($img_ext ? str_replace("." . $default_extension, "", $bn) : $bn)) . ("" != $img_ext ? '.' . $img_ext : '')); $attch = wp_all_import_get_image_from_gallery($image_name, $targetDir); if (!empty($attch)) { $success_images++; } else { $failed_msgs[] = sprintf(__('Image `%s` not found in media library.', 'wp_all_import_plugin'), $image_name); } } } if ((int) $success_images === 1) { $success_msg = sprintf(__('%d image was successfully founded in media gallery', 'wp_all_import_plugin'), $success_images); } elseif ((int) $success_images > 1) { $success_msg = sprintf(__('%d images were successfully founded in media gallery', 'wp_all_import_plugin'), $success_images); } break; // Download images hosted elsewhere // Download images hosted elsewhere default: $start = time(); if (!empty($post['imgs'])) { foreach ($post['imgs'] as $img) { if (!preg_match('%^(http|https|ftp|ftps)%i', $img)) { $failed_msgs[] = sprintf(__('URL `%s` is not valid.', 'wp_all_import_plugin'), $img); continue; } $image_name = wp_unique_filename($targetDir, 'test'); $image_filepath = $targetDir . '/' . $image_name; $url = trim($img); $request = get_file_curl($url, $image_filepath); $get_ctx = stream_context_create(array('http' => array('timeout' => 5))); if ((is_wp_error($request) or $request === false) and !@file_put_contents($image_filepath, @file_get_contents($img, false, $get_ctx))) { $failed_msgs[] = is_wp_error($request) ? $request->get_error_message() : sprintf(__('File `%s` cannot be saved locally', 'wp_all_import_plugin'), $img); } elseif (!($image_info = apply_filters('pmxi_getimagesize', @getimagesize($image_filepath), $image_filepath)) or !in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) { $failed_msgs[] = sprintf(__('File `%s` is not a valid image.', 'wp_all_import_plugin'), $img); } else { $success_images++; } @unlink($image_filepath); } } $time = time() - $start; if ((int) $success_images === 1) { $success_msg = sprintf(__('%d image was successfully downloaded in %s seconds', 'wp_all_import_plugin'), $success_images, number_format($time, 2)); } elseif ((int) $success_images > 1) { $success_msg = sprintf(__('%d images were successfully downloaded in %s seconds', 'wp_all_import_plugin'), $success_images, number_format($time, 2)); } break; } } exit(json_encode(array('success_images' => $success_images, 'success_msg' => $success_msg, 'failed_msgs' => $failed_msgs))); die; }