Plugin Directory

Changeset 3427414


Ignore:
Timestamp:
12/25/2025 05:42:43 PM (8 weeks ago)
Author:
pipdig
Message:

mu-plugin

Location:
blogger-importer-extended/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • blogger-importer-extended/trunk/bootstrap.php

    r3418466 r3427414  
    3939}
    4040
    41 // Import the first 15 images from post content to avoid timeout
     41// Import the first x images to avoid timeout
    4242if (!defined('BIE_IMAGE_IMPORT_LIMIT')) {
    4343    define('BIE_IMAGE_IMPORT_LIMIT', 15);
     
    6161// Plugin page links
    6262add_filter('plugin_action_links_'.plugin_basename(__FILE__), function($links) {
    63     $links[] = '<a href="'.admin_url('options-general.php?page=bie-settings').'">'.__('Run Importer').'</a>';
    64     $links[] = '<a href="'.admin_url('options-general.php?page=bie-settings#redirectsCard').'">301 Redirects</a>';
     63    $links[] = '<a href="'.esc_url(admin_url('options-general.php?page=bie-settings')).'">'.__('Run Importer').'</a>';
     64    $links[] = '<a href="'.esc_url(admin_url('options-general.php?page=bie-settings#redirectsCard')).'">301 Redirects</a>';
    6565    return $links;
    6666});
     
    7272    bie_create_database_tables();
    7373   
    74     if (!get_option('bie_installed_date')) {
    75         add_option('bie_installed_date', date('Y-m-d'));
    76     }
    77    
    7874    update_option('default_pingback_flag', '');
    7975    update_option('default_ping_status', 'closed');
     76   
     77    // Now we create mu-plugin which ensures all other plugins are disabled when importing content from Blogger (only impacts requests to AJAX from the BIE plugin)
     78   
     79    // Not on multisite
     80    if (is_multisite()) {
     81        return;
     82    }
     83   
     84    $mu_dir = WP_CONTENT_DIR.'/mu-plugins';
     85    $mu_file = $mu_dir.'/blogger-importer-extended-helper.php';
     86
     87    if (!is_dir($mu_dir)) {
     88        wp_mkdir_p($mu_dir);
     89    }
     90
     91    if (!is_dir($mu_dir) || !is_writable($mu_dir) || file_exists($mu_file)) {
     92        return;
     93    }
     94   
     95    $code = <<<'PHP'
     96<?php
     97/**
     98 * Plugin Name: Blogger Importer Extended - Helper
     99 * Description: Create as stable environment for importing content from Blogger. This mu-plugin is only used by the Blogger Importer Extended plugin and is removed when deactivated. If you are not longer using that plugin, you can delete this file.
     100 */
     101
     102if (!defined('DOING_AJAX') || !DOING_AJAX) {
     103    return;
     104}
     105
     106if (empty($_REQUEST['action']) || $_REQUEST['action'] !== 'bie_progress_ajax') {
     107    return;
     108}
     109
     110add_filter('option_active_plugins', function($plugins) {
     111   
     112    $allowed = array(
     113        'blogger-importer-extended/bootstrap.php',
     114    );
     115
     116    return array_values(array_intersect($plugins, $allowed));
     117   
     118});
     119PHP;
     120
     121    @file_put_contents($mu_file, $code);
    80122   
    81123});
     
    92134        delete_option($result->option_name);
    93135    }
     136   
     137    if (is_multisite()) {
     138        return;
     139    }
     140
     141    $mu_file = WP_CONTENT_DIR.'/mu-plugins/blogger-importer-extended-helper.php';
     142
     143    if (!file_exists($mu_file) || !is_writable($mu_file)) {
     144        return;
     145    }
     146   
     147    // Delete the mu-plugin created on activation
     148    @unlink($mu_file);
    94149   
    95150});
     
    149204    <div class="notice notice-success">
    150205        <h2>Blogger Importer</h2>
    151         <p>Thank you for installing Blogger Importer Extended! Please go to <a href="<?php echo admin_url('options-general.php?page=bie-settings'); ?>">this page</a> to get started.</p>
     206        <p>Thank you for installing Blogger Importer Extended! Please go to <a href="<?php echo esc_url(admin_url('options-general.php?page=bie-settings')); ?>">this page</a> to get started.</p>
    152207        <form action="" method="post">
    153208            <input type="hidden" value="1" name="bie_hide_setup_notice" />
    154209            <?php wp_nonce_field('sec', 'bie_hide_setup_notice_nonce'); ?>
    155210            <p class="submit" style="margin-top: 5px; padding-top: 5px;">
    156                 <a href="<?php echo admin_url('options-general.php?page=bie-settings'); ?>" class="button button-primary" style="margin-right: 5px;">Get Started</a> <input name="submit" class="button" value="Remove this notice" type="submit" />
     211                <a href="<?php echo esc_url(admin_url('options-general.php?page=bie-settings')); ?>" class="button button-primary" style="margin-right: 5px;">Get Started</a> <input name="submit" class="button" value="Remove this notice" type="submit" />
    157212            </p>
    158213        </form>
     
    243298    jQuery(document).ready(function($) {
    244299       
    245         $('#wpwrap').before('<div id="pipdigBloggerImporter"><a id="pipdigBloggerClose" href="<?php echo admin_url('options-general.php?page=bie-settings'); ?>" title="Return to dashboard"><span class="dashicons dashicons-no-alt"></span></a><div id="pipdigBloggerImporterContent"><img src="<?php echo BIE_PATH; ?>img/boxes.svg" alt="" class="fade_out" style="width:150px" /><h2 class="fade_out">Welcome to the Blogger Importer!</h2><div id="bieLicenseChoices"><p>The free version of this plugin can import up to 20 blog posts and pages.</p><p>Alternatively you can purchase an <a href="https://go.pipdig.co/open.php?id=bie-pro" target="_blank" rel="noopener">unlimited license</a> for unlimited posts, pages, comments and images.</p><p>Read more about the differences <a href="https://go.pipdig.co/open.php?id=bie-pro" target="_blank" rel="noopener">here</a>.</p><div style="margin-top:20px"><div class="button" id="bieFreeBtn">20 posts for free</div> <div class="button button-primary" id="bieProBtn">Unlimited license</div></div></div><div id="blogLicenseStep" class="fade_out" style="display:none"><p class="fade_out" style="margin-bottom: 20px;">What is your license key? License keys an be purchased <a href="https://go.pipdig.co/open.php?id=bie-pro" target="_blank" rel="noopener">here</a>.</p><input type="text" value="" class="wide-fat fade_out" style="width:320px;max-width:100%;" id="bieLicenseField"> <input type="button" value="<?php echo esc_attr(__('Submit')); ?>" class="button button-primary fade_out" id="bieLicenseSubmit"><div id="bieCheckingLicense" style="display: none; margin-top: 10px;"><span class="dashicons dashicons-update spin"></span> Checking License...</div><div id="bieCheckingLicenseResult" style="margin-top: 10px;"></div></div><div id="blogIdStep" class="fade_out" style="display:none"><p><span id="bieLicenseSuccessMsg"></span>Please enter your Blog\'s ID in the option below. You can find your Blog ID like <a href="<?php echo BIE_PATH; ?>img/find_blog_id.png" target="_blank" rel="noopener">this example</a>.</p><p style="margin-bottom: 20px;"><span class="dashicons dashicons-warning"></span> Please note that Blogger settings must be <a href="<?php echo BIE_PATH; ?>img/blogger_public.png" target="_blank" rel="noopener">Public</a> during the import.</p><input type="text" value="" class="wide-fat fade_out" style="width:320px;max-width:100%;" id="BlogggerBlogIdField" placeholder="Blog ID should be a number"> <input type="button" value="<?php echo esc_attr(__('Submit')); ?>" class="button button-primary fade_out" id="submitBlogId"></div><div id="pipdigBloggerImpoterMsg1"></div><p id="postImportProgress"></p></div></div><div id="totalPostCount" style="display:none"></div><div id="lastUpdateCountdown" style="display:none"></div>');
     300        $('#wpwrap').before('<div id="pipdigBloggerImporter"><a id="pipdigBloggerClose" href="<?php echo esc_url(admin_url('options-general.php?page=bie-settings')); ?>" title="Return to dashboard"><span class="dashicons dashicons-no-alt"></span></a><div id="pipdigBloggerImporterContent"><img src="<?php echo BIE_PATH; ?>img/boxes.svg" alt="" class="fade_out" style="width:150px" /><h2 class="fade_out">Welcome to the Blogger Importer!</h2><div id="bieLicenseChoices"><p>The free version of this plugin can import up to 20 blog posts and pages.</p><p>Alternatively you can purchase an <a href="https://go.pipdig.co/open.php?id=bie-pro" target="_blank" rel="noopener">unlimited license</a> for unlimited posts, pages, comments and images.</p><p>Read more about the differences <a href="https://go.pipdig.co/open.php?id=bie-pro" target="_blank" rel="noopener">here</a>.</p><div style="margin-top:20px"><div class="button" id="bieFreeBtn">20 posts for free</div> <div class="button button-primary" id="bieProBtn">Unlimited license</div></div></div><div id="blogLicenseStep" class="fade_out" style="display:none"><p class="fade_out" style="margin-bottom: 20px;">What is your license key? License keys an be purchased <a href="https://go.pipdig.co/open.php?id=bie-pro" target="_blank" rel="noopener">here</a>.</p><input type="text" value="" class="wide-fat fade_out" style="width:320px;max-width:100%;" id="bieLicenseField"> <input type="button" value="<?php echo esc_attr(__('Submit')); ?>" class="button button-primary fade_out" id="bieLicenseSubmit"><div id="bieCheckingLicense" style="display: none; margin-top: 10px;"><span class="dashicons dashicons-update spin"></span> Checking License...</div><div id="bieCheckingLicenseResult" style="margin-top: 10px;"></div></div><div id="blogIdStep" class="fade_out" style="display:none"><p><span id="bieLicenseSuccessMsg"></span>Please enter your Blog\'s ID in the option below. You can find your Blog ID like <a href="<?php echo BIE_PATH; ?>img/find_blog_id.png" target="_blank" rel="noopener">this example</a>.</p><p style="margin-bottom: 20px;"><span class="dashicons dashicons-warning"></span> Please note that Blogger settings must be <a href="<?php echo BIE_PATH; ?>img/blogger_public.png" target="_blank" rel="noopener">Public</a> during the import.</p><input type="text" value="" class="wide-fat fade_out" style="width:320px;max-width:100%;" id="BlogggerBlogIdField" placeholder="Blog ID should be a number"> <input type="button" value="<?php echo esc_attr(__('Submit')); ?>" class="button button-primary fade_out" id="submitBlogId"></div><div id="pipdigBloggerImpoterMsg1"></div><p id="postImportProgress"></p></div></div><div id="totalPostCount" style="display:none"></div><div id="lastUpdateCountdown" style="display:none"></div>');
    246301       
    247302        var bieLicenseField = $('#bieLicenseField');
     
    317372                    $('#bieCheckingLicenseResult').html('This license has expired. Would you like to <a href="https://go.pipdig.co/open.php?id=bie-pro" target="_blank" rel="noopener">purchase a new one</a>?');
    318373                } else if (response == 3) {
    319                     $('#bieCheckingLicenseResult').html('This license does not exist. Please check your email receipt for the license key or <a href="<?php echo admin_url('tools.php?page=bie-importer'); ?>">click here</a> to restart the import process.');
     374                    $('#bieCheckingLicenseResult').html('This license does not exist. Please check your email receipt for the license key or <a href="<?php echo esc_url(admin_url('tools.php?page=bie-importer')); ?>">click here</a> to restart the import process.');
    320375                } else {
    321376                   
     
    453508                $('.fade_out').addClass('pipdig_hide');
    454509                importPostsBtn.addClass('pipdig_hide');
    455                 message.html('<img src="<?php echo BIE_PATH; ?>img/moving.svg" alt="" style="width: 150px;" /><h2><span class="dashicons dashicons-update spin"></span> Importing, Please wait...</h2><p>Please <strong>keep this window open</strong>.</p><p>'+importingTimeNotice+'</p><div style="margin-top: 25px"><a href="<?php echo admin_url('tools.php?page=bie-importer'); ?>&bid='+BlogggerBlogIdField.val()+'" class="button fade_out" id="stopImport"><span class="dashicons dashicons-no" style="margin-top: 4px;"></span> Stop the import!</a></div>');
     510                message.html('<img src="<?php echo BIE_PATH; ?>img/moving.svg" alt="" style="width: 150px;" /><h2><span class="dashicons dashicons-update spin"></span> Importing, Please wait...</h2><p>Please <strong>keep this window open</strong>.</p><p>'+importingTimeNotice+'</p><div style="margin-top: 25px"><a href="<?php echo esc_url(admin_url('tools.php?page=bie-importer')); ?>&bid='+BlogggerBlogIdField.val()+'" class="button fade_out" id="stopImport"><span class="dashicons dashicons-no" style="margin-top: 4px;"></span> Stop the import!</a></div>');
    456511               
    457512                importPosts('', 0, skipComments, skipImages, skipPages, skipAuthors, convertFormatting);
     
    509564                    console.log(response);
    510565                    if (response.includes("https://go.pipdig.co/open.php?id=2")) {
    511                         message.html('<img src="<?php echo BIE_PATH; ?>img/battery_low.svg" alt="" style="width: 150px;" />'+response+'<p style="margin-top: 20px"><a class="button" href="<?php echo admin_url('options-general.php?page=bie-settings'); ?>">Return to dashboard</a></p>');
     566                        message.html('<img src="<?php echo BIE_PATH; ?>img/battery_low.svg" alt="" style="width: 150px;" />'+response+'<p style="margin-top: 20px"><a class="button" href="<?php echo esc_url(admin_url('options-general.php?page=bie-settings')); ?>">Return to dashboard</a></p>');
    512567                    } else {
    513                         message.html('<img src="<?php echo BIE_PATH; ?>img/broken.svg" alt="" style="width: 150px;" /><h2>Connection lost</h2><p>It looks like the importer has stopped working. Don\'t worry though, any progress was not lost! Click the button below to continue.</p><p>Are you seeing this message a lot? <a href="https://support.pipdig.co/articles/blogger-importer-extended-faq/" target="_blank" rel="noopener">Click here</a> for some tips for easier migrations.</p><p style="margin-top: 20px"><a class="button-primary" href="<?php echo admin_url('tools.php?page=bie-importer'); ?>&bid='+BlogggerBlogIdField.val()+'">Continue Importer</a></p>');
     568                        message.html('<img src="<?php echo BIE_PATH; ?>img/broken.svg" alt="" style="width: 150px;" /><h2>Connection lost</h2><p>It looks like the importer has stopped working. Don\'t worry though, any progress was not lost! Click the button below to continue.</p><p>Are you seeing this message a lot? <a href="https://support.pipdig.co/articles/blogger-importer-extended-faq/" target="_blank" rel="noopener">Click here</a> for some tips for easier migrations.</p><p style="margin-top: 20px"><a class="button-primary" href="<?php echo esc_url(admin_url('tools.php?page=bie-importer')); ?>&bid='+BlogggerBlogIdField.val()+'">Continue Importer</a></p>');
    514569                    }
    515570                    window.onbeforeunload = null; // Remove navigation prompt
     
    530585                    $('#lastUpdateCountdown').text('180');
    531586                   
    532                     /*
    533                     if (resp.latest_imported_id != '' && resp.latest_imported_title != '' && resp.total_posts != 0) {
    534                         $('#postImportProgress').html('<h2>Status Update:</h2>There are now <strong>'+resp.total_posts+'</strong> <a href="<?php echo admin_url('edit.php'); ?>" target="_blank" rel="noopener">blog posts</a> in WordPress.<br /><br />Last item imported:<br /><br /><a href="<?php echo trailingslashit(admin_url()); ?>post.php?post=' + resp.latest_imported_id + '&action=edit" target="_blank" rel="noopener" style="text-decoration:none">' + resp.latest_imported_title + '</a>');
    535                     }
    536                     */
    537                    
    538587                    if (typeof resp.total_posts !== 'undefined' && resp.total_posts != 0) {
    539588                        var time = new Date();
    540589                        var currentTime = time.toLocaleString('en-US', {hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: true});
    541                         $('#postImportProgress').html('<h2>Status Update:</h2><span style="font-style:italic">'+currentTime+': There are <strong>'+resp.total_posts+'</strong> <a href="<?php echo admin_url('edit.php'); ?>" target="_blank" rel="noopener">blog posts</a> in WordPress.</span>');
     590                        $('#postImportProgress').html('<h2>Status Update:</h2><span style="font-style:italic">'+currentTime+': There are <strong>'+resp.total_posts+'</strong> <a href="<?php echo esc_url(admin_url('edit.php')); ?>" target="_blank" rel="noopener">blog posts</a> in WordPress.</span>');
    542591                    }
    543592                   
     
    553602                    $('#lastUpdateCountdown').text('');
    554603                    $('#postImportProgress').text('');
    555                     message.html('<img src="<?php echo BIE_PATH; ?>img/success.svg" alt="" style="width: 150px;" /><h2>Success!</h2><p>All content was imported successfully.</p><p>What now? Don\'t forget to setup the <a href="<?php echo admin_url('options-general.php?page=bie-settings'); ?>">remaining steps</a>.</p><p style="margin-top: 20px"><a class="button" href="<?php echo admin_url('options-general.php?page=bie-settings'); ?>">Return to dashboard</a></p>');
     604                    message.html('<img src="<?php echo BIE_PATH; ?>img/success.svg" alt="" style="width: 150px;" /><h2>Success!</h2><p>All content was imported successfully.</p><p>What now? Don\'t forget to setup the <a href="<?php echo esc_url(admin_url('options-general.php?page=bie-settings')); ?>">remaining steps</a>.</p><p style="margin-top: 20px"><a class="button" href="<?php echo esc_url(admin_url('options-general.php?page=bie-settings')); ?>">Return to dashboard</a></p>');
    556605                    $('.fade_out').slideUp(550);
    557606                   
     
    579628                if (counter === 0) {
    580629                    window.onbeforeunload = null; // Remove navigation prompt
    581                     message.html('<img src="<?php echo BIE_PATH; ?>img/broken.svg" alt="" style="width: 150px;" /><h2>Connection lost</h2><p>It looks like the importer has stopped unexpectedly. Don\'t worry though, any progress was not lost! Click the button below to continue the current import.</p><p>Are you seeing this message a lot? <a href="https://support.pipdig.co/articles/blogger-importer-extended-faq/" target="_blank" rel="noopener">Click here</a> for some tips for easier migrations.</p><p style="margin-top: 20px"><a class="button-primary" href="<?php echo admin_url('tools.php?page=bie-importer'); ?>&bid='+BlogggerBlogIdField.val()+'">Continue Importer</a></p>');
     630                    message.html('<img src="<?php echo BIE_PATH; ?>img/broken.svg" alt="" style="width: 150px;" /><h2>Connection lost</h2><p>It looks like the importer has stopped unexpectedly. Don\'t worry though, any progress was not lost! Click the button below to continue the current import.</p><p>Are you seeing this message a lot? <a href="https://support.pipdig.co/articles/blogger-importer-extended-faq/" target="_blank" rel="noopener">Click here</a> for some tips for easier migrations.</p><p style="margin-top: 20px"><a class="button-primary" href="<?php echo esc_url(admin_url('tools.php?page=bie-importer')); ?>&bid='+BlogggerBlogIdField.val()+'">Continue Importer</a></p>');
    582631                    $('#lastUpdateCountdown').text('');
    583632                    return;
     
    727776        } else {
    728777            // no previous import found
    729             echo '<div class="button button-primary fade_out" id="startImport" style="margin-top: 10px" data-total-posts="'.absint($response->posts).'"><span class="dashicons dashicons-controls-play" style="margin-top: 4px;"></span> Start import!</div> &nbsp;<a href="'.admin_url('tools.php?page=bie-importer').'" class="button fade_out" style="margin-top: 10px">Cancel</a>';
     778            echo '<div class="button button-primary fade_out" id="startImport" style="margin-top: 10px" data-total-posts="'.absint($response->posts).'"><span class="dashicons dashicons-controls-play" style="margin-top: 4px;"></span> Start import!</div> &nbsp;<a href="'.esc_url(admin_url('tools.php?page=bie-importer')).'" class="button fade_out" style="margin-top: 10px">Cancel</a>';
    730779        }
    731780       
     
    794843    wp_defer_term_counting(true);
    795844    wp_defer_comment_counting(true);
    796     remove_action('post_updated', 'wp_save_post_revision');
    797     add_filter('intermediate_image_sizes_advanced', 'pipdig_blogger_skip_image_sizes'); // disable image sizes from generating, temporarily whilst uploading
     845    add_filter('intermediate_image_sizes_advanced', '__return_empty_array');
     846    add_filter('big_image_size_threshold', '__return_false');
    798847   
    799848    if (!defined('WP_IMPORTING')) define('WP_IMPORTING', true);
     
    869918                    );
    870919                    $wpdb->insert($wpdb->prefix.'bie_redirects', $row, $formats);
    871                    
    872                     /*
    873                     $title = get_the_title($post_id);
    874                     $latest_imported_title = html_entity_decode($title, ENT_QUOTES, 'UTF-8'); // convert chars like & https://stackoverflow.com/a/6684000
    875                     $latest_imported_id = $post_id;
    876                     */
    877920                   
    878921                } else {
     
    9631006   
    9641007    wp_suspend_cache_invalidation(false);
    965     wp_defer_term_counting(false);
    966     wp_defer_comment_counting(false);
    967     add_action('post_updated', 'wp_save_post_revision');
    968     remove_filter('intermediate_image_sizes_advanced', 'pipdig_blogger_skip_image_sizes'); // return image sizes to normal after
    9691008   
    9701009    $total_posts = (int) $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = 'post'");
     
    9731012        'next_page' => $next_page_token,
    9741013        'posts_imported' => $x,
    975         //'latest_imported_title' => !empty($latest_imported_title) ? strip_tags($latest_imported_title) : '',
    976         //'latest_imported_id' => !empty($latest_imported_id) ? strip_tags($latest_imported_id) : '',
    9771014        'total_posts' => $total_posts,
    9781015    );
     
    11081145    }
    11091146   
    1110 }
    1111 
    1112 function pipdig_blogger_skip_image_sizes($sizes) {
    1113     return array();
    11141147}
    11151148
     
    12511284    }
    12521285   
    1253     // Add lazy load and srcset if supported
    1254     /*
    1255     if (function_exists('wp_filter_content_tags')) {
    1256         $content = wp_filter_content_tags($content);
    1257     }
    1258     */
    1259    
    12601286    return array(
    12611287        'content' => $content,
  • blogger-importer-extended/trunk/uninstall.php

    r3418466 r3427414  
    88delete_option('bie_license');
    99delete_option('bie_hide_setup_notice');
     10delete_option('bie_installed_date');
    1011
    1112global $wpdb;
     
    1415    delete_option($result->option_name);
    1516}
    16 
    17 /*
    18 // Do we want to delete the redirects on uninstall? Maybe not
    19 global $wpdb;
    20 $table_name = $wpdb->prefix.'bie_redirects';
    21 $wpdb->query("DROP TABLE IF EXISTS $table_name");
    22 */
Note: See TracChangeset for help on using the changeset viewer.