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)));
}
예제 #2
0
function pmxi_admin_head()
{
    ?>
	
	<style type="text/css">
		#toplevel_page_pmxi-admin-home ul li:last-child{
			display: none;
		}
	</style>
	<?php 
    $input = new PMXI_Input();
    $import_id = $input->get('id', false);
    $import_action = $input->get('action', false);
    if ($import_id) {
        ?>
		<script type="text/javascript">
			var import_id = '<?php 
        echo $import_id;
        ?>
';			
		</script>
		<?php 
    }
    ?>
		<script type="text/javascript">
			var import_action = '<?php 
    echo $import_action;
    ?>
';
		</script>
	<?php 
}
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_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 "&lt;?php" and "?&gt;"', '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_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));
}
예제 #6
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $this->input = new PMXI_Input();
     $this->input->addFilter('trim');
     $this->errors = new WP_Error();
     $this->init();
 }
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;
}
예제 #8
0
function pmxi_admin_notices()
{
    // notify user if history folder is not writable
    $uploads = wp_upload_dir();
    if (!@is_dir($uploads['basedir'] . '/wpallimport_history') or !@is_writable($uploads['basedir'] . '/wpallimport_history')) {
        ?>
		<div class="error"><p>
			<?php 
        printf(__('<b>%s Plugin</b>: History folder %s must be writable for the plugin to function properly. Please deactivate the plugin, set proper permissions to the folder and activate the plugin again.', 'pmxi_plugin'), PMXI_Plugin::getInstance()->getName(), $uploads['basedir'] . '/wpallimport_history');
        ?>
		</p></div>
		<?php 
    }
    // notify user
    if (!PMXI_Plugin::getInstance()->getOption('dismiss') and strpos($_SERVER['REQUEST_URI'], 'pmxi-admin') !== false) {
        ?>
		<div class="updated"><p>
			<?php 
        printf(__('Welcome to WP All Import. We hope you like it. Please send all support requests and feedback to <a href="mailto:support@soflyy.com">support@soflyy.com</a>.<br/><br/><a href="javascript:void(0);" id="dismiss">dismiss</a>', 'pmxi_plugin'));
        ?>
		</p></div>
		<?php 
    }
    if (class_exists('PMWI_Plugin') and (defined('PMWI_VERSION') and version_compare(PMWI_VERSION, '1.2.8') <= 0 and PMWI_EDITION == 'paid' or defined('PMWI_FREE_VERSION') and version_compare(PMWI_FREE_VERSION, '1.1.1') <= 0 and PMWI_EDITION == 'free')) {
        ?>
		<div class="error"><p>
			<?php 
        printf(__('<b>%s Plugin</b>: Please update your WP All Import WooCommerce add-on to the latest version</a>', 'pmwi_plugin'), PMWI_Plugin::getInstance()->getName());
        ?>
		</p></div>
		<?php 
        if (defined('PMWI_EDITION') and PMWI_EDITION == 'paid') {
            deactivate_plugins(PMWI_ROOT_DIR . '/plugin.php');
        } else {
            deactivate_plugins(PMWI_FREE_ROOT_DIR . '/plugin.php');
        }
    }
    $input = new PMXI_Input();
    $messages = $input->get('pmxi_nt', array());
    if ($messages) {
        is_array($messages) or $messages = array($messages);
        foreach ($messages as $type => $m) {
            in_array((string) $type, array('updated', 'error')) or $type = 'updated';
            ?>
			<div class="<?php 
            echo $type;
            ?>
"><p><?php 
            echo $m;
            ?>
</p></div>
			<?php 
        }
    }
}
예제 #9
0
function pmxi_admin_head()
{
    ?>
	
	<style type="text/css">
		#toplevel_page_pmxi-admin-home ul li:last-child{
			display: none;
		}
	</style>
	<?php 
    $input = new PMXI_Input();
    $get_params = $input->get(array('id' => false, 'action' => false));
    if ($get_params['id']) {
        ?>
		<script type="text/javascript">
			var import_id = '<?php 
        echo $get_params["id"];
        ?>
';			
		</script>
		<?php 
    }
    $wp_all_import_ajax_nonce = '';
    if (get_current_user_id() and current_user_can(PMXI_Plugin::$capabilities)) {
        $wp_all_import_ajax_nonce = wp_create_nonce("wp_all_import_secure");
    }
    ?>
	<script type="text/javascript">
		var ajaxurl = '<?php 
    echo admin_url("admin-ajax.php");
    ?>
';
		var import_action = '<?php 
    echo $get_params["action"];
    ?>
';			
		var wp_all_import_security = '<?php 
    echo $wp_all_import_ajax_nonce;
    ?>
