Plugin Directory

Changeset 3379262


Ignore:
Timestamp:
10/16/2025 06:49:28 AM (5 months ago)
Author:
recorp
Message:
  • FIXED: Skip assets not working issue.
  • FIXED: Some other issues.
  • ADDED: Increase 3 pages limitation to 6 pages.
Location:
export-wp-page-to-static-html/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • export-wp-page-to-static-html/trunk/README.txt

    r3358063 r3379262  
    44Requires at least: 4.1 
    55Tested up to: 6.8
    6 Stable tag: 4.3.2
     6Stable tag: 4.3.3
    77License: GPLv2 or later 
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html 
  • export-wp-page-to-static-html/trunk/admin/includes/AjaxRequests/assetsExporter.php

    r3350057 r3379262  
    2525    public function assets_exporter() {
    2626
    27     \rcCheckNonce();
    28 
    29     $asset_type = isset($_POST['asset_type']) ? \sanitize_text_field($_POST['asset_type']) : "";
    30 
    31     include __DIR__ . '/../class-ExtractorHelpers.php';
    32     $extractorHelpers = new \ExtractorHelpers();
    33 
    34     $asset_type = isset($_POST['asset_type']) ? sanitize_text_field($_POST['asset_type']) : null;
    35     $limit      = isset($_POST['limit']) ? (int) $_POST['limit'] : 1;
    36 
    37     $assets = $extractorHelpers->get_next_export_asset($asset_type, $limit);
    38 
    39     // Normalize to array
    40     if ($limit === 1) {
    41         $assets = $assets ? [$assets] : [];
     27        \rcCheckNonce();
     28
     29        $asset_type = isset($_POST['asset_type']) ? \sanitize_text_field($_POST['asset_type']) : "";
     30
     31        include __DIR__ . '/../class-ExtractorHelpers.php';
     32        $extractorHelpers = new \ExtractorHelpers();
     33
     34        $asset_type = isset($_POST['asset_type']) ? sanitize_text_field($_POST['asset_type']) : null;
     35        $limit      = isset($_POST['limit']) ? (int) $_POST['limit'] : 1;
     36
     37        $assets = $extractorHelpers->get_next_export_asset($asset_type, $limit);
     38
     39        // Normalize to array
     40        if ($limit === 1) {
     41            $assets = $assets ? [$assets] : [];
     42        }
     43
     44        $results = [
     45            'css'     => [],
     46            'js'      => [],
     47            'image'   => [],
     48            'url'     => [],
     49            'skipped' => [],
     50        ];
     51
     52        foreach ($assets as $asset) {
     53
     54            $id       = isset($asset['id']) ? (int) $asset['id'] : 0;
     55            $url      = isset($asset['url']) ? $asset['url'] : '';
     56            $found_on = isset($asset['found_on']) ? $asset['found_on'] : '';
     57            $type     = isset($asset['type']) ? $asset['type'] : '';
     58            $status   = isset($asset['status']) ? $asset['status'] : '';
     59            $new_name = isset($asset['new_file_name']) ? $asset['new_file_name'] : '';
     60
     61            if (!$id || !$url || !$type) {
     62                $results['skipped'][] = ['id' => $id, 'reason' => 'missing_required_fields'];
     63                continue;
     64            }
     65
     66            if ($status === 'processing') {
     67                $results[$type][] = [
     68                    'id'           => $id,
     69                    'url'          => $url,
     70                    'asset_status' => $status,
     71                    'handled'      => false,
     72                    'message'      => 'Already processing',
     73                ];
     74                continue;
     75            }
     76
     77            $extractorHelpers->update_asset_url_status($url, 'processing');
     78
     79            try {
     80                switch ($type) {
     81                    case 'css':
     82                        $extractorHelpers->save_stylesheet($url, $found_on, $new_name);
     83                        break;
     84
     85                    case 'js':
     86                        $extractorHelpers->save_scripts($url, $found_on, $new_name);
     87                        break;
     88
     89                    case 'url':
     90                        $endpoint = rest_url('ewptshp/v1/run');
     91                        $token    = get_option('ewptshp_worker_token');
     92
     93                        wp_remote_post($endpoint, [
     94                            'timeout'   => 5,
     95                            'blocking'  => false,
     96                            'sslverify' => false,
     97                            'body'      => [
     98                                'token' => $token,
     99                                'url'   => $url,
     100                            ],
     101                        ]);
     102                       
     103                        error_log('[URL DOne] onAssetsExporter'. $url);
     104                        break;
     105
     106                    case 'image':
     107                        if (method_exists($extractorHelpers, 'save_image')) {
     108                            $extractorHelpers->save_image($url, $found_on, $new_name);
     109                        } else {
     110                        }
     111                        break;
     112
     113                    default:
     114                        $results['skipped'][] = ['id' => $id, 'reason' => 'unknown_type', 'type' => $type];
     115                        continue 2;
     116                }
     117
     118                $results[$type][] = [
     119                    'id'           => $id,
     120                    'url'          => $url,
     121                    'asset_status' => 'processed',
     122                    'handled'      => true,
     123                ];
     124
     125            } catch (Exception $e) {
     126                $extractorHelpers->update_asset_url_status($url, 'failed');
     127
     128                $results[$type][] = [
     129                    'id'           => $id,
     130                    'url'          => $url,
     131                    'asset_status' => 'failed',
     132                    'handled'      => false,
     133                    'error'        => $e->getMessage(),
     134                ];
     135            }
     136        }
     137
     138
     139        echo wp_json_encode([
     140            'success' => true,
     141            'status'  => 'success',
     142            'fetched' => count($assets),
     143            'grouped' => [
     144                'css'   => $results['css'],
     145                'js'    => $results['js'],
     146                'image' => $results['image'],
     147                'url'   => $results['url'],
     148            ],
     149            'skipped' => $results['skipped'],
     150        ], JSON_UNESCAPED_SLASHES);
     151
     152        $status = (string) $this->getSettings('creating_zip');
     153        $proc   = (string) $this->getSettings('creating_zip_process');
     154        $creatingHtmlProcess = $this->getSettings('creating_html_process', 'running');
     155
     156
     157        if ($creatingHtmlProcess === 'completed' && $this->are_all_assets_exported() && $status !== 'running') {
     158            $this->setSettings('creating_zip', 'running');
     159        }
     160        elseif ($status === 'running' && $proc !== 'running' && $proc !== 'completed') {
     161            do_action('assets_files_exporting_completed');
     162        }
     163
     164
     165        wp_die();
    42166    }
    43 
    44     $results = [
    45         'css'     => [],
    46         'js'      => [],
    47         'image'   => [],
    48         'url'     => [],
    49         'skipped' => [],
    50     ];
    51 
    52     foreach ($assets as $asset) {
    53 
    54         $id       = isset($asset['id']) ? (int) $asset['id'] : 0;
    55         $url      = isset($asset['url']) ? $asset['url'] : '';
    56         $found_on = isset($asset['found_on']) ? $asset['found_on'] : '';
    57         $type     = isset($asset['type']) ? $asset['type'] : '';
    58         $status   = isset($asset['status']) ? $asset['status'] : '';
    59         $new_name = isset($asset['new_file_name']) ? $asset['new_file_name'] : '';
    60 
    61         if (!$id || !$url || !$type) {
    62             $results['skipped'][] = ['id' => $id, 'reason' => 'missing_required_fields'];
    63             continue;
    64         }
    65 
    66         if ($status === 'processing') {
    67             $results[$type][] = [
    68                 'id'           => $id,
    69                 'url'          => $url,
    70                 'asset_status' => $status,
    71                 'handled'      => false,
    72                 'message'      => 'Already processing',
    73             ];
    74             continue;
    75         }
    76 
    77         $extractorHelpers->update_asset_url_status($url, 'processing');
    78 
    79         try {
    80             switch ($type) {
    81                 case 'css':
    82                     $extractorHelpers->save_stylesheet($url, $found_on, $new_name);
    83                     break;
    84 
    85                 case 'js':
    86                     $extractorHelpers->save_scripts($url, $found_on, $new_name);
    87                     break;
    88 
    89                 case 'url':
    90                     $endpoint = rest_url('ewptshp/v1/run');
    91                     $token    = get_option('ewptshp_worker_token');
    92 
    93                     wp_remote_post($endpoint, [
    94                         'timeout'   => 5,
    95                         'blocking'  => false,
    96                         'sslverify' => false,
    97                         'body'      => [
    98                             'token' => $token,
    99                             'url'   => $url,
    100                         ],
    101                     ]);
    102                    
    103                     error_log('[URL DOne] onAssetsExporter'. $url);
    104                     break;
    105 
    106                 case 'image':
    107                     if (method_exists($extractorHelpers, 'save_image')) {
    108                         $extractorHelpers->save_image($url, $found_on, $new_name);
    109                     } else {
    110                     }
    111                     break;
    112 
    113                 default:
    114                     $results['skipped'][] = ['id' => $id, 'reason' => 'unknown_type', 'type' => $type];
    115                     continue 2;
    116             }
    117 
    118             $results[$type][] = [
    119                 'id'           => $id,
    120                 'url'          => $url,
    121                 'asset_status' => 'processed',
    122                 'handled'      => true,
    123             ];
    124 
    125         } catch (Exception $e) {
    126             $extractorHelpers->update_asset_url_status($url, 'failed');
    127 
    128             $results[$type][] = [
    129                 'id'           => $id,
    130                 'url'          => $url,
    131                 'asset_status' => 'failed',
    132                 'handled'      => false,
    133                 'error'        => $e->getMessage(),
    134             ];
    135         }
    136     }
    137 
    138 
    139     echo wp_json_encode([
    140         'success' => true,
    141         'status'  => 'success',
    142         'fetched' => count($assets),
    143         'grouped' => [
    144             'css'   => $results['css'],
    145             'js'    => $results['js'],
    146             'image' => $results['image'],
    147             'url'   => $results['url'],
    148         ],
    149         'skipped' => $results['skipped'],
    150     ], JSON_UNESCAPED_SLASHES);
    151 
    152     $status = (string) $this->getSettings('creating_zip');
    153     $proc   = (string) $this->getSettings('creating_zip_process');
    154     $creatingHtmlProcess = $this->getSettings('creating_html_process', 'running');
    155 
    156 
    157     if ($creatingHtmlProcess === 'completed' && $this->are_all_assets_exported() && $status !== 'running') {
    158         $this->setSettings('creating_zip', 'running');
    159     }
    160     elseif ($status === 'running' && $proc !== 'running' && $proc !== 'completed') {
    161         do_action('assets_files_exporting_completed');
    162     }
    163 
    164 
    165     wp_die();
    166 }
    167167
    168168
     
    171171        $table = $wpdb->prefix . 'export_urls_logs';
    172172
    173         // Count total css/js assets
     173        // Build dynamic type condition
     174        $types = [];
     175       
     176        $skip = (array) $this->getSettings('skipAssetsFiles', array());
     177       
     178        if (!array_key_exists('stylesheets', $skip)) {
     179            $types[] = "'css'";
     180        }
     181       
     182        if (!array_key_exists('scripts', $skip)) {
     183            $types[] = "'js'";
     184        }
     185
     186        // If both skipped, nothing to check
     187        if (empty($types)) {
     188            return true;
     189        }
     190
     191        $types_in = implode(',', $types);
     192
     193        // Count total assets
    174194        $total = $wpdb->get_var("
    175195            SELECT COUNT(*)
    176196            FROM {$table}
    177             WHERE type IN ('css', 'js')
     197            WHERE type IN ({$types_in})
    178198        ");
    179199
    180         // If no css/js assets exist, return false (or change this to true if preferred)
     200        // If no matching assets exist
    181201        if ((int) $total === 0) {
    182202            return false;
    183203        }
    184204
    185         // Count how many of those have been exported
     205        // Count exported assets
    186206        $exported = $wpdb->get_var("
    187207            SELECT COUNT(*)
    188208            FROM {$table}
    189             WHERE type IN ('css', 'js') AND exported = 1
     209            WHERE type IN ({$types_in}) AND exported = 1
    190210        ");
    191211
    192         // Return true only if all css/js assets are exported
     212        // Return true only if all assets are exported
    193213        return ((int) $total === (int) $exported);
    194214    }
  • export-wp-page-to-static-html/trunk/admin/includes/AjaxRequests/exportLogPercentage.php

    r3350057 r3379262  
    262262        return $wpdb->query($sql); // Returns number of affected rows
    263263    }
     264
    264265    public function are_all_assets_exported() {
    265266        global $wpdb;
    266267        $table = $wpdb->prefix . 'export_urls_logs';
    267268
    268         // Count total css/js assets
     269        // Build dynamic type condition
     270        $types = [];
     271       
     272        $skip = (array) $this->getSettings('skipAssetsFiles', array());
     273       
     274        if (!array_key_exists('stylesheets', $skip)) {
     275            $types[] = "'css'";
     276        }
     277       
     278        if (!array_key_exists('scripts', $skip)) {
     279            $types[] = "'js'";
     280        }
     281
     282        // If both skipped, nothing to check
     283        if (empty($types)) {
     284            return true;
     285        }
     286
     287        $types_in = implode(',', $types);
     288
     289        // Count total assets
    269290        $total = $wpdb->get_var("
    270291            SELECT COUNT(*)
    271292            FROM {$table}
    272             WHERE type IN ('css', 'js')
     293            WHERE type IN ({$types_in})
    273294        ");
    274295
    275         // If no css/js assets exist, return false (or change this to true if preferred)
     296        // If no matching assets exist
    276297        if ((int) $total === 0) {
    277298            return false;
    278299        }
    279300
    280         // Count how many of those have been exported
     301        // Count exported assets
    281302        $exported = $wpdb->get_var("
    282303            SELECT COUNT(*)
    283304            FROM {$table}
    284             WHERE type IN ('css', 'js') AND exported = 1
     305            WHERE type IN ({$types_in}) AND exported = 1
    285306        ");
    286307
    287         // Return true only if all css/js assets are exported
     308        // Return true only if all assets are exported
    288309        return ((int) $total === (int) $exported);
    289310    }
    290311
    291312
     313
    292314}
  • export-wp-page-to-static-html/trunk/admin/includes/data/data.php

    r3335694 r3379262  
    9090
    9191        public function handle_ajax() {
     92            $reason_key = isset($_POST['reason_key']) ? sanitize_text_field($_POST['reason_key']) : '';
     93
    9294            $data = [
    9395                'site_url'    => get_site_url(),
    94                 'reason_key'  => sanitize_text_field($_POST['reason_key']),
     96                'reason_key'  => $reason_key,
    9597                'feedback'    => sanitize_textarea_field($_POST['feedback']),
    9698                'wp_version'  => get_bloginfo('version'),
  • export-wp-page-to-static-html/trunk/admin/partials/sections/hidden-fields-and-js.php

    r3350057 r3379262  
    3535
    3636            selectBox.select2({
    37             placeholder: "Choose up to 3 pages",
     37            placeholder: "Choose up to 6 pages",
    3838            dropdownParent: selectDropdown,
    39             maximumSelectionLength: 3,
     39            maximumSelectionLength: 6,
    4040            language: {
    4141                maximumSelected: function (args) {
    42                 return "Maximum 3 pages can be selected. Upgrade to pro version to select unlimited pages.";
     42                return "Maximum 6 pages can be selected. Upgrade to pro version to select unlimited pages.";
    4343                }
    4444            },
  • export-wp-page-to-static-html/trunk/export-wp-page-to-static-html.php

    r3358063 r3379262  
    1010 * Plugin URI:        https://myrecorp.com
    1111 * Description:       Seamlessly export any WordPress page or post into lightweight, fully responsive static HTML/CSS and print-ready PDF with a single click. Boost your site’s performance and security by serving pre-rendered pages, create offline-friendly backups. Perfect for developers, content creators, and businesses needing fast, reliable exports of WordPress content.
    12  * Version:           4.3.2
     12 * Version:           4.3.3
    1313 * Author:            ReCorp
    1414 * Author URI:        https://www.upwork.com/fl/rayhan1
     
    5050    register_activation_hook( __FILE__, 'activate_export_wp_page_to_static_html' );
    5151
    52     if (!function_exists('run_export_wp_page_to_static_html')){
     52    if (!function_exists('run_export_wp_page_to_static_html_pro')){
    5353
    5454        /**
     
    5757         * Rename this for your plugin and update it as you release new versions.
    5858         */
    59         define( 'EXPORT_WP_PAGE_TO_STATIC_HTML_VERSION', '4.3.2' );
     59        define( 'EXPORT_WP_PAGE_TO_STATIC_HTML_VERSION', '4.3.3' );
    6060        define( 'EWPPTSH_PLUGIN_DIR_URL', plugin_dir_url(__FILE__) );
    6161        define( 'EWPPTSH_PLUGIN_DIR_PATH', plugin_dir_path(__FILE__) );
     
    118118        }
    119119        run_export_wp_page_to_static_html();
     120       
     121
     122        function wpptsh_error_log($log){
     123            if (EWPPTSH_DEVELOPER_MODE) {
     124                error_log($log);
     125            }
     126        }
     127        // On plugin activation (once), create/store a token
     128        register_activation_hook(__FILE__, function(){
     129            if (!get_option('ewptshp_worker_token')) {
     130                add_option('ewptshp_worker_token', wp_generate_password(32, false, false));
     131            }
     132        });
     133
     134        // Runs on every load, no __FILE__ here
     135        function wpptsh_update_db_check() {
     136            $installed_ver = get_option('wpptsh_db_version');
     137
     138            if ($installed_ver !=WPPTSH_DB_VERSION) {
     139                global $wpdb;
     140                $table_name = $wpdb->prefix . 'export_urls_logs';
     141
     142                // Add only missing column(s)
     143                $wpdb->query("ALTER TABLE $table_name ADD COLUMN type TINYTEXT NOT NULL");
     144
     145
     146                update_option('wpptsh_db_version', WPPTSH_DB_VERSION);
     147            }
     148           
     149        }
     150        add_action('plugins_loaded', 'wpptsh_update_db_check');
    120151    }
    121152
    122153//}
    123     function wpptsh_error_log($log){
    124         if (EWPPTSH_DEVELOPER_MODE) {
    125             error_log($log);
    126         }
    127     }
    128     // On plugin activation (once), create/store a token
    129     register_activation_hook(__FILE__, function(){
    130         if (!get_option('ewptshp_worker_token')) {
    131             add_option('ewptshp_worker_token', wp_generate_password(32, false, false));
    132         }
    133     });
    134 
    135     // Runs on every load, no __FILE__ here
    136     function wpptsh_update_db_check() {
    137         $installed_ver = get_option('wpptsh_db_version');
    138 
    139         if ($installed_ver !=WPPTSH_DB_VERSION) {
    140             global $wpdb;
    141             $table_name = $wpdb->prefix . 'export_urls_logs';
    142 
    143             // Add only missing column(s)
    144             $wpdb->query("ALTER TABLE $table_name ADD COLUMN type TINYTEXT NOT NULL");
    145 
    146 
    147             update_option('wpptsh_db_version', WPPTSH_DB_VERSION);
    148         }
    149        
    150     }
    151     add_action('plugins_loaded', 'wpptsh_update_db_check');
  • export-wp-page-to-static-html/trunk/includes/class-export-wp-page-to-static-html-activator.php

    r3357379 r3379262  
    3232    public static function activate() {
    3333
    34         if ( is_plugin_active( 'export-wp-page-to-static-html-pro-premium/export-wp-page-to-static-html.php' ) ) {
    35             deactivate_plugins( 'export-wp-page-to-static-html-pro-premium/export-wp-page-to-static-html.php' );
    36         }
    3734
    3835        global $wpdb;
     
    105102        }
    106103
     104        if ( is_plugin_active( 'export-wp-page-to-static-html-pro-premium/export-wp-page-to-static-html.php' ) ) {
     105            deactivate_plugins( 'export-wp-page-to-static-html-pro-premium/export-wp-page-to-static-html.php' );
     106        }
     107        elseif ( is_plugin_active( 'export-wp-page-to-static-html-pro/export-wp-page-to-static-html.php' ) ) {
     108            deactivate_plugins( 'export-wp-page-to-static-html-pro/export-wp-page-to-static-html.php' );
     109        }
    107110
    108111
Note: See TracChangeset for help on using the changeset viewer.