<?php
require_once(plugin_dir_path(__FILE__) . 'functions.php');
function sh_epua_plugin_html()
{
	
	$custom_posts_names = array();
    $custom_posts_labels = array();
    $user_ids = array();
    $user_names = array();

    $args = array(
        'public' => true,
        '_builtin' => false
    );

    $output = 'objects';

    $operator = 'and';
	
	$allpost_types = get_post_types($args, $output, $operator);
	
	foreach ($allpost_types as $post_type) {

        $custom_posts_names[] = $post_type->name;
        $custom_posts_labels[] = $post_type->labels->singular_name;

    }
	?>
	<div class="maincontentplugin" id="main-content">
		<h2 align="center">Export all posts urls</h2>
		<div class="shmainwrapper">
            <div id="shmainontainer" class="postbox shcolumns">

                <div class="inside">
					<form method="post" action="" id="allurlsetting">
						<table id="allurlsettingtable">
							<tr>
							<th>Select Post type url you want to export</th>
							<td><div class="form-group">
							 <label><input type="radio" name="selected_post_type" value="any"  disabled /> All
                                        Types (pages, posts, and custom post types) <span class="bold">(Available in pro)</span></label>
							</div><div class="form-group">
							 <label><input type="radio" name="selected_post_type" value="page" required="required" checked /> Pages
                                        </label>
							</div><div class="form-group">
							 <label><input type="radio" name="selected_post_type" value="post" required="required" checked /> Posts
                                   </label>
							</div>
							<?php

                                    if (!empty($custom_posts_names) && !empty($custom_posts_labels)) {
                                        for ($i = 0; $i < count($custom_posts_names); $i++) {
                                            echo '<div class="form-group"><label><input type="radio" name="post-type" value="' . esc_html($custom_posts_names[$i]) . '" disabled/> ' . esc_html($custom_posts_labels[$i]) . ' Posts <span class="bold">(Available in pro)</span></label></div>';
                                        }
                                    }
                                    ?>
							
							</td>
							</tr>
							  <tr>
								<td class="submitrow" colspan="2"> 
                                    <input type="submit" name="export" class="button button-primary"
                                           value="Get All Selected Urls"/>
                                </td>

                            </tr>
							
					
						</table>
					</form>
				</div>	
	       </div>
		   <div id="eauSideContainer" class="eaucolumns">
                <div class="postbox">
                    <h3>Want to Support?</h3>
                    <div class="inside">
                        <p>If you enjoyed the plugin, and want to support:</p>
                        <ul>
                            <li>
                                <a href="https://sivahtech.com/hire-me/"
                                   target="_blank">Hire me</a> on a project
                            </li>
                            <li>Buy me a Coffee
                                <a href="https://sivahtech.com/donate/" target="_blank"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif"/> </a>

                            </li>
                        </ul>
                        <hr>
                        <h3>Wanna say Thanks?</h3>
                        <ul>
                            <li>Leave <a
                                        href="https://wordpress.org/plugins/export-all-posts-urls/reviews/?filter=5#new-post"
                                        target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a> rating
                            </li>
                            <li>Tweet me: <a href="https://twitter.com/SivahTech" target="_blank">@sivahtech</a>
                            </li>
                        </ul>
                        <hr>
                        <h3>Got a Problem?</h3>
                        <p>If you want to report a bug or suggest new feature. You can:</p>
                        <ul>
                            <li>Create <a href="https://wordpress.org/support/plugin/export-all-posts-urls/" target="_blank">Support
                                    Ticket</a></li>

                            <li>Write me an <a
                                        href="https://sivahtech.com/get-in-touch/"
                                        target="_blank">Email</a></li>
                        </ul>
                        <strong>Reporting</strong> an issue is way better than leaving <strong>1 star</strong> feedback, which does not help you, me, or the community. So, please consider giving me a chance to help before leaving any negative feedback.
                        <hr>
                        <h4 id="eauDevelopedBy">Developed by: <a
                                    href="https://sivahtech.com/get-in-touch/"
                                    target="_blank">Sivahtech</a></h4>
                    </div>
                </div>
            </div>
		</div>
	</div>
<?php
if (isset($_POST['export'])) {
	
	if (!empty($_POST['selected_post_type'])){
		$allowed_values = ['page', 'post'];
		if(in_array($_POST['selected_post_type'],$allowed_values )){
			$post_type = sanitize_text_field($_POST['selected_post_type']);
			$offset = 'all';
			$post_per_page = 'all';
			$selected_post_type = sh_epua_your_post_selected($post_type, $custom_posts_names);
			
			
			$args =array(
				'post_type' => $selected_post_type,
				'posts_per_page' => -1,
				
			);
			
			
			sh_epua_print_output($args,$selected_post_type);
		}else{
			
			echo "<div class='notice notice-error' style='width: 93%'>Sorry, Please select either page or post! :)</div>";
			exit;	
		}
	}else{
		echo "<div class='notice notice-error' style='width: 93%'>Sorry, you missed something, Please recheck above options! :)</div>";
		exit;
    }
}
	
}
sh_epua_plugin_html();