';
	</script>
	<?php 
}
예제 #10
0
파일: upload.php 프로젝트: mynein/myne
 function __construct($file, $errors, $targetDir = false)
 {
     $this->file = $file;
     $this->errors = $errors;
     $uploads = wp_upload_dir();
     $input = new PMXI_Input();
     $import_id = $input->get('id');
     if (empty($import_id)) {
         $import_id = $input->get('import_id');
     }
     if (empty($import_id)) {
         $import_id = false;
     }
     if ($uploads['error']) {
         $this->uploadsPath = false;
     } else {
         $this->uploadsPath = !$targetDir ? wp_all_import_secure_file($uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::UPLOADS_DIRECTORY, $import_id, true) : $targetDir;
     }
 }
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)));
}
예제 #12
0
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)));
}
예제 #13
0
 /**
  * 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']);
 }
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 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));
}
예제 #16
0
 /**
  * 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);
 }
예제 #17
0
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));
}
예제 #18
0
파일: import.php 프로젝트: hikaram/wee
    /**
     * Import processing step (status console)
     */
    public function process($save_history = true)
    {
        $wp_uploads = wp_upload_dir();
        $import = $this->data['update_previous'];
        $history_log = new PMXI_History_Record();
        $input = new PMXI_Input();
        if (!empty(PMXI_Plugin::$session->history_id)) {
            $history_log->getById(PMXI_Plugin::$session->history_id);
        }
        $log_storage = (int) PMXI_Plugin::getInstance()->getOption('log_storage');
        if (!PMXI_Plugin::is_ajax()) {
            $import->set((empty(PMXI_Plugin::$session->source) ? array() : PMXI_Plugin::$session->source) + array('xpath' => PMXI_Plugin::$session->xpath, 'options' => PMXI_Plugin::$session->options, 'count' => PMXI_Plugin::$session->count, 'friendly_name' => PMXI_Plugin::$session->options['friendly_name'], 'feed_type' => PMXI_Plugin::$session->feed_type, 'parent_import_id' => $this->data['update_previous']->isEmpty() ? PMXI_Plugin::$session->parent_import_id : $this->data['update_previous']->parent_import_id, 'queue_chunk_number' => 0, 'triggered' => 0, 'processing' => 0, 'executing' => 1, 'iteration' => !empty($import->iteration) ? $import->iteration : 0))->save();
            if (PMXI_Plugin::$session->action != 'continue') {
                // store import info in database
                $import->set(array('imported' => 0, 'created' => 0, 'updated' => 0, 'skipped' => 0, 'deleted' => 0))->update();
            }
            // add history log
            $custom_type = get_post_type_object($import->options['custom_type']);
            // unlink previous logs
            $by = array();
            $by[] = array(array('import_id' => $import->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->set(array('import_id' => $import->id, 'date' => date('Y-m-d H:i:s'), 'type' => PMXI_Plugin::$session->action != 'continue' ? 'manual' : 'continue', 'summary' => sprintf(__("%d %ss created %d updated %d deleted %d skipped", "pmxi_plugin"), $import->created, $custom_type->labels->singular_name, $import->updated, $import->deleted, $import->skipped)))->save();
            PMXI_Plugin::$session->set('history_id', $history_log->id);
            foreach (get_taxonomies() as $tax) {
                delete_transient("pmxi_{$tax}_terms");
            }
            do_action('pmxi_before_xml_import', $import->id);
            PMXI_Plugin::$session->set('update_previous', $import->id);
            if (empty($import->options['encoding'])) {
                $currentOptions = $import->options;
                $currentOptions['encoding'] = 'UTF-8';
                $import->set(array('options' => $currentOptions))->update();
            }
            // unlink previous files
            $history = new PMXI_File_List();
            $history->setColumns('id', 'name', 'registered_on', 'path')->getBy(array('import_id' => $import->id), 'id DESC');
            if ($history->count()) {
                foreach ($history as $file) {
                    $history_file_path = wp_all_import_get_absolute_path($file['path']);
                    if (@file_exists($history_file_path) and $history_file_path != PMXI_Plugin::$session->filePath) {
                        if (in_array($import->type, array('upload'))) {
                            wp_all_import_remove_source($history_file_path, false);
                        } else {
                            wp_all_import_remove_source($history_file_path);
                        }
                    }
                    $history_file = new PMXI_File_Record();
                    $history_file->getBy('id', $file['id']);
                    if (!$history_file->isEmpty()) {
                        $history_file->delete();
                    }
                }
            }
            if ($save_history) {
                $history_file = new PMXI_File_Record();
                $history_file->set(array('name' => $import->name, 'import_id' => $import->id, 'path' => wp_all_import_get_relative_path(PMXI_Plugin::$session->filePath), 'registered_on' => date('Y-m-d H:i:s')))->save();
            }
            /*
            	Split file up into 1000 record chunks.			
            	This option will decrease the amount of slowdown experienced at the end of large imports. 
            	The slowdown is partially caused by the need for WP All Import to read deeper and deeper into the file on each successive iteration. 
            	Splitting the file into pieces means that, for example, instead of having to read 19000 records into a 20000 record file when importing the last 1000 records, 
            	WP All Import will just split it into 20 chunks, and then read the last chunk from the beginning.
            */
            if ("ajax" == $import->options['import_processing'] and $import->count > PMXI_Plugin::getInstance()->getOption('large_feed_limit') and $import->options['chuncking']) {
                $chunk_files = array();
                if (!empty(PMXI_Plugin::$session->local_paths)) {
                    $records_count = 0;
                    $chunk_records_count = 0;
                    $feed = "<?xml version=\"1.0\" encoding=\"" . $import->options['encoding'] . "\"?>" . "\n" . "<pmxi_records>";
                    foreach (PMXI_Plugin::$session->local_paths as $key => $path) {
                        $file = new PMXI_Chunk($path, array('element' => $import->root_element, 'encoding' => $import->options['encoding']));
                        // loop through the file until all lines are read
                        while ($xml = $file->read()) {
                            if (!empty($xml)) {
                                PMXI_Import_Record::preprocessXml($xml);
                                $chunk = "<?xml version=\"1.0\" encoding=\"" . $import->options['encoding'] . "\"?>" . "\n" . $xml;
                                $dom = new DOMDocument('1.0', $import->options['encoding']);
                                $old = libxml_use_internal_errors(true);
                                $dom->loadXML($chunk);
                                // 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($import->xpath) and $elements->length) {
                                    $records_count += $elements->length;
                                    $chunk_records_count += $elements->length;
                                    $feed .= $xml;
                                }
                            }
                            if ($chunk_records_count == PMXI_Plugin::getInstance()->getOption('large_feed_limit') or $records_count == $import->count) {
                                $feed .= "</pmxi_records>";
                                $chunk_file_path = wp_all_import_secure_file($wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::TEMP_DIRECTORY) . DIRECTORY_SEPARATOR . "pmxi_chunk_" . count($chunk_files) . "_" . basename($path);
                                file_put_contents($chunk_file_path, $feed);
                                $chunk_files[] = $chunk_file_path;
                                $chunk_records_count = 0;
                                $feed = "<?xml version=\"1.0\" encoding=\"" . $import->options['encoding'] . "\"?>" . "\n" . "<pmxi_records>";
                            }
                        }
                    }
                    PMXI_Plugin::$session->set('local_paths', $chunk_files);
                }
            }
            PMXI_Plugin::$session->save_data();
            if ($log_storage) {
                $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 (PMXI_Plugin::$session->action != 'continue') {
                    if (file_exists($log_file)) {
                        wp_all_import_remove_source($log_file, false);
                    }
                    //@file_put_contents($log_file, sprintf(__('<p>Source path `%s`</p>', 'wp_all_import_plugin'), $import->path));
                }
            }
            $this->data['ajax_processing'] = "ajax" == $import->options['import_processing'] ? true : false;
            $this->render();
            wp_ob_end_flush_all();
            flush();
            @set_time_limit(0);
            $import_id = $input->get('id', 0);
            if ("ajax" == $import->options['import_processing'] and !$import_id) {
                PMXI_Plugin::$session->convertData($import->id);
                //die();
            }
        } elseif (empty($import->id)) {
            $import = new PMXI_Import_Record();
            $import_id = $input->get('id', PMXI_Plugin::$session->update_previous);
            $import->getById($import_id);
        }
        $ajax_processing = "ajax" == $import->options['import_processing'] ? true : false;
        if (PMXI_Plugin::is_ajax() and $ajax_processing and !check_ajax_referer('wp_all_import_secure', 'security', false)) {
            exit(__('Security check', 'wp_all_import_plugin'));
        }
        if ($ajax_processing) {
            $logger = create_function('$m', 'echo "<div class=\\"progress-msg\\">$m</div>\\n"; flush();');
        } else {
            $logger = create_function('$m', 'echo "<div class=\\"progress-msg\\">$m</div>\\n"; if ( "" != strip_tags(wp_all_import_strip_tags_content($m))) { PMXI_Plugin::$session->log .= "<p>".strip_tags(wp_all_import_strip_tags_content($m))."</p>"; flush(); }');
        }
        PMXI_Plugin::$session->set('start_time', empty(PMXI_Plugin::$session->start_time) ? time() : PMXI_Plugin::$session->start_time);
        wp_cache_flush();
        if (PMXI_Plugin::is_ajax() or !$ajax_processing) {
            $iteration_start_time = time();
            if ($log_storage) {
                $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 ($ajax_processing) {
                // HTTP headers for no cache etc
                header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
                header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
                header("Cache-Control: no-store, no-cache, must-revalidate");
                header("Cache-Control: post-check=0, pre-check=0", false);
                header("Pragma: no-cache");
            }
            $loop = 0;
            $pointer = 0;
            $records = array();
            if ($import->options['is_import_specified']) {
                foreach (preg_split('% *, *%', $import->options['import_specified'], -1, PREG_SPLIT_NO_EMPTY) as $chank) {
                    if (preg_match('%^(\\d+)-(\\d+)$%', $chank, $mtch)) {
                        $records = array_merge($records, range(intval($mtch[1]), intval($mtch[2])));
                    } else {
                        $records = array_merge($records, array(intval($chank)));
                    }
                }
            }
            $records_to_import = empty($records) ? $import->count : $records[count($records) - 1];
            $failures = $input->get('failures', 0);
            // auto decrease records per iteration option
            if ($failures) {
                $options = $import->options;
                $options['records_per_request'] = ceil($options['records_per_request'] / 2) ? ceil($options['records_per_request'] / 2) : 1;
                $import->set(array('options' => $options))->update();
            }
            $records_per_request = (!$ajax_processing and $import->options['records_per_request'] < 50) ? 50 : $import->options['records_per_request'];
            if (!empty(PMXI_Plugin::$session->local_paths)) {
                $feed = "<?xml version=\"1.0\" encoding=\"" . $import->options['encoding'] . "\"?>" . "\n" . "<pmxi_records>";
                foreach (PMXI_Plugin::$session->local_paths as $key => $path) {
                    $import_done = $import->imported + $import->skipped == $records_to_import ? true : false;
                    if ($import_done) {
                        if (strpos($path, "pmxi_chunk_") !== false and @file_exists($path)) {
                            wp_all_import_remove_source($path, false);
                        }
                        PMXI_Plugin::$session->set('local_paths', array());
                        PMXI_Plugin::$session->save_data();
                        break;
                    }
                    $file = new PMXI_Chunk($path, array('element' => $import->root_element, 'encoding' => $import->options['encoding'], 'pointer' => PMXI_Plugin::$session->pointer, 'filter' => true));
                    // loop through the file until all lines are read
                    while ($xml = $file->read() and empty($import->canceled)) {
                        if (!empty($xml)) {
                            if (!$import->options['chuncking']) {
                                PMXI_Import_Record::preprocessXml($xml);
                            }
                            $chunk = "<?xml version=\"1.0\" encoding=\"" . $import->options['encoding'] . "\"?>" . "\n" . $xml;
                            $dom = new DOMDocument('1.0', $import->options['encoding']);
                            $old = libxml_use_internal_errors(true);
                            $dom->loadXML($chunk);
                            // FIX: libxml xpath doesn't handle default namespace properly, so remove it upon XML load
                            libxml_use_internal_errors($old);
                            $xpath = new DOMXPath($dom);
                            $pointer++;
                            if ($this->data['elements'] = $elements = @$xpath->query($import->xpath) and $elements->length) {
                                /* Merge nested XML/CSV files */
                                /*$nested_files = json_decode($import->options['nested_files'], true);
                                		if ( ! empty($nested_files) and is_array($nested_files)){										
                                			$merger = new PMXI_Nested($dom, $nested_files, $xml, $import->xpath, $elements);
                                			$merger->merge();
                                			$xml = $merger->get_xml();
                                			unset($merger);
                                		}	*/
                                // continue action
                                if ($import->imported + $import->skipped >= PMXI_Plugin::$session->chunk_number + $elements->length - 1) {
                                    PMXI_Plugin::$session->set('chunk_number', PMXI_Plugin::$session->chunk_number + $elements->length);
                                    PMXI_Plugin::$session->save_data();
                                    continue;
                                }
                                if (!$loop and $ajax_processing) {
                                    ob_start();
                                }
                                $feed .= $xml;
                                $loop += $elements->length;
                                $processed_records = $import->imported + $import->skipped;
                                if ($loop == $records_per_request or $processed_records + $loop == $records_to_import or $processed_records == $records_to_import) {
                                    $feed .= "</pmxi_records>";
                                    $import->process($feed, $logger, PMXI_Plugin::$session->chunk_number, false, '/pmxi_records', $loop);
                                    unset($dom, $xpath);
                                    if (!$ajax_processing) {
                                        $feed = "<?xml version=\"1.0\" encoding=\"" . $import->options['encoding'] . "\"?>" . "\n" . "<pmxi_records>";
                                        $loop = 0;
                                    } else {
                                        if (!$history_log->isEmpty()) {
                                            $custom_type = get_post_type_object($import->options['custom_type']);
                                            $history_log->set(array('time_run' => time() - strtotime($history_log->date), 'summary' => sprintf(__("%d %ss created %d updated %d deleted %d skipped", "pmxi_plugin"), $import->created, $custom_type->labels->singular_name, $import->updated, $import->deleted, $import->skipped)))->update();
                                        }
                                        unset($file);
                                        PMXI_Plugin::$session->set('pointer', PMXI_Plugin::$session->pointer + $pointer);
                                        PMXI_Plugin::$session->save_data();
                                        $log_data = ob_get_clean();
                                        if ($log_storage) {
                                            $log = @fopen($log_file, 'a+');
                                            @fwrite($log, $log_data);
                                            @fclose($log);
                                        }
                                        $iteration_execution_time = time() - $iteration_start_time;
                                        wp_send_json(array('imported' => $import->imported, 'created' => $import->created, 'updated' => $import->updated, 'percentage' => ceil($processed_records / $import->count * 100), 'warnings' => PMXI_Plugin::$session->warnings, 'errors' => PMXI_Plugin::$session->errors, 'log' => $log_data, 'done' => false, 'records_per_request' => $import->options['records_per_request']));
                                    }
                                }
                            }
                        }
                    }
                    // Move to the next file, set pointer to first element
                    if ($ajax_processing) {
                        if (strpos($path, "pmxi_chunk_") !== false and @file_exists($path)) {
                            @unlink($path);
                        }
                        PMXI_Plugin::$session->set('pointer', 1);
                        $pointer = 0;
                        $lp = PMXI_Plugin::$session->local_paths;
                        array_shift($lp);
                        PMXI_Plugin::$session->set('local_paths', $lp);
                        PMXI_Plugin::$session->save_data();
                    } else {
                        break;
                    }
                }
            }
        }
        if (PMXI_Plugin::is_ajax() and empty(PMXI_Plugin::$session->local_paths) or !$ajax_processing or !empty($import->canceled)) {
            if ("ajax" != $import->options['import_processing'] and $log_storage) {
                $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 (PMXI_Plugin::$session->action != 'continue') {
                    @file_put_contents($log_file, PMXI_Plugin::$session->log);
                } else {
                    $log = @fopen($log_file, 'a+');
                    @fwrite($log, PMXI_Plugin::$session->log);
                    @fclose($log);
                }
            }
            wp_cache_flush();
            foreach (get_taxonomies() as $tax) {
                delete_option("{$tax}_children");
                _get_term_hierarchy($tax);
            }
            $import->set(array('registered_on' => date('Y-m-d H:i:s'), 'executing' => 0))->update();
            // add history log
            $custom_type = get_post_type_object($import->options['custom_type']);
            $history_log->set(array('time_run' => time() - strtotime($history_log->date), 'summary' => sprintf(__("%d %ss created %d updated %d deleted %d skipped", "pmxi_plugin"), $import->created, $custom_type->labels->singular_name, $import->updated, $import->deleted, $import->skipped)))->update();
            // clear import session
            PMXI_Plugin::$session->clean_session($import->id);
            // clear session data (prevent from reimporting the same data on page refresh)
            // [indicate in header process is complete]
            $msg = !empty($import->canceled) ? addcslashes(__('Canceled', 'wp_all_import_plugin'), "\n\r") : addcslashes(__('Complete', 'wp_all_import_plugin'), "\n\r");
            if ($ajax_processing) {
                ob_start();
            }
            do_action('pmxi_after_xml_import', $import->id);
            $import->options['is_import_specified'] and $logger and call_user_func($logger, 'Done');
            echo <<<COMPLETE
<script type="text/javascript">
//<![CDATA[
(function(\$){\t
\t\$('#status').html('{$msg}');\t
\twindow.onbeforeunload = false;
})(jQuery);
//]]>
</script>
COMPLETE;
            // [/indicate in header process is complete]
            if ($ajax_processing) {
                wp_send_json(array('imported' => $import->imported, 'created' => $import->created, 'updated' => $import->updated, 'percentage' => 100, 'warnings' => PMXI_Plugin::$session->warnings, 'errors' => PMXI_Plugin::$session->errors, 'log' => ob_get_clean(), 'done' => true, 'records_per_request' => $import->options['records_per_request']));
            }
        }
    }
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;
}
예제 #20
0
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;
}
예제 #21
0
 /**
  * pre-dispatching logic for admin page controllers
  */
 public function __adminInit()
 {
     self::$session = new PMXI_Handler();
     $input = new PMXI_Input();
     $page = strtolower($input->getpost('page', ''));
     if (preg_match('%^' . preg_quote(str_replace('_', '-', self::PREFIX), '%') . '([\\w-]+)$%', $page)) {
         //$this->adminDispatcher($page, strtolower($input->getpost('action', 'index')));
         $action = strtolower($input->getpost('action', 'index'));
         // capitalize prefix and first letters of class name parts
         if (function_exists('preg_replace_callback')) {
             $controllerName = preg_replace_callback('%(^' . preg_quote(self::PREFIX, '%') . '|_).%', array($this, "replace_callback"), str_replace('-', '_', $page));
         } else {
             $controllerName = preg_replace('%(^' . preg_quote(self::PREFIX, '%') . '|_).%e', 'strtoupper("$0")', str_replace('-', '_', $page));
         }
         $actionName = str_replace('-', '_', $action);
         if (method_exists($controllerName, $actionName)) {
             $this->_admin_current_screen = (object) array('id' => $controllerName, 'base' => $controllerName, 'action' => $actionName, 'is_ajax' => strpos($_SERVER["HTTP_ACCEPT"], 'json') !== false, 'is_network' => is_network_admin(), 'is_user' => is_user_admin());
             add_filter('current_screen', array($this, 'getAdminCurrentScreen'));
             add_filter('admin_body_class', create_function('', 'return "' . 'wpallimport-plugin";'));
             $controller = new $controllerName();
             if (!$controller instanceof PMXI_Controller_Admin) {
                 throw new Exception("Administration page `{$page}` matches to a wrong controller type.");
             }
             if ($this->_admin_current_screen->is_ajax) {
                 // ajax request
                 $controller->{$action}();
                 do_action('pmxi_action_after');
                 die;
                 // stop processing since we want to output only what controller is randered, nothing in addition
             } elseif (!$controller->isInline) {
                 @ob_start();
                 $controller->{$action}();
                 self::$buffer = @ob_get_clean();
             } else {
                 self::$buffer_callback = array($controller, $action);
             }
         } else {
             // redirect to dashboard if requested page and/or action don't exist
             wp_redirect(admin_url());
             die;
         }
     }
 }
