function pmxe_wp_ajax_dismiss_export_warnings()
{
    if (!check_ajax_referer('wp_all_export_secure', 'security', false)) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
    }
    if (!current_user_can(PMXE_Plugin::$capabilities)) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
    }
    $input = new PMXE_Input();
    $post = $input->post('data', false);
    if (!empty($post) && !empty($post['export_id'])) {
        $option_name = 'wpae_dismiss_warnings_' . $post['export_id'];
        update_option($option_name, 1);
    }
    exit(json_encode(array('result' => true)));
}
function pmxe_wp_ajax_export_filtering_count()
{
    if (!check_ajax_referer('wp_all_export_secure', 'security', false)) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
    }
    if (!current_user_can('manage_options')) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
    }
    ob_start();
    $input = new PMXE_Input();
    $post = $input->post('data', array());
    $filter_args = array('filter_rules_hierarhy' => $post['filter_rules_hierarhy'], 'product_matching_mode' => $post['product_matching_mode']);
    $input = new PMXE_Input();
    $export_id = $input->get('id', 0);
    if (empty($export_id)) {
        $export_id = !empty(PMXE_Plugin::$session->update_previous) ? PMXE_Plugin::$session->update_previous : 0;
    }
    $export = new PMXE_Export_Record();
    $export->getById($export_id);
    if (!$export->isEmpty()) {
        XmlExportEngine::$exportOptions = $export->options + PMXE_Plugin::get_default_import_options();
        XmlExportEngine::$exportOptions['export_only_new_stuff'] = $post['export_only_new_stuff'];
    }
    XmlExportEngine::$is_user_export = 'users' == $post['cpt'] ? true : false;
    XmlExportEngine::$post_types = array($post['cpt']);
    $filters = new XmlExportFiltering($filter_args);
    $filters->parseQuery();
    PMXE_Plugin::$session->set('whereclause', $filters->get('queryWhere'));
    PMXE_Plugin::$session->set('joinclause', $filters->get('queryJoin'));
    PMXE_Plugin::$session->save_data();
    $found_records = 0;
    if ('users' == $post['cpt']) {
        add_action('pre_user_query', 'wp_all_export_pre_user_query', 10, 1);
        $exportQuery = new WP_User_Query(array('orderby' => 'ID', 'order' => 'ASC', 'number' => 10));
        if (!empty($exportQuery->results)) {
            $found_records = $exportQuery->get_total();
        }
        remove_action('pre_user_query', 'wp_all_export_pre_user_query');
    } else {
        add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
        add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
        $cpt = $post['cpt'] == 'product' ? array('product', 'product_variation') : $post['cpt'];
        $exportQuery = new WP_Query(array('post_type' => $cpt, 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => 10));
        if (!empty($exportQuery->found_posts)) {
            $found_records = $exportQuery->found_posts;
        }
        remove_filter('posts_join', 'wp_all_export_posts_join');
        remove_filter('posts_where', 'wp_all_export_posts_where');
    }
    if ($post['is_confirm_screen']) {
        ?>
				
		<?php 
        if ($found_records > 0) {
            ?>
			<h3><?php 
            _e('Your export is ready to run.', 'wp_all_export_plugin');
            ?>
</h3>							
			<h4><?php 
            printf(__('WP All Export will export %d %s.', 'wp_all_export_plugin'), $found_records, wp_all_export_get_cpt_name(array($post['cpt']), $found_records));
            ?>
</h4>
		<?php 
        } else {
            ?>
			<?php 
            if (!$export->isEmpty() and $export->options['export_only_new_stuff']) {
                ?>
			<h3><?php 
                _e('Nothing to export.', 'wp_all_export_plugin');
                ?>
</h3>
			<h4><?php 
                printf(__("All %s have already been exported.", "wp_all_export_plugin"), wp_all_export_get_cpt_name(array($post['cpt'])));
                ?>
</h4>			
			<?php 
            } else {
                ?>
			<h3><?php 
                _e('Nothing to export.', 'wp_all_export_plugin');
                ?>
</h3>
			<h4><?php 
                printf(__("No matching %s found for selected filter rules.", "wp_all_export_plugin"), wp_all_export_get_cpt_name(array($post['cpt'])));
                ?>
</h4>
			<?php 
            }
            ?>
		<?php 
        }
        ?>

		<?php 
    } else {
        ?>
		<div class="founded_records">			
			<?php 
        if ($found_records > 0) {
            ?>
			<h3><span class="matches_count"><?php 
            echo $found_records;
            ?>
</span> <strong><?php 
            echo wp_all_export_get_cpt_name(array($post['cpt']), $found_records);
            ?>
</strong> will be exported</h3>
			<h4><?php 
            _e("Continue to Step 2 to choose data to include in the export file.", "wp_all_export_plugin");
            ?>
</h4>		
			<?php 
        } else {
            ?>
			<h4 style="line-height:60px;"><?php 
            printf(__("No matching %s found for selected filter rules.", "wp_all_export_plugin"), wp_all_export_get_cpt_name(array($post['cpt'])));
            ?>
</h4>
			<?php 
        }
        ?>
		</div>
		<?php 
    }
    exit(json_encode(array('html' => ob_get_clean(), 'found_records' => $found_records)));
    die;
}
function pmxe_wp_ajax_export_filtering()
{
    if (!check_ajax_referer('wp_all_export_secure', 'security', false)) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
    }
    if (!current_user_can(PMXE_Plugin::$capabilities)) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
    }
    $response = array('html' => '', 'btns' => '');
    ob_start();
    $errors = new WP_Error();
    $input = new PMXE_Input();
    $post = $input->post('data', array());
    if (!empty($post['cpt'])) {
        $engine = new XmlExportEngine($post, $errors);
        $engine->init_available_data();
        ?>
		<div class="wpallexport-content-section">
			<div class="wpallexport-collapsed-header">
				<h3><?php 
        _e('Add Filtering Options', 'wp_all_export_plugin');
        ?>
</h3>	
			</div>		
			<div class="wpallexport-collapsed-content">			
				<?php 
        include_once PMXE_ROOT_DIR . '/views/admin/export/blocks/filters.php';
        ?>
			</div>	
		</div>

	<?php 
    }
    $response['html'] = ob_get_clean();
    if (XmlExportEngine::$is_user_export || XmlExportEngine::$is_comment_export) {
        $response['btns'] = '';
        exit(json_encode($response));
        die;
    }
    ob_start();
    if (XmlExportEngine::$is_auto_generate_enabled) {
        ?>
	<span class="wp_all_export_btn_with_note">
		<a href="javascript:void(0);" class="back rad3 auto-generate-template" style="float:none; background: #425f9a; padding: 0 50px; margin-right: 10px; color: #fff; font-weight: normal;"><?php 
        printf(__('Migrate %s', 'wp_all_export_plugin'), wp_all_export_get_cpt_name(array($post['cpt']), 2));
        ?>
</a>											
		<span class="auto-generate-template">&nbsp;</span>
	</span>
	<span class="wp_all_export_btn_with_note">
		<input type="submit" class="button button-primary button-hero wpallexport-large-button" value="<?php 
        _e('Customize Export File', 'wp_all_export_plugin');
        ?>
"/>
		<span class="auto-generate-template">&nbsp;</span>
	</span>
	<?php 
    } else {
        ?>
	
	<span class="wp_all_export_btn_with_note">
		<input type="submit" class="button button-primary button-hero wpallexport-large-button" value="<?php 
        _e('Customize Export File', 'wp_all_export_plugin');
        ?>
"/>		
	</span>
	<?php 
    }
    $response['btns'] = ob_get_clean();
    exit(json_encode($response));
    die;
}
Exemplo n.º 4
0
function pmxe_wp_ajax_export_filtering()
{
    if (!check_ajax_referer('wp_all_export_secure', 'security', false)) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
    }
    if (!current_user_can('manage_options')) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
    }
    ob_start();
    $errors = new WP_Error();
    $input = new PMXE_Input();
    $post = $input->post('data', array());
    if (!empty($post['cpt'])) {
        $engine = new XmlExportEngine($post, $errors);
        $engine->init_available_data();
        ?>
		<div class="wpallexport-content-section">
			<div class="wpallexport-collapsed-header">
				<h3><?php 
        _e('Add Filtering Options', 'wp_all_export_plugin');
        ?>
</h3>	
			</div>		
			<div class="wpallexport-collapsed-content">			
				<div class="wp_all_export_rule_inputs">
					<table>
						<tr>
							<th><?php 
        _e('Element', 'wp_all_export_plugin');
        ?>
</th>
							<th><?php 
        _e('Rule', 'wp_all_export_plugin');
        ?>
</th>
							<th><?php 
        _e('Value', 'wp_all_export_plugin');
        ?>
</th>
							<th>&nbsp;</th>
						</tr>
						<tr>
							<td style="width: 25%;">
								<select id="wp_all_export_xml_element">
									<option value=""><?php 
        _e('Select Element', 'wp_all_export_plugin');
        ?>
</option>																
									<?php 
        echo $engine->render_filters();
        ?>
						
								</select>
							</td>
							<td style="width: 25%;" id="wp_all_export_available_rules">
								<select id="wp_all_export_rule">
									<option value=""><?php 
        _e('Select Rule', 'wp_all_export_plugin');
        ?>
</option>							
								</select>
							</td>
							<td style="width: 25%;">
								<input id="wp_all_export_value" type="text" placeholder="value" value=""/>
							</td>
							<td style="width: 15%;">
								<a id="wp_all_export_add_rule" href="javascript:void(0);"><?php 
        _e('Add Rule', 'wp_all_export_plugin');
        ?>
</a>
							</td>
						</tr>
					</table>						
				</div>	
				<div id="wpallexport-filters" style="padding:0;">								
					<div class="wpallexport-content-section" style="padding:0; border: none;">					
						<fieldset id="wp_all_export_filtering_rules">					
							<?php 
        $filter_rules = PMXE_Plugin::$session->get('filter_rules_hierarhy');
        $filter_rules_hierarhy = json_decode($filter_rules);
        ?>
							<p style="margin:20px 0 5px; text-align:center; <?php 
        if (!empty($filter_rules_hierarhy)) {
            ?>
 display:none;<?php 
        }
        ?>
"><?php 
        _e('No filtering options. Add filtering options to only export records matching some specified criteria.', 'wp_all_export_plugin');
        ?>
</p>					
							<ol class="wp_all_export_filtering_rules">
								<?php 
        if (!empty($filter_rules_hierarhy) and is_array($filter_rules_hierarhy)) {
            $rulenumber = 0;
            foreach ($filter_rules_hierarhy as $rule) {
                if (is_null($rule->parent_id)) {
                    $rulenumber++;
                    ?>
												<li id="item_<?php 
                    echo $rulenumber;
                    ?>
" class="dragging">
													<div class="drag-element">
			    										<input type="hidden" value="<?php 
                    echo $rule->element;
                    ?>
" class="wp_all_export_xml_element" name="wp_all_export_xml_element[<?php 
                    echo $rulenumber;
                    ?>
]"/>
			    										<input type="hidden" value="<?php 
                    echo $rule->title;
                    ?>
" class="wp_all_export_xml_element_title" name="wp_all_export_xml_element_title[<?php 
                    echo $rulenumber;
                    ?>
]"/>
											    		<input type="hidden" value="<?php 
                    echo $rule->condition;
                    ?>
" class="wp_all_export_rule" name="wp_all_export_rule[<?php 
                    echo $rulenumber;
                    ?>
]"/>
			    										<input type="hidden" value="<?php 
                    echo $rule->value;
                    ?>
" class="wp_all_export_value" name="wp_all_export_value[<?php 
                    echo $rulenumber;
                    ?>
]"/>
			    										<span class="rule_element"><?php 
                    echo $rule->title;
                    ?>
</span> 
			    										<span class="rule_as_is"><?php 
                    echo $rule->condition;
                    ?>
</span> 
			    										<span class="rule_condition_value"><?php 
                    echo $rule->value;
                    ?>
</span>	    										
			    										<span class="condition" <?php 
                    if ($rulenumber == count($filter_rules_hierarhy)) {
                        ?>
style="display:none;"<?php 
                    }
                    ?>
> 
			    											<label for="rule_and_<?php 
                    echo $rulenumber;
                    ?>
">AND</label>
			    											<input id="rule_and_<?php 
                    echo $rulenumber;
                    ?>
" type="radio" value="and" name="rule[<?php 
                    echo $rulenumber;
                    ?>
]" <?php 
                    if ($rule->clause == 'AND') {
                        ?>
checked="checked"<?php 
                    }
                    ?>
 class="rule_condition"/>
			    											<label for="rule_or_<?php 
                    echo $rulenumber;
                    ?>
">OR</label>
			    											<input id="rule_or_<?php 
                    echo $rulenumber;
                    ?>
" type="radio" value="or" name="rule[<?php 
                    echo $rulenumber;
                    ?>
]" <?php 
                    if ($rule->clause == 'OR') {
                        ?>
checked="checked"<?php 
                    }
                    ?>
 class="rule_condition"/> 
			    										</span>
			    									</div>
			    									<a href="javascript:void(0);" class="icon-item remove-ico"></a>
			    									<?php 
                    echo wp_all_export_reverse_rules_html($filter_rules_hierarhy, $rule, $rulenumber);
                    ?>
			    								</li>
			    								<?php 
                }
            }
        }
        ?>
							</ol>	
							<div class="clear"></div>								
							<div class="ajax-console" id="filtering_result">

							</div>
							<!--a href="javascript:void(0);" id="wp_all_export_apply_filters" <?php 
        if (empty($filter_rules_hierarhy)) {
            ?>
style="display:none;"<?php 
        }
        ?>
><?php 
        _e('Apply Filters To Export Data', 'wp_all_export_plugin');
        ?>
</a-->
							<div class="wp_all_export_filter_preloader"></div>			
						</fieldset>						

						<?php 
        if ("product" == $post["cpt"] and class_exists('WooCommerce')) {
            ?>

						<div class="input wp_all_export_product_matching_mode" <?php 
            if (empty($filter_rules_hierarhy)) {
                ?>
style="display:none;"<?php 
            }
            ?>
>
							<?php 
            $product_matching_mode = PMXE_Plugin::$session->get('product_matching_mode');
            ?>
							<label><?php 
            _e("Variable product matching rules: ", "wp_all_export_plugin");
            ?>
</label>
							<select name="product_matching_mode">
								<option value="strict" <?php 
            echo $product_matching_mode == 'strict' ? 'selected="selected"' : '';
            ?>
><?php 
            _e("Strict", "wp_all_export_plugin");
            ?>
</option>
								<option value="permissive" <?php 
            echo $product_matching_mode == 'permissive' ? 'selected="selected"' : '';
            ?>
><?php 
            _e("Permissive", "wp_all_export_plugin");
            ?>
</option>
							</select>
							<a href="#help" class="wpallexport-help" style="position: relative; top: 0px;" title="<?php 
            _e('Strict matching requires all variations to pass in order for the product to be exported. Permissive matching allows the product to be exported if any of the variations pass.', 'wp_all_export_plugin');
            ?>
">?</a>							
						</div>

						<?php 
        }
        ?>

							

					</div>	
				</div>
			</div>	
		</div>

	<?php 
    }
    exit(json_encode(array('html' => ob_get_clean())));
    die;
}
function pmxe_wp_ajax_export_filtering_count()
{
    if (!check_ajax_referer('wp_all_export_secure', 'security', false)) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
    }
    if (!current_user_can(PMXE_Plugin::$capabilities)) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
    }
    ob_start();
    $input = new PMXE_Input();
    $post = $input->post('data', array());
    $filter_args = array('filter_rules_hierarhy' => empty($post['filter_rules_hierarhy']) ? array() : $post['filter_rules_hierarhy'], 'product_matching_mode' => empty($post['product_matching_mode']) ? 'strict' : $post['product_matching_mode']);
    $input = new PMXE_Input();
    $export_id = $input->get('id', 0);
    if (empty($export_id)) {
        $export_id = !empty(PMXE_Plugin::$session->update_previous) ? PMXE_Plugin::$session->update_previous : 0;
    }
    $export = new PMXE_Export_Record();
    $export->getById($export_id);
    if (!$export->isEmpty()) {
        XmlExportEngine::$exportOptions = $export->options + PMXE_Plugin::get_default_import_options();
        XmlExportEngine::$exportOptions['export_only_new_stuff'] = $post['export_only_new_stuff'];
    }
    XmlExportEngine::$is_user_export = ('users' == $post['cpt'] or 'shop_customer' == $post['cpt']) ? true : false;
    XmlExportEngine::$is_comment_export = 'comments' == $post['cpt'] ? true : false;
    XmlExportEngine::$post_types = array($post['cpt']);
    $filters = new XmlExportFiltering($filter_args);
    $filters->parseQuery();
    PMXE_Plugin::$session->set('whereclause', $filters->get('queryWhere'));
    PMXE_Plugin::$session->set('joinclause', $filters->get('queryJoin'));
    PMXE_Plugin::$session->save_data();
    $found_records = 0;
    $total_records = 0;
    $cpt = array($post['cpt']);
    $is_products_export = ($post['cpt'] == 'product' and class_exists('WooCommerce'));
    if ($post['export_type'] == 'advanced') {
        if (XmlExportEngine::$is_user_export) {
            // get total users
            $totalQuery = eval('return new WP_User_Query(array(' . PMXE_Plugin::$session->get('wp_query') . ', \'offset\' => 0, \'number\' => 10 ));');
            if (!empty($totalQuery->results)) {
                $found_records = $total_records = $totalQuery->get_total();
            }
        } elseif (XmlExportEngine::$is_comment_export) {
            // get total comments
            $totalQuery = eval('return new WP_Comment_Query(array(' . PMXE_Plugin::$session->get('wp_query') . ', \'number\' => 10, \'count\' => true ));');
            $found_records = $total_records = $totalQuery->get_comments();
        } else {
            remove_all_actions('parse_query');
            remove_all_actions('pre_get_posts');
            ob_start();
            // get custom post type records depends on filters
            add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
            add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
            // get total custom post type records
            $totalQuery = eval('return new WP_Query(array(' . PMXE_Plugin::$session->get('wp_query') . ', \'offset\' => 0, \'posts_per_page\' => 10 ));');
            if (!empty($totalQuery->found_posts)) {
                $found_records = $total_records = $totalQuery->found_posts;
            }
            wp_reset_postdata();
            remove_filter('posts_join', 'wp_all_export_posts_join');
            remove_filter('posts_where', 'wp_all_export_posts_where');
            ob_get_clean();
        }
    } else {
        if ('users' == $post['cpt'] or 'shop_customer' == $post['cpt']) {
            // get total users
            $totalQuery = new WP_User_Query(array('orderby' => 'ID', 'order' => 'ASC', 'number' => 10));
            if (!empty($totalQuery->results)) {
                $found_records = $total_records = $totalQuery->get_total();
            }
        } elseif ('comments' == $post['cpt']) {
            // get total comments
            global $wp_version;
            if (version_compare($wp_version, '4.2.0', '>=')) {
                $totalQuery = new WP_Comment_Query(array('orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10, 'count' => true));
                $found_records = $total_records = $totalQuery->get_comments();
            } else {
                $found_records = $total_records = get_comments(array('orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10, 'count' => true));
            }
        } else {
            remove_all_actions('parse_query');
            remove_all_actions('pre_get_posts');
            $cpt = $is_products_export ? array('product', 'product_variation') : array($post['cpt']);
            ob_start();
            // get custom post type records depends on filters
            add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
            add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
            // get total custom post type records
            $totalQuery = new WP_Query(array('post_type' => $cpt, 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => 10));
            if (!empty($totalQuery->found_posts)) {
                $found_records = $total_records = $totalQuery->found_posts;
            }
            wp_reset_postdata();
            remove_filter('posts_join', 'wp_all_export_posts_join');
            remove_filter('posts_where', 'wp_all_export_posts_where');
            ob_end_clean();
        }
    }
    if ($post['is_confirm_screen']) {
        ?>
				
		<?php 
        if ($found_records > 0) {
            ?>
			<h3><?php 
            _e('Your export is ready to run.', 'wp_all_export_plugin');
            ?>
</h3>										
			<h4><?php 
            printf(__('WP All Export will export %d %s.', 'wp_all_export_plugin'), $found_records, wp_all_export_get_cpt_name($cpt, $found_records));
            ?>
</h4>
		<?php 
        } else {
            ?>
			<?php 
            if (!$export->isEmpty() and $export->options['export_only_new_stuff']) {
                ?>
				<h3><?php 
                _e('Nothing to export.', 'wp_all_export_plugin');
                ?>
</h3>
				<h4><?php 
                printf(__("All %s have already been exported.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt));
                ?>
</h4>			
			<?php 
            } elseif ($total_records > 0) {
                ?>
				<h3><?php 
                _e('Nothing to export.', 'wp_all_export_plugin');
                ?>
</h3>
				<h4><?php 
                printf(__("No matching %s found for selected filter rules.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt));
                ?>
</h4>
			<?php 
            } else {
                ?>
				<h3><?php 
                _e('Nothing to export.', 'wp_all_export_plugin');
                ?>
</h3>
				<h4><?php 
                printf(__("There aren't any %s to export.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt));
                ?>
</h4>
			<?php 
            }
            ?>
		<?php 
        }
        ?>

		<?php 
    } elseif ($post['is_template_screen']) {
        ?>
				
		<?php 
        if ($found_records > 0) {
            ?>
			<h3><span class="matches_count"><?php 
            echo $found_records;
            ?>
</span> <strong><?php 
            echo wp_all_export_get_cpt_name($cpt, $found_records);
            ?>
</strong> will be exported</h3>
			<h4><?php 
            _e("Choose data to include in the export file.", "wp_all_export_plugin");
            ?>
</h4>
		<?php 
        } else {
            ?>
			<?php 
            if (!$export->isEmpty() and $export->options['export_only_new_stuff']) {
                ?>
				<h3><?php 
                _e('Nothing to export.', 'wp_all_export_plugin');
                ?>
</h3>
				<h4><?php 
                printf(__("All %s have already been exported.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt));
                ?>
</h4>			
			<?php 
            } elseif ($total_records > 0) {
                ?>
				<h3><?php 
                _e('Nothing to export.', 'wp_all_export_plugin');
                ?>
</h3>
				<h4><?php 
                printf(__("No matching %s found for selected filter rules.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt));
                ?>
</h4>
			<?php 
            } else {
                ?>
				<h3><?php 
                _e('Nothing to export.', 'wp_all_export_plugin');
                ?>
</h3>
				<h4><?php 
                printf(__("There aren't any %s to export.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt));
                ?>
</h4>
			<?php 
            }
            ?>
		<?php 
        }
        ?>

		<?php 
    } else {
        ?>
		<div class="founded_records">			
			<?php 
        if ($found_records > 0) {
            ?>
				
				<?php 
            if (XmlExportEngine::$is_user_export || XmlExportEngine::$is_comment_export) {
                ?>
				<h3><span class="matches_count"><?php 
                echo $found_records;
                ?>
</span> <strong><?php 
                echo wp_all_export_get_cpt_name($cpt, $found_records);
                ?>
</strong> can be exported</h3>
				<h4><?php 
                printf(__('Upgrade to the professional edition of WP All Export to export %s.', 'wp_all_export_plugin'), wp_all_export_get_cpt_name($cpt));
                ?>
</h4>
				<?php 
            } else {
                ?>
				<h3><span class="matches_count"><?php 
                echo $found_records;
                ?>
</span> <strong><?php 
                echo wp_all_export_get_cpt_name($cpt, $found_records);
                ?>
</strong> will be exported</h3>
				<h4><?php 
                _e("Continue to configure and run your export.", "wp_all_export_plugin");
                ?>
</h4>
				<?php 
            }
            ?>
			<?php 
        } elseif ($total_records > 0) {
            ?>
				<h4 style="line-height:60px;"><?php 
            printf(__("No matching %s found for selected filter rules.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt));
            ?>
</h4>
			<?php 
        } else {
            ?>
				<h4 style="line-height:60px;"><?php 
            printf(__("There aren't any %s to export.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt));
            ?>
</h4>
			<?php 
        }
        ?>
		</div>
		<?php 
    }
    exit(json_encode(array('html' => ob_get_clean(), 'found_records' => $found_records)));
    die;
}
function pmxe_wp_ajax_wpae_available_rules()
{
    if (!check_ajax_referer('wp_all_export_secure', 'security', false)) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
    }
    if (!current_user_can(PMXE_Plugin::$capabilities)) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
    }
    ob_start();
    $input = new PMXE_Input();
    $post = $input->post('data', array());
    ?>
	<select id="wp_all_export_rule">
		<option value=""><?php 
    _e('Select Rule', 'wp_all_export_plugin');
    ?>
</option>
		<?php 
    if (strpos($post['selected'], 'tx_') === 0) {
        ?>
										

				<!-- Taxonomies -->
				<option value="in"><?php 
        echo __('In', 'wp_all_export_plugin') . ' ' . ucwords(str_replace(array("tx_", "_"), array("", " "), $post['selected']));
        ?>
</option>
				<option value="not_in"><?php 
        echo __('Not In', 'wp_all_export_plugin') . ' ' . ucwords(str_replace(array("tx_", "_"), array("", " "), $post['selected']));
        ?>
</option>

				<!-- Custom Fields -->
				<!--option value="between">BETWEEN</option-->
			
			<?php 
    } elseif (in_array($post['selected'], array('post_date', 'user_registered', 'comment_date'))) {
        ?>
			<option value="equals"><?php 
        _e('equals', 'wp_all_export_plugin');
        ?>
</option>
			<option value="not_equals"><?php 
        _e("doesn't equal", 'wp_all_export_plugin');
        ?>
</option>
			<option value="greater"><?php 
        _e('newer than', 'wp_all_export_plugin');
        ?>
</option>
			<option value="equals_or_greater"><?php 
        _e('equal to or newer than', 'wp_all_export_plugin');
        ?>
</option>
			<option value="less"><?php 
        _e('older than', 'wp_all_export_plugin');
        ?>
</option>
			<option value="equals_or_less"><?php 
        _e('equal to or older than', 'wp_all_export_plugin');
        ?>
</option>

			<option value="contains"><?php 
        _e('contains', 'wp_all_export_plugin');
        ?>
</option>
			<option value="not_contains"><?php 
        _e("doesn't contain", 'wp_all_export_plugin');
        ?>
</option>
			<option value="is_empty"><?php 
        _e('is empty', 'wp_all_export_plugin');
        ?>
</option>
			<option value="is_not_empty"><?php 
        _e('is not empty', 'wp_all_export_plugin');
        ?>
</option>
			<?php 
    } elseif (in_array($post['selected'], array('wp_capabilities'))) {
        ?>
			<option value="contains"><?php 
        _e('contains', 'wp_all_export_plugin');
        ?>
</option>
			<option value="not_contains"><?php 
        _e("doesn't contain", 'wp_all_export_plugin');
        ?>
</option>
			<?php 
    } elseif (in_array($post['selected'], array('user_login', 'user_nicename', 'user_role', 'user_email', 'display_name', 'first_name', 'last_name', 'nickname', 'description', 'post_status', 'post_title', 'post_content', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_agent', 'comment_type', 'comment_content'))) {
        ?>
			<option value="equals"><?php 
        _e('equals', 'wp_all_export_plugin');
        ?>
</option>
			<option value="not_equals"><?php 
        _e("doesn't equal", 'wp_all_export_plugin');
        ?>
</option>
			<option value="contains"><?php 
        _e('contains', 'wp_all_export_plugin');
        ?>
</option>
			<option value="not_contains"><?php 
        _e("doesn't contain", 'wp_all_export_plugin');
        ?>
</option>
			<option value="is_empty"><?php 
        _e('is empty', 'wp_all_export_plugin');
        ?>
</option>
			<option value="is_not_empty"><?php 
        _e('is not empty', 'wp_all_export_plugin');
        ?>
</option>
			<?php 
    } else {
        ?>
			<option value="equals"><?php 
        _e('equals', 'wp_all_export_plugin');
        ?>
</option>
			<option value="not_equals"><?php 
        _e("doesn't equal", 'wp_all_export_plugin');
        ?>
</option>
			<option value="greater"><?php 
        _e('greater than', 'wp_all_export_plugin');
        ?>
</option>
			<option value="equals_or_greater"><?php 
        _e('equal to or greater than', 'wp_all_export_plugin');
        ?>
</option>
			<option value="less"><?php 
        _e('less than', 'wp_all_export_plugin');
        ?>
</option>
			<option value="equals_or_less"><?php 
        _e('equal to or less than', 'wp_all_export_plugin');
        ?>
</option>

			<option value="contains"><?php 
        _e('contains', 'wp_all_export_plugin');
        ?>
</option>
			<option value="not_contains"><?php 
        _e("doesn't contain", 'wp_all_export_plugin');
        ?>
</option>
			<option value="is_empty"><?php 
        _e('is empty', 'wp_all_export_plugin');
        ?>
</option>
			<option value="is_not_empty"><?php 
        _e('is not empty', 'wp_all_export_plugin');
        ?>
</option>
			<?php 
    }
    ?>
	</select>
	<?php 
    exit(json_encode(array('html' => ob_get_clean())));
    die;
}
function pmxe_wp_ajax_export_filtering_count()
{
    if (!check_ajax_referer('wp_all_export_secure', 'security', false)) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
    }
    if (!current_user_can('manage_options')) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
    }
    ob_start();
    $input = new PMXE_Input();
    $post = $input->post('data', array());
    $filter_args = array('filter_rules_hierarhy' => $post['filter_rules_hierarhy'], 'product_matching_mode' => $post['product_matching_mode']);
    XmlExportEngine::$is_user_export = 'users' == $post['cpt'] ? true : false;
    XmlExportEngine::$post_types = array($post['cpt']);
    $filters = new XmlExportFiltering($filter_args);
    $filters->parseQuery();
    PMXE_Plugin::$session->set('whereclause', $filters->get('queryWhere'));
    PMXE_Plugin::$session->set('joinclause', $filters->get('queryJoin'));
    PMXE_Plugin::$session->save_data();
    $found_records = 0;
    if ('users' == $post['cpt']) {
        add_action('pre_user_query', 'wp_all_export_pre_user_query', 10, 1);
        $exportQuery = new WP_User_Query(array('orderby' => 'ID', 'order' => 'ASC', 'number' => 10));
        if (!empty($exportQuery->results)) {
            $found_records = $exportQuery->get_total();
        }
        remove_action('pre_user_query', 'wp_all_export_pre_user_query');
    } else {
        add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
        add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
        $exportQuery = new WP_Query(array('post_type' => $post['cpt'], 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => 10));
        if (!empty($exportQuery->found_posts)) {
            $found_records = $exportQuery->found_posts;
        }
        remove_filter('posts_join', 'wp_all_export_posts_join');
        remove_filter('posts_where', 'wp_all_export_posts_where');
    }
    ?>
	<div class="founded_records">			
		<?php 
    if ($found_records > 0) {
        ?>
		<h3><span class="matches_count"><?php 
        echo $found_records;
        ?>
</span> <strong><?php 
        echo wp_all_export_get_cpt_name(array($post['cpt']), $found_records);
        ?>
</strong> will be exported</h3>
		<h4><?php 
        _e("Continue to Step 2 to choose data to include in the export file.");
        ?>
</h4>		
		<?php 
    } else {
        ?>
		<h4 style="line-height:60px;"><?php 
        printf(__("No matching %s found for selected filter rules"), wp_all_export_get_cpt_name(array($post['cpt'])));
        ?>
</h4>
		<?php 
    }
    ?>
	</div>
	<?php 
    exit(json_encode(array('html' => ob_get_clean())));
    die;
}
function pmxe_wp_ajax_export_available_rules()
{
    if (!check_ajax_referer('wp_all_export_secure', 'security', false)) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
    }
    if (!current_user_can('manage_options')) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
    }
    ob_start();
    $input = new PMXE_Input();
    $post = $input->post('data', array());
    ?>
	<select id="wp_all_export_rule">
		<option value=""><?php 
    _e('Select Rule', 'wp_all_export_plugin');
    ?>
</option>
		<?php 
    if (strpos($post['selected'], 'tx_') === 0) {
        ?>
										

				<!-- Taxonomies -->
				<option value="in">IN</option>
				<option value="not_in">NOT IN</option>

				<!-- Custom Fields -->
				<!--option value="between">BETWEEN</option-->
			
			<?php 
    } else {
        ?>
			<option value="equals"><?php 
        _e('equals', 'wp_all_export_plugin');
        ?>
</option>
			<option value="not_equals"><?php 
        _e('not equals', 'wp_all_export_plugin');
        ?>
</option>
			<option value="greater"><?php 
        _e('greater than', 'wp_all_export_plugin');
        ?>
</option>
			<option value="equals_or_greater"><?php 
        _e('equals or greater than', 'wp_all_export_plugin');
        ?>
</option>
			<option value="less"><?php 
        _e('less than', 'wp_all_export_plugin');
        ?>
</option>
			<option value="equals_or_less"><?php 
        _e('equals or less than', 'wp_all_export_plugin');
        ?>
</option>

			<option value="contains"><?php 
        _e('contains', 'wp_all_export_plugin');
        ?>
</option>
			<option value="not_contains"><?php 
        _e('not contains', 'wp_all_export_plugin');
        ?>
</option>
			<option value="is_empty"><?php 
        _e('is empty', 'wp_all_export_plugin');
        ?>
</option>
			<option value="is_not_empty"><?php 
        _e('is not empty', 'wp_all_export_plugin');
        ?>
</option>
			<?php 
    }
    ?>
	</select>
	<?php 
    exit(json_encode(array('html' => ob_get_clean())));
    die;
}