Make WordPress Core


Ignore:
Timestamp:
09/20/2005 03:17:43 AM (21 years ago)
Author:
ryan
Message:

wp_insert_comment(), wp_update_comment(), wp_allow_comment(), and wp_filter_comment() from skeltoac. fixes #1683

File:
1 edited

Legend:

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

    r2880 r2894  
    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 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>
     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>
    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                 return "<html><head><script type='text/javascript'>window.onload=setInterval('window.location.reload()', $msec);</script>\n</head>\n<body>";
     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";
    4144        }
    4245
     
    7982                curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
    8083                curl_setopt($ch, CURLOPT_URL,$_url);
    81                 curl_setopt($ch, CURLOPT_USERAGENT, 'Developing Blogger Exporter');
     84                curl_setopt($ch, CURLOPT_USERAGENT, 'Blogger Exporter');
    8285                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    8386                curl_setopt($ch, CURLOPT_HEADER,1);
     
    99102                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    100103                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     104                curl_setopt($ch, CURLOPT_USERAGENT, 'Blogger Exporter');
    101105                curl_setopt($ch, CURLOPT_HEADER,1);
    102106                if (is_array($header)) curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
     
    131135                if ($user && $pass) curl_setopt($ch, CURLOPT_USERPWD,"{$user}:{$pass}");
    132136                curl_setopt($ch, CURLOPT_URL,$url);
    133                 curl_setopt($ch, CURLOPT_USERAGENT, 'Developing Blogger Exporter');
     137                curl_setopt($ch, CURLOPT_USERAGENT, 'Blogger Exporter');
    134138                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    135139                curl_setopt($ch, CURLOPT_HEADER,$parse);
     
    166170
    167171        // Publishes.
    168         function publish_blogger($i) {
     172        function publish_blogger($i, $text) {
     173                $head = $this->refresher(1000) . "<h1>$text</h1>\n";
    169174                if ( ! $this->import['blogs'][$_GET['blog']]['publish'][$i] ) {
    170175                        // First call. Start the publish process.
     
    178183                                if ( preg_match('#<p class="progressIndicator">.*</p>#U', $response['body'], $matches) ) {
    179184                                        $progress = $matches[0];
    180                                         die($progress);
     185                                        die($head . $progress);
    181186                                } else {
    182187                                        echo "matches:<pre>" . print_r($matches,1) . "</pre>\n";
    183188                                }
    184189                        } else {
    185                                 echo "<h1>Publish error: No 302</h1><p>Please tell the devs.</p><pre>" . addslashes(print_r($response,1)) . "</pre>\n";
     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                                }
    186197                        }
    187198                        die();
     
    194205                                if ( strstr($progress, '100%') )
    195206                                        $this->set_next_step($i);
    196                                 die($progress);
     207                                die($head . $progress);
    197208                        } else {
    198209                                echo "<h1>Publish error: No matches</h1><p>Please tell the devs.</p><pre>" . print_r($matches,1) . "</pre>\n";
     
    271282                                        'published' => false,
    272283                                        'archives' => false,
    273                                         'newusers' => array(),
    274284                                        'lump_authors' => false,
    275285                                        'newusers' => 0,
     
    368378        // Step 3: Publish with the new template and settings.
    369379        function publish_blog() {
    370                 echo $this->refresher(2400) . "<h1>Publishing with new template and options</h1>\n";
    371                 $this->publish_blogger(5);
     380                $this->publish_blogger(5, 'Publishing with new template and options');
    372381        }
    373382
     
    403412                                $commentcount = 0;
    404413                                $skippedcommentcount = 0;
    405                                 $status = '';
     414                                $status = 'in progress...';
     415                                $this->import['blogs'][$_GET['blog']]['archives']["$url"] = $status;
     416                                update_option('import-blogger', $import);
    406417                                $archive = implode('',file($url));
    407418       
     
    417428                                        //$post_number = $postinfo[3];
    418429                                        $post_title = ( $postinfo[4] != '' ) ? $postinfo[4] : $postinfo[3];
    419                                         $post_author = trim($wpdb->escape($postinfo[1]));
    420                                         $post_author_name = trim(addslashes($postinfo[1]));
     430                                        $post_author_name = $wpdb->escape(trim($postinfo[1]));
    421431                                        $post_author_email = $postinfo[5] ? $postinfo[5] : 'no@email.com';
    422432       
     
    465475                                        $post_status = 'publish';
    466476       
    467                                         if ( post_exists($post_title, '', $post_date) ) {
     477                                        if ( $comment_post_ID = post_exists($post_title, '', $post_date) ) {
    468478                                                $skippedpostcount++;
    469                                                 $comment_post_ID = $dupcheck[0]['ID'];
    470479                                        } else {
    471480                                                $post_array = compact('post_author', 'post_content', 'post_title', 'post_category', 'post_author', 'post_date', 'post_status');
     
    491500                                                        $commenthour = '00';
    492501                                                $comment_date = "$commentyear-$commentmonth-$commentday $commenthour:$commentminute:$commentsecond";
    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.
     502                                                $comment_author = addslashes(strip_tags(html_entity_decode($commentinfo[1])));
    494503                                                if ( strpos($commentinfo[1], 'a href') ) {
    495504                                                        $comment_author_parts = explode('&quot;', htmlentities($commentinfo[1]));
    496505                                                        $comment_author_url = $comment_author_parts[1];
    497506                                                } else $comment_author_url = '';
    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) ) {
     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) ) {
    501511                                                        $skippedcommentcount++;
    502512                                                } else {
    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                                                 ");
     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++;
    509516                                                }
    510517                                                $commentcount++;
     
    523530                if ( ! $did_one )
    524531                        $this->set_next_step(7);
    525                 die( $this->refresher(5000) . $output );
     532                die( $this->refresher(1000) . $output );
    526533        }
    527534
     
    569576        // Step 8: Republish, all back to normal
    570577        function republish_blog() {
    571                 echo $this->refresher(2400) . "<h1>Publishing with original template and options</h1>\n";
    572                 $this->publish_blogger(9);
     578                $this->publish_blogger(9, 'Publishing with original template and options');
    573579        }
    574580
     
    582588                if ( count($this->import['blogs']) > 1 )
    583589                        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";
    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";
     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";
    586592               
    587593                echo "\n<ul>";
     
    596602                if ( isset($_GET['noheader']) ) {
    597603                        $this->import = get_settings('import-blogger');
     604
     605                        ob_start();
    598606
    599607                        if ( isset($_GET['step']) ) {
     
    606614                                $step = 0;
    607615                        }
     616
    608617                        switch ($step) {
    609618                                case 0 :
Note: See TracChangeset for help on using the changeset viewer.