예제 #22
0
 public function generate_import_id()
 {
     $input = new PMXI_Input();
     $import_id = $input->get('id', 'new');
     return $import_id;
 }
예제 #23
0
 /**
  * pre-dispatching logic for admin page controllers
  */
 public function __adminInit()
 {
     $input = new PMXI_Input();
     $page = strtolower($input->getpost('page', ''));
     if (preg_match('%^' . preg_quote(str_replace('_', '-', self::PREFIX), '%') . '([\\w-]+)$%', $page)) {
         $this->adminDispatcher($page, strtolower($input->getpost('action', 'index')));
     }
 }
예제 #24
0
function pmxi_admin_notices()
{
    // notify user if history folder is not writable
    $uploads = wp_upload_dir();
    // compare woocommerce add-on version
    if (class_exists('PMWI_Plugin') and (defined('PMWI_VERSION') and version_compare(PMWI_VERSION, '2.1.4') < 0 and PMWI_EDITION == 'paid' or defined('PMWI_FREE_VERSION') and version_compare(PMWI_FREE_VERSION, '1.2.2') < 0 and PMWI_EDITION == 'free')) {
        ?>
		<div class="error"><p>
			<?php 
        printf(__('<b>%s Plugin</b>: Please update your WP All Import WooCommerce add-on to the latest version', 'pmwi_plugin'), PMWI_Plugin::getInstance()->getName());
        ?>
		</p></div>
		<?php 
        if (defined('PMWI_EDITION') and PMWI_EDITION == 'paid') {
            deactivate_plugins(PMWI_ROOT_DIR . '/wpai-woocommerce-add-on.php');
        } else {
            if (defined('PMWI_FREE_ROOT_DIR')) {
                deactivate_plugins(PMWI_FREE_ROOT_DIR . '/plugin.php');
            } else {
                deactivate_plugins(PMWI_ROOT_DIR . '/plugin.php');
            }
        }
    }
    // compare ACF add-on
    if (class_exists('PMAI_Plugin') and defined('PMAI_VERSION') and version_compare(PMAI_VERSION, '3.0.0-beta1') < 0 and PMAI_EDITION == 'paid') {
        ?>
		<div class="error"><p>
			<?php 
        printf(__('<b>%s Plugin</b>: Please update your WP All Import ACF add-on to the latest version', 'pmwi_plugin'), PMAI_Plugin::getInstance()->getName());
        ?>
		</p></div>
		<?php 
        if (defined('PMAI_EDITION') and PMAI_EDITION == 'paid') {
            deactivate_plugins(PMAI_ROOT_DIR . '/wpai-acf-add-on.php');
        }
    }
    // compare Linkcloak add-on
    if (class_exists('PMLCA_Plugin') and defined('PMLCA_VERSION') and version_compare(PMLCA_VERSION, '1.0.0-beta1') < 0 and PMLCA_EDITION == 'paid') {
        ?>
		<div class="error"><p>
			<?php 
        printf(__('<b>%s Plugin</b>: Please update your WP All Import Linkcloak add-on to the latest version', 'pmwi_plugin'), PMLCA_Plugin::getInstance()->getName());
        ?>
		</p></div>
		<?php 
        if (defined('PMLCA_EDITION') and PMLCA_EDITION == 'paid') {
            deactivate_plugins(PMLCA_ROOT_DIR . '/wpai-linkcloak-add-on.php');
        }
    }
    // compare User add-on
    if (class_exists('PMUI_Plugin') and defined('PMUI_VERSION') and version_compare(PMUI_VERSION, '1.0.0-beta1') < 0 and PMUI_EDITION == 'paid') {
        ?>
		<div class="error"><p>
			<?php 
        printf(__('<b>%s Plugin</b>: Please update your WP All Import User add-on to the latest version', 'pmwi_plugin'), PMUI_Plugin::getInstance()->getName());
        ?>
		</p></div>
		<?php 
        if (defined('PMUI_EDITION') and PMUI_EDITION == 'paid') {
            deactivate_plugins(PMUI_ROOT_DIR . '/wpai-user-add-on.php');
        }
    }
    // compare WPML add-on
    if (class_exists('PMLI_Plugin') and defined('PMLI_VERSION') and version_compare(PMLI_VERSION, '1.0.0-beta1') < 0 and PMLI_EDITION == 'paid') {
        ?>
		<div class="error"><p>
			<?php 
        printf(__('<b>%s Plugin</b>: Please update your WP All Import WPML add-on to the latest version', 'pmwi_plugin'), PMLI_Plugin::getInstance()->getName());
        ?>
		</p></div>
		<?php 
        if (defined('PMLI_EDITION') and PMLI_EDITION == 'paid') {
            deactivate_plugins(PMLI_ROOT_DIR . '/plugin.php');
        }
    }
    $input = new PMXI_Input();
    $messages = $input->get('pmxi_nt', array());
    if ($messages) {
        is_array($messages) or $messages = array($messages);
        foreach ($messages as $type => $m) {
            in_array((string) $type, array('updated', 'error')) or $type = 'updated';
            ?>
			<div class="<?php 
            echo $type;
            ?>
"><p><?php 
            echo $m;
            ?>
</p></div>
			<?php 
        }
    }
    $warnings = $input->get('warnings', array());
    if ($warnings) {
        is_array($warnings) or $warnings = explode(',', $warnings);
        foreach ($warnings as $code) {
            switch ($code) {
                case 1:
                    $m = __('<strong>Warning:</strong> your title is blank.', 'pmxi_plugin');
                    break;
                case 2:
                    $m = __('<strong>Warning:</strong> your content is blank.', 'pmxi_plugin');
                    break;
                case 3:
                    $m = __('<strong>Warning:</strong> You must <a href="http://www.wpallimport.com/upgrade-to-pro/?utm_source=free-plugin&utm_medium=in-plugin&utm_campaign=images" target="_blank">upgrade to the Pro edition of WP All Import</a> to import images. The settings you configured in the images section will be ignored.', 'pmxi_plugin');
                    break;
                case 4:
                    $m = __('<strong>Warning:</strong> You must <a href="http://www.wpallimport.com/upgrade-to-pro/?utm_source=free-plugin&utm_medium=in-plugin&utm_campaign=custom-fields" target="_blank">upgrade to the Pro edition of WP All Import</a> to import data to Custom Fields. The settings you configured in the Custom Fields section will be ignored.', 'pmxi_plugin');
                    break;
                default:
                    $m = false;
                    break;
            }
            if ($m) {
                ?>
			<div class="error"><p><?php 
                echo $m;
                ?>
</p></div>
			<?php 
            }
        }
    }
    wp_all_import_addon_notifications();
}
예제 #25
0
 /**
  * pre-dispatching logic for admin page controllers
  */
 public function __adminInit()
 {
     // create history folder
     $uploads = wp_upload_dir();
     $wpallimportDirs = array(WP_ALL_IMPORT_UPLOADS_BASE_DIRECTORY, self::LOGS_DIRECTORY, self::FILES_DIRECTORY, self::TEMP_DIRECTORY, self::UPLOADS_DIRECTORY, self::HISTORY_DIRECTORY);
     foreach ($wpallimportDirs as $destination) {
         $dir = $uploads['basedir'] . DIRECTORY_SEPARATOR . $destination;
         if (!is_dir($dir)) {
             wp_mkdir_p($dir);
         }
         if (!@file_exists($dir . DIRECTORY_SEPARATOR . 'index.php')) {
             @touch($dir . DIRECTORY_SEPARATOR . 'index.php');
         }
     }
     self::$session = new PMXI_Handler();
     $input = new PMXI_Input();
     $page = strtolower($input->getpost('page', ''));
     if (preg_match('%^' . preg_quote(str_replace('_', '-', self::PREFIX), '%') . '([\\w-]+)$%', $page)) {
         //$this->adminDispatcher($page, strtolower($input->getpost('action', 'index')));
         $action = strtolower($input->getpost('action', 'index'));
         // capitalize prefix and first letters of class name parts
         if (function_exists('preg_replace_callback')) {
             $controllerName = preg_replace_callback('%(^' . preg_quote(self::PREFIX, '%') . '|_).%', array($this, "replace_callback"), str_replace('-', '_', $page));
         } else {
             $controllerName = preg_replace('%(^' . preg_quote(self::PREFIX, '%') . '|_).%e', 'strtoupper("$0")', str_replace('-', '_', $page));
         }
         $actionName = str_replace('-', '_', $action);
         if (method_exists($controllerName, $actionName)) {
             @ini_set("max_input_time", PMXI_Plugin::getInstance()->getOption('max_input_time'));
             @ini_set("max_execution_time", PMXI_Plugin::getInstance()->getOption('max_execution_time'));
             if (!get_current_user_id() or !current_user_can('manage_options')) {
                 // This nonce is not valid.
                 die('Security check');
             } else {
                 $this->_admin_current_screen = (object) array('id' => $controllerName, 'base' => $controllerName, 'action' => $actionName, 'is_ajax' => strpos($_SERVER["HTTP_ACCEPT"], 'json') !== false, 'is_network' => is_network_admin(), 'is_user' => is_user_admin());
                 add_filter('current_screen', array($this, 'getAdminCurrentScreen'));
                 add_filter('admin_body_class', create_function('', 'return "' . 'wpallimport-plugin";'));
                 $controller = new $controllerName();
                 if (!$controller instanceof PMXI_Controller_Admin) {
                     throw new Exception("Administration page `{$page}` matches to a wrong controller type.");
                 }
                 if ($this->_admin_current_screen->is_ajax) {
                     // ajax request
                     $controller->{$action}();
                     do_action('pmxi_action_after');
                     die;
                     // stop processing since we want to output only what controller is randered, nothing in addition
                 } elseif (!$controller->isInline) {
                     @ob_start();
                     $controller->{$action}();
                     self::$buffer = @ob_get_clean();
                 } else {
                     self::$buffer_callback = array($controller, $action);
                 }
             }
         } else {
             // redirect to dashboard if requested page and/or action don't exist
             wp_redirect(admin_url());
             die;
         }
     }
 }
