Make WordPress Core


Ignore:
Timestamp:
10/01/2005 11:29:03 AM (21 years ago)
Author:
ryan
Message:

Blogger importer updates from skeltoac. fixes #1722

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/import/blogger.php

    r2894 r2928  
    2222                echo '<h2>'.__('Import Blogger').'</h2>';
    2323                _e("<p>Howdy! This importer allows you to import posts and comments from your Blogger account into your WordPress blog.</p>
    24 <p>Before you get started, you should <u>back up your Blogger template</u> by copying and pasting it into a text file on your computer. This script has to modify your template and other Blogger settings so it can get your posts and comments. It should restore everything afterwards but if you have put a lot of work into your template, it would be a good idea to make your own backup first.</p>
     24<p>Before you get started, you may want to back up your Blogger template by copying and pasting it into a text file on your computer. This script has to modify your template and other Blogger settings so it can get your posts and comments. It should restore everything afterwards but if you have put a lot of work into your template, it would be a good idea to make your own backup first.</p>
    2525<p>When you are ready to begin, enter your Blogger username and password below and click Start. Do not close this window until the process is complete.</p>");
    2626                echo "<iframe src='admin.php?import=blogger&noheader=true' height='350px' width = '99%'></iframe>";
     
    3838        // Generates a string that will make the page reload in a specified interval.
    3939        function refresher($msec) {
    40                 if ( $msec )
    41                         return "<html><head><script type='text/javascript'>window.onload=setTimeout('window.location.reload()', $msec);</script>\n</head>\n<body>\n";
    42                 else
    43                         return "<html><head><script type='text/javascript'>window.onload=window.location.reload();</script>\n</head>\n<body>\n";
     40                return "<html><head><script type='text/javascript'>window.onload=setInterval('window.location.reload()', $msec);</script>\n</head>\n<body>";
    4441        }
    4542
     
    8279                curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
    8380                curl_setopt($ch, CURLOPT_URL,$_url);
    84                 curl_setopt($ch, CURLOPT_USERAGENT, 'Blogger Exporter');
     81                curl_setopt($ch, CURLOPT_USERAGENT, 'Developing Blogger Exporter');
    8582                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    8683                curl_setopt($ch, CURLOPT_HEADER,1);
     
    10299                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    103100                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    104                 curl_setopt($ch, CURLOPT_USERAGENT, 'Blogger Exporter');
    105101                curl_setopt($ch, CURLOPT_HEADER,1);
    106102                if (is_array($header)) curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
     
    135131                if ($user && $pass) curl_setopt($ch, CURLOPT_USERPWD,"{$user}:{$pass}");
    136132                curl_setopt($ch, CURLOPT_URL,$url);
    137                 curl_setopt($ch, CURLOPT_USERAGENT, 'Blogger Exporter');
     133                curl_setopt($ch, CURLOPT_USERAGENT, 'Developing Blogger Exporter');
    138134                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    139135                curl_setopt($ch, CURLOPT_HEADER,$parse);
     
    170166
    171167        // Publishes.
    172         function publish_blogger($i, $text) {
    173                 $head = $this->refresher(1000) . "<h1>$text</h1>\n";
     168        function publish_blogger($i) {
    174169                if ( ! $this->import['blogs'][$_GET['blog']]['publish'][$i] ) {
    175170                        // First call. Start the publish process.
     
    183178                                if ( preg_match('#<p class="progressIndicator">.*</p>#U', $response['body'], $matches) ) {
    184179                                        $progress = $matches[0];
    185                                         die($head . $progress);
     180                                        die($progress);
    186181                                } else {
    187182                                        echo "matches:<pre>" . print_r($matches,1) . "</pre>\n";
    188183                                }
    189184                        } else {
    190                                 if ( strstr($response['body'], 'Please sign in before proceeding') ) {
    191                                         $this->import['cookies'] = $this->login_blogger($this->import['user'], $this->import['pass']);
    192                                         update_option('import-blogger', $this->import);
    193                                         die($this->refresher(500) . "<h1>Logging into Blogger again...</h1>");
    194                                 } else {
    195                                         echo "<h1>Publish error: No 302</h1><p>Please tell the devs.</p><pre>" . addslashes(print_r($response,1)) . "</pre>\n";
    196                                 }
     185                                echo "<h1>Publish error: No 302</h1><p>Please tell the devs.</p><pre>" . addslashes(print_r($response,1)) . "</pre>\n";
    197186                        }
    198187                        die();
     
    205194                                if ( strstr($progress, '100%') )
    206195                                        $this->set_next_step($i);
    207                                 die($head . $progress);
     196                                die($progress);
    208197                        } else {
    209198                                echo "<h1>Publish error: No matches</h1><p>Please tell the devs.</p><pre>" . print_r($matches,1) . "</pre>\n";
     
    282271                                        'published' => false,
    283272                                        'archives' => false,
     273                                        'newusers' => array(),
    284274                                        'lump_authors' => false,
    285275                                        'newusers' => 0,
     
    378368        // Step 3: Publish with the new template and settings.
    379369        function publish_blog() {
    380                 $this->publish_blogger(5, 'Publishing with new template and options');
     370                echo $this->refresher(2400) . "<h1>Publishing with new template and options</h1>\n";
     371                $this->publish_blogger(5);
    381372        }
    382373
     
    412403                                $commentcount = 0;
    413404                                $skippedcommentcount = 0;
    414                                 $status = 'in progress...';
    415                                 $this->import['blogs'][$_GET['blog']]['archives']["$url"] = $status;
    416                                 update_option('import-blogger', $import);
     405                                $status = '';
    417406                                $archive = implode('',file($url));
    418407       
     
    428417                                        //$post_number = $postinfo[3];
    429418                                        $post_title = ( $postinfo[4] != '' ) ? $postinfo[4] : $postinfo[3];
    430                                         $post_author_name = $wpdb->escape(trim($postinfo[1]));
     419                                        $post_author = trim($wpdb->escape($postinfo[1]));
     420                                        $post_author_name = trim(addslashes($postinfo[1]));
    431421                                        $post_author_email = $postinfo[5] ? $postinfo[5] : 'no@email.com';
    432422       
     
    475465                                        $post_status = 'publish';
    476466       
    477                                         if ( $comment_post_ID = post_exists($post_title, '', $post_date) ) {
     467                                        if ( post_exists($post_title, '', $post_date) ) {
    478468                                                $skippedpostcount++;
     469                                                $comment_post_ID = $dupcheck[0]['ID'];
    479470                                        } else {
    480471                                                $post_array = compact('post_author', 'post_content', 'post_title', 'post_category', 'post_author', 'post_date', 'post_status');
     
    500491                                                        $commenthour = '00';
    501492                                                $comment_date = "$commentyear-$commentmonth-$commentday $commenthour:$commentminute:$commentsecond";
    502                                                 $comment_author = addslashes(strip_tags(html_entity_decode($commentinfo[1])));
     493                                                $comment_author = addslashes(strip_tags(html_entity_decode($commentinfo[1]))); // Believe it or not, Blogger allows a user to call himself "Mr. Hell's Kitchen" which, as a string, really confuses SQL.
    503494                                                if ( strpos($commentinfo[1], 'a href') ) {
    504495                                                        $comment_author_parts = explode('&quot;', htmlentities($commentinfo[1]));
    505496                                                        $comment_author_url = $comment_author_parts[1];
    506497                                                } else $comment_author_url = '';
    507                                                 $comment_content = $commentinfo[2];
    508                                                 $comment_content = str_replace(array('<br>','<BR>','<br/>','<BR/>','<br />','<BR />'), "\n", $comment_content);
    509                                                 $comment_approved = 1;
    510                                                 if ( comment_exists($comment_author, $comment_date) ) {
     498                                                $comment_content = addslashes($commentinfo[2]);
     499                                                $comment_content = str_replace('<br>', '<br />', $comment_content);
     500                                                if ( $comment_post_ID == comment_exists($comment_author, $comment_date) ) {
    511501                                                        $skippedcommentcount++;
    512502                                                } else {
    513                                                         $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_date', 'comment_content', 'comment_approved');
    514                                                         $commentdata = wp_filter_comment($commentdata);
    515                                                         if ( false == wp_insert_comment($commentdata) ) $skippedcommentcount++;
     503                                                        $result = $wpdb->query("
     504                                                        INSERT INTO $wpdb->comments
     505                                                        (comment_post_ID,comment_author,comment_author_url,comment_date,comment_content)
     506                                                        VALUES
     507                                                                ('$comment_post_ID','$comment_author','$comment_author_url','$comment_date','$comment_content')
     508                                                ");
    516509                                                }
    517510                                                $commentcount++;
     
    530523                if ( ! $did_one )
    531524                        $this->set_next_step(7);
    532                 die( $this->refresher(1000) . $output );
     525                die( $this->refresher(5000) . $output );
    533526        }
    534527
     
    576569        // Step 8: Republish, all back to normal
    577570        function republish_blog() {
    578                 $this->publish_blogger(9, 'Publishing with original template and options');
     571                echo $this->refresher(2400) . "<h1>Publishing with original template and options</h1>\n";
     572                $this->publish_blogger(9);
    579573        }
    580574
     
    588582                if ( count($this->import['blogs']) > 1 )
    589583                        echo "<li>In case you haven't done it already, you can import the posts from any other blogs you may have:" . $this->show_blogs() . "</li>\n";
    590                 if ( $n = $this->import['blogs'][$_GET['blog']]['newusers'] )
    591                         echo "<li>Since we had to create $n new user" . ( $n > 1 ? 's' : '' ) . ", you probably want to go to <a href='users.php' target='_parent'>Authors & Users</a>, where you can give them new passwords or delete them. If you want to make all of the imported posts yours, you will be given that option when you delete the new authors.</li>\n";
     584                if ( $n = count($this->import['blogs'][$_GET['blog']]['newusers']) )
     585                        echo "<li>Since we had to create $n new users, you probably want to go to <a href='users.php' target='_parent'>Authors & Users</a>, where you can give them new passwords or delete them. If you want to make all of the imported posts yours, you will be given that option when you delete the new authors.</li>\n";
    592586               
    593587                echo "\n<ul>";
     
    602596                if ( isset($_GET['noheader']) ) {
    603597                        $this->import = get_settings('import-blogger');
    604 
    605                         ob_start();
    606598
    607599                        if ( isset($_GET['step']) ) {
     
    614606                                $step = 0;
    615607                        }
    616 
    617608                        switch ($step) {
    618609                                case 0 :
Note: See TracChangeset for help on using the changeset viewer.