Plugin Directory

Changeset 3237856


Ignore:
Timestamp:
02/10/2025 11:13:08 AM (14 months ago)
Author:
Atlas_Gondal
Message:

release 5.0 - new export fields and performance optimizations

Location:
export-all-urls
Files:
12 added
4 edited

Legend:

Unmodified
Added
Removed
  • export-all-urls/trunk/eau_functions.php

    r2990491 r3237856  
    77 * Time: 9:01 AM
    88 */
     9
    910namespace Export_All_URLs;
    1011
     
    1314require_once(plugin_dir_path(__FILE__) . 'classes/constants.php');
    1415
    15 class EAU_Functions{
     16class EAU_Functions
     17{
    1618    public function Eau_Export_fields()
    1719    {
    1820        return  array(
    19             'p_id'          => __('Post ID', Constants::PLUGIN_TEXT_DOMAIN),
    20             'title'         => __('Title', Constants::PLUGIN_TEXT_DOMAIN),
    21             'url'           => __('URL', Constants::PLUGIN_TEXT_DOMAIN),
    22             'categories'    => __('Categories', Constants::PLUGIN_TEXT_DOMAIN),
    23             'tags'          => __('Tags', Constants::PLUGIN_TEXT_DOMAIN),
    24             'author'        => __('Author', Constants::PLUGIN_TEXT_DOMAIN),
    25             'p_date'        => __('Published Date', Constants::PLUGIN_TEXT_DOMAIN),
    26             'm_date'        => __('Modified Date', Constants::PLUGIN_TEXT_DOMAIN),
     21            'p_id'              => __('Post ID', Constants::PLUGIN_TEXT_DOMAIN),
     22            'title'             => __('Title', Constants::PLUGIN_TEXT_DOMAIN),
     23            'url'               => __('URL', Constants::PLUGIN_TEXT_DOMAIN),
     24            'categories'        => __('Categories', Constants::PLUGIN_TEXT_DOMAIN),
     25            'category_urls'   => __('Category URLs', Constants::PLUGIN_TEXT_DOMAIN),
     26            'tags'              => __('Tags', Constants::PLUGIN_TEXT_DOMAIN),
     27            'tag_urls'         => __('Tag URLs', Constants::PLUGIN_TEXT_DOMAIN),
     28            'author'            => __('Author', Constants::PLUGIN_TEXT_DOMAIN),
     29            'p_date'            => __('Published Date', Constants::PLUGIN_TEXT_DOMAIN),
     30            'm_date'            => __('Modified Date', Constants::PLUGIN_TEXT_DOMAIN),
     31            'status'            => __('Status', Constants::PLUGIN_TEXT_DOMAIN),
    2732        );
    2833    }
    29    
     34
    3035    /**
    3136     * Returns an array of field labels for the selected fields.
     
    3944        $all_fields = self::Eau_Export_fields();
    4045        $extracted_fields = $hash ? array('#') : array();
    41    
     46
    4247        foreach ($selected_fields as $key) {
    4348            if (array_key_exists($key, $all_fields)) {
     
    4550            }
    4651        }
    47    
     52
    4853        return $extracted_fields;
    4954    }
    50    
     55
    5156    public function eau_extract_relative_url($url)
    5257    {
    5358        return preg_replace('/^(http)?s?:?\/\/[^\/]*(\/?.*)$/i', '$2', '' . $url);
    5459    }
    55    
     60
    5661    public function eau_is_checked($name, $value)
    5762    {
     
    6166            }
    6267        }
    63    
     68
    6469        return false;
    6570    }
    66    
    67    
     71
     72
    6873    /**
    6974     * @param $selected_post_type
     
    8186    public function eau_generate_output($selected_post_type, $post_status, $post_author, $exclude_domain, $post_per_page, $offset, $export_type, $export_fields, $csv_name, $posts_from, $posts_upto)
    8287    {
    83    
     88
    8489        $data_array = array();
    8590        $html_row = '';
    8691        $counter = 0;
    87    
     92
    8893        if ($post_author == "all") {
    8994            $post_author = "";
    9095        }
    91    
     96
    9297        if ($post_per_page == "all" && $offset == "all") {
    9398            $post_per_page = -1;
    9499            $offset = "";
    95100        }
    96    
    97         switch ($post_status) {
    98             case "all":
    99                 $post_status = array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'trash');
    100                 break;
    101             case 'publish':
    102                 $post_status = 'publish';
    103                 break;
    104             case 'pending':
    105                 $post_status = 'pending';
    106                 break;
    107             case 'draft':
    108                 $post_status = 'draft';
    109                 break;
    110             case 'future':
    111                 $post_status = 'future';
    112                 break;
    113             case 'private':
    114                 $post_status = 'private';
    115                 break;
    116             case 'trash':
    117                 $post_status = 'trash';
    118                 break;
    119             default:
    120                 $post_status = 'publish';
    121                 break;
    122         }
    123    
     101
     102        if (in_array("all", $post_status)) {
     103            $post_status = array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'trash');
     104        }
     105        if (in_array("draft", $post_status)) {
     106            $post_status[] = 'auto-draft';
     107        }
     108
    124109        $posts_query = new \WP_Query(array(
    125110            'post_type'         => $selected_post_type,
     
    138123            )
    139124        ));
    140    
     125
    141126        if (!$posts_query->have_posts()) {
    142127            echo "<div class='notice notice-error' style='width: 93%'>" . __("no result found in that range, please <strong>reselect and try again</strong>!", Constants::PLUGIN_TEXT_DOMAIN) . "</div>";
    143128            return;
    144129        }
    145    
     130
    146131        $total_results = $posts_query->found_posts;
    147132        $counter = 1;
    148    
     133
    149134        while ($posts_query->have_posts()) {
    150135            $posts_query->the_post();
     
    152137            $post_type = get_post_type($post_id);
    153138            $taxonomies = get_object_taxonomies($post_type);
    154    
     139
     140            $post_terms = [];
     141            foreach ($taxonomies as $taxonomy) {
     142                if (strpos($taxonomy, 'cat') !== false || strpos($taxonomy, 'tag') !== false) {
     143                    $terms = get_the_terms($post_id, $taxonomy);
     144                    if ($terms && !is_wp_error($terms)) {
     145                        $post_terms[$taxonomy] = $terms;
     146                    }
     147                }
     148            }
     149
    155150            $row = array();
    156151            foreach ($export_fields as $field) {
     
    167162                    case 'categories':
    168163                        $categories = array();
    169                         foreach ($taxonomies as $taxonomy) {
     164                        foreach ($post_terms as $taxonomy => $terms) {
    170165                            if (strpos($taxonomy, 'cat') !== false) {
    171                                 $categories[] = strip_tags(get_the_term_list($post_id, $taxonomy, '', ', '));
     166                                foreach ($terms as $term) {
     167                                    $categories[] = esc_html($term->name);
     168                                }
    172169                            }
    173170                        }
    174171                        $row[] = implode(', ', $categories);
    175172                        break;
     173                    case 'category_urls':
     174                        $categories_urls = array();
     175                        foreach ($post_terms as $taxonomy => $terms) {
     176                            if (strpos($taxonomy, 'cat') !== false) {
     177                                foreach ($terms as $term) {
     178                                    $category_url = get_term_link($term);
     179                                    if (!is_wp_error($category_url)) {
     180                                        $categories_urls[] = esc_url($category_url);
     181                                    }
     182                                }
     183                            }
     184                        }
     185                        $row[] = implode(', ', $categories_urls);
     186                        break;
    176187                    case 'tags':
    177188                        $tags = array();
    178                         foreach ($taxonomies as $taxonomy) {
     189                        foreach ($post_terms as $taxonomy => $terms) {
    179190                            if (strpos($taxonomy, 'tag') !== false) {
    180                                 $tags[] = strip_tags(get_the_term_list($post_id, $taxonomy, '', ', '));
     191                                foreach ($terms as $term) {
     192                                    $tags[] = esc_html($term->name);
     193                                }
    181194                            }
    182195                        }
    183196                        $row[] = implode(', ', $tags);
    184197                        break;
     198                    case 'tag_urls':
     199                        $tags_urls = array();
     200                        foreach ($post_terms as $taxonomy => $terms) {
     201                            if (strpos($taxonomy, 'tag') !== false) {
     202                                foreach ($terms as $term) {
     203                                    $tags_urls[] = esc_url(get_term_link($term));
     204                                }
     205                            }
     206                        }
     207                        $row[] = implode(', ', $tags_urls);
     208                        break;
    185209                    case 'author':
    186210                        $row[] = htmlspecialchars_decode(get_the_author());
     
    192216                        $row[] = get_the_modified_date('Y-m-d H:i:s', $post_id);
    193217                        break;
    194                 }
    195             }
    196    
     218                    case 'status':
     219                        $row[] = ucfirst(get_post_status($post_id));
     220                        break;
     221                }
     222            }
     223
    197224            if ($export_type == 'text') {
    198225                $data_array[] = $row;
    199226            } else {
    200    
     227
    201228                $html_row .= '<tr>';
    202229                $html_row .= '<td>' . $counter . '</td>';
     
    209236        }
    210237        wp_reset_postdata();
    211    
     238
    212239        self::eau_export_data($data_array, $html_row, $total_results, $export_fields, $export_type, $csv_name);
    213240    }
    214    
    215    
     241
     242
    216243    public function eau_export_data($data_array, $row, $total_results, $export_fields, $export_type, $csv_name)
    217244    {
    218    
     245
    219246        $file_path = wp_upload_dir();
    220    
     247
    221248        switch ($export_type) {
    222    
     249
    223250            case "text":
    224    
     251
    225252                $file = $file_path['path'] . "/" . $csv_name . '.CSV';
    226253                $myfile = @fopen($file, "w") or die("<div class='error' style='width: 95.3%; margin-left: 2px;'>" . __("Unable to create a file on your server! (either invalid name supplied or permission issue)", Constants::PLUGIN_TEXT_DOMAIN) . "</div>");
    227254                fprintf($myfile, "\xEF\xBB\xBF");
    228    
     255
    229256                $csv_url = esc_url($file_path['url'] . "/" . $csv_name . ".CSV");
    230    
     257
    231258                $field_labels = self::eau_get_field_labels($export_fields);
    232    
     259
    233260                fputcsv($myfile, $field_labels);
    234    
     261
    235262                foreach ($data_array as $data_row) {
    236263                    fputcsv($myfile, $data_row);
    237264                }
    238    
     265
    239266                fclose($myfile);
    240    
     267
    241268                echo "<div class='updated' style='width: 97%'>Data exported successfully! <a href='" . $csv_url . "' target='_blank'><strong>" . __('Click here', Constants::PLUGIN_TEXT_DOMAIN) . "</strong></a> " . __('to Download', Constants::PLUGIN_TEXT_DOMAIN) . ".</div>";
    242269                echo "<div class='notice notice-warning' style='width: 97%'>" . __('Once you have downloaded the file, it is recommended to delete file from the server, for security reasons.', Constants::PLUGIN_TEXT_DOMAIN) . " <a href='" . wp_nonce_url(admin_url('tools.php?page=extract-all-urls-settings&del=y&f=') . base64_encode($file)) . "' ><strong>" . __('Click Here', Constants::PLUGIN_TEXT_DOMAIN) . "</strong></a> " . __('to delete the file. And don\'t worry, you can always regenerate anytime. :)', Constants::PLUGIN_TEXT_DOMAIN) . "</div>";
    243270                echo "<div class='notice notice-info' style='width: 97%'><strong>" . __('Total', Constants::PLUGIN_TEXT_DOMAIN) . "</strong> " . __('number of links', Constants::PLUGIN_TEXT_DOMAIN) . ": <strong>" . esc_html($total_results,) . "</strong>.</div>";
    244    
     271
    245272                break;
    246    
     273
    247274            case "here":
    248    
     275
    249276                echo "<h1 align='center' style='padding: 10px 0;'><strong>" . __('Below is a list of Exported Data:', Constants::PLUGIN_TEXT_DOMAIN) . "</strong></h1>";
    250277                echo "<h2 align='center' style='font-weight: normal;'>" . __('Total number of links', Constants::PLUGIN_TEXT_DOMAIN) . ": <strong>" . esc_html($total_results) . "</strong>.</h2>";
    251    
     278
    252279                echo '<table id="outputData" class="wp-list-table widefat fixed striped">';
    253280                echo '<thead><tr>';
    254    
     281
    255282                $field_labels = self::eau_get_field_labels($export_fields, $hash = true);
    256    
     283
    257284                foreach ($field_labels as $label) {
    258285                    echo '<th>' . ucfirst($label) . '</th>';
    259286                }
    260    
     287
    261288                echo '</tr></thead><tbody>';
    262289                echo $row;
    263290                echo '</tbody></table>';
    264    
     291
    265292                break;
    266    
     293
    267294            default:
    268    
     295
    269296                echo __('Sorry, you missed export type, Please', Constants::PLUGIN_TEXT_DOMAIN) . " <strong>" . __('Select Export Type', Constants::PLUGIN_TEXT_DOMAIN) . "</strong> " . __('and try again!', Constants::PLUGIN_TEXT_DOMAIN) . " :)";
    270297                break;
    271298        }
    272299    }
    273    
    274300}
    275301
  • export-all-urls/trunk/extract-all-urls-settings.php

    r2990491 r3237856  
    7272    $selected_post_type = isset($_POST['post-type']) ? $_POST['post-type'] : 'any';
    7373    $selected_export_fields = isset($_POST['export_fields']) ? $_POST['export_fields'] : ($form_submitted ? array() : array('url', 'title'));
    74     $selected_post_status = isset($_POST['post-status']) ? $_POST['post-status'] : 'publish';
     74    $selected_post_status = isset($_POST['post-status']) ? $_POST['post-status'] : ($form_submitted ? array() : array('publish'));
    7575    $selected_user = isset($_POST['post-author']) ? $_POST['post-author'] : 'all';
    7676    $selected_export_type = isset($_POST['export-type']) ? $_POST['export-type'] : 'here';
     
    129129
    130130                                    <?php foreach ($post_status as $value => $label) : ?>
    131                                         <label><input type="radio" name="post-status" value="<?php echo $value; ?>" <?php echo $value == $selected_post_status ? 'checked' : ''; ?>> <?php echo $label; ?></label><br />
     131                                        <label><input type="checkbox" name="post-status[]" value="<?php echo $value; ?>" <?php echo in_array($value, $selected_post_status) ? 'checked' : ''; ?>> <?php echo $label; ?></label><br />
    132132                                    <?php endforeach; ?>
    133133
     
    312312                $export_type = sanitize_text_field($_POST['export-type']);
    313313                $export_fields = map_deep($_POST['export_fields'], 'sanitize_text_field');
    314                 $post_status = sanitize_text_field($_POST['post-status']);
     314                $post_status = map_deep($_POST['post-status'], 'sanitize_text_field');
    315315                $post_author = sanitize_text_field($_POST['post-author']);
    316316                $exclude_domain = isset($_POST['exclude-domain']) ? sanitize_text_field($_POST['exclude-domain']) : null;
  • export-all-urls/trunk/extract-all-urls.php

    r3112244 r3237856  
    55Plugin URI: https://AtlasGondal.com/
    66Description: This plugin enables you to extract information such as Title, URL, Categories, Tags, Author, as well as Published and Modified dates for built-in post types (e.g., post, page) or any other custom post types present on your site. You have the option to display the output in the dashboard or export it as a CSV file. This can be highly beneficial for tasks like migration, SEO analysis, and security audits.
    7 Version: 4.7.1
     7Version: 5.0
    88Author: Atlas Gondal
    99Author URI: https://AtlasGondal.com/
  • export-all-urls/trunk/readme.txt

    r3194637 r3237856  
    55Requires at least: 3.1
    66Tested up to: 6.7.1
    7 Stable tag: 4.7.1
     7Stable tag: 5.0
    88Requires PHP: 5.4
    99License: GPLv2 or later
     
    2020* URL
    2121* Categories
     22* Category URLs
    2223* Tags
     24* Tag URLs
    2325* Author
    2426* Published Date
    2527* Modified Date
     28* Status
    2629
    2730The data can be filtered by post type, post status, date range, and author before extraction, and the plugin also provides the option to export using a specific post range.
     
    134137
    135138== Changelog ==
     139
     140= 5.0 =
     141* New - additional export fields added (status, category urls, tag urls)
     142* New - allows multiple post status selection
     143* Improvement - few backend refinements to improve performance
     144* Compatibility - tested with Wordpress 6.7.1
    136145
    137146= 4.7.1 =
     
    233242== Upgrade Notice ==
    234243
    235 = 4.7.1 =
    236 * Compatibility - tested with WordPress 6.7-alpha-58656
     244= 5.0 =
     245* New - additional export fields added (status, category urls, tag urls)
     246* New - allows multiple post status selection
     247* Improvement - few backend refinements to improve performance
     248* Compatibility - tested with Wordpress 6.7.1
Note: See TracChangeset for help on using the changeset viewer.