예제 #26
0
function pmxi_admin_notices()
{
    // notify user if history folder is not writable
    $uploads = wp_upload_dir();
    // compare woocommerce add-on version
    if (class_exists('PMWI_Plugin') and (defined('PMWI_VERSION') and version_compare(PMWI_VERSION, '2.1.3 RC5') < 0 and PMWI_EDITION == 'paid' or defined('PMWI_FREE_VERSION') and version_compare(PMWI_FREE_VERSION, '1.2.1') <= 0 and PMWI_EDITION == 'free')) {
        ?>
		<div class="error"><p>
			<?php 
        printf(__('<b>%s Plugin</b>: Please update your WP All Import WooCommerce add-on to the latest version', 'pmwi_plugin'), PMWI_Plugin::getInstance()->getName());
        ?>
		</p></div>
		<?php 
        if (defined('PMWI_EDITION') and PMWI_EDITION == 'paid') {
            deactivate_plugins(PMWI_ROOT_DIR . '/wpai-woocommerce-add-on.php');
        } else {
            if (defined('PMWI_FREE_ROOT_DIR')) {
                deactivate_plugins(PMWI_FREE_ROOT_DIR . '/plugin.php');
            } else {
                deactivate_plugins(PMWI_ROOT_DIR . '/plugin.php');
            }
        }
    }
    // compare ACF add-on
    if (class_exists('PMAI_Plugin') and defined('PMAI_VERSION') and version_compare(PMAI_VERSION, '3.0.0-beta1') < 0 and PMAI_EDITION == 'paid') {
        ?>
		<div class="error"><p>
			<?php 
        printf(__('<b>%s Plugin</b>: Please update your WP All Import ACF add-on to the latest version', 'pmwi_plugin'), PMAI_Plugin::getInstance()->getName());
        ?>
		</p></div>
		<?php 
        if (defined('PMAI_EDITION') and PMAI_EDITION == 'paid') {
            deactivate_plugins(PMAI_ROOT_DIR . '/wpai-acf-add-on.php');
        }
    }
    // compare Linkcloak add-on
    if (class_exists('PMLCA_Plugin') and defined('PMLCA_VERSION') and version_compare(PMLCA_VERSION, '1.0.0-beta1') < 0 and PMLCA_EDITION == 'paid') {
        ?>
		<div class="error"><p>
			<?php 
        printf(__('<b>%s Plugin</b>: Please update your WP All Import Linkcloak add-on to the latest version', 'pmwi_plugin'), PMLCA_Plugin::getInstance()->getName());
        ?>
		</p></div>
		<?php 
        if (defined('PMLCA_EDITION') and PMLCA_EDITION == 'paid') {
            deactivate_plugins(PMLCA_ROOT_DIR . '/wpai-linkcloak-add-on.php');
        }
    }
    // compare User add-on
    if (class_exists('PMUI_Plugin') and defined('PMUI_VERSION') and version_compare(PMUI_VERSION, '1.0.0-beta1') < 0 and PMUI_EDITION == 'paid') {
        ?>
		<div class="error"><p>
			<?php 
        printf(__('<b>%s Plugin</b>: Please update your WP All Import User add-on to the latest version', 'pmwi_plugin'), PMUI_Plugin::getInstance()->getName());
        ?>
		</p></div>
		<?php 
        if (defined('PMUI_EDITION') and PMUI_EDITION == 'paid') {
            deactivate_plugins(PMUI_ROOT_DIR . '/wpai-user-add-on.php');
        }
    }
    // compare WPML add-on
    if (class_exists('PMLI_Plugin') and defined('PMLI_VERSION') and version_compare(PMLI_VERSION, '1.0.0-beta1') < 0 and PMLI_EDITION == 'paid') {
        ?>
		<div class="error"><p>
			<?php 
        printf(__('<b>%s Plugin</b>: The WPML Add-On Plugin is no longer compatible with this version of WP All Import - please contact support@wpallimport.com and we will supply the latest version of WP All Import that is compatible with the WPML Add-On.', 'pmwi_plugin'), PMLI_Plugin::getInstance()->getName());
        ?>
		</p></div>
		<?php 
        if (defined('PMLI_EDITION') and PMLI_EDITION == 'paid') {
            deactivate_plugins(PMLI_ROOT_DIR . '/plugin.php');
        }
    }
    $input = new PMXI_Input();
    $messages = $input->get('pmxi_nt', array());
    if ($messages) {
        is_array($messages) or $messages = array($messages);
        foreach ($messages as $type => $m) {
            in_array((string) $type, array('updated', 'error')) or $type = 'updated';
            ?>
			<div class="<?php 
            echo $type;
            ?>
"><p><?php 
            echo $m;
            ?>
</p></div>
			<?php 
        }
    }
    $warnings = $input->get('warnings', array());
    if ($warnings) {
        is_array($warnings) or $warnings = explode(',', $warnings);
        foreach ($warnings as $code) {
            switch ($code) {
                case 1:
                    $m = __('<strong>Warning:</strong> your title is blank.', 'wp_all_import_plugin');
                    break;
                case 2:
                    $m = __('<strong>Warning:</strong> your content is blank.', 'wp_all_import_plugin');
                    break;
                default:
                    $m = false;
                    break;
            }
            if ($m) {
                ?>
			<div class="error"><p><?php 
                echo $m;
                ?>
</p></div>
			<?php 
            }
        }
    }
    wp_all_import_addon_notifications();
}
 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;
 }
예제 #28
0
 /**
  * __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'])) {
                 foreach ($this->cloud as $el => $count) {
                     $this->options['element'] = $el;
                     break;
                 }
             }
         }
     }
     $path = $this->get_file_path();
     if ($this->parser_type == 'xmlreader') {
         $this->reader = new XMLReader();
         @$this->reader->open($path);
         @$this->reader->setParserProperty(XMLReader::VALIDATE, false);
     } else {
         $parseroptions = array("uniqueNode" => $this->options['element']);
         $CHUNK_SIZE = 1024;
         $streamProvider = new Prewk\XmlStringStreamer\Stream\File($path, $CHUNK_SIZE);
         $parser = new Parser\UniqueNode($parseroptions);
         $this->reader = new XmlStringStreamer($parser, $streamProvider);
     }
 }