]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/import/blogger.php
Wordpress 2.7.1
[autoinstalls/wordpress.git] / wp-admin / import / blogger.php
index b518cd73a8379564aff4ab06027047a37fd7ba89..0879cd11b0cb4ad96654f0b03618ae57786a8f8b 100644 (file)
@@ -1,26 +1,66 @@
 <?php
-
-define( 'MAX_RESULTS',        50 ); // How many records per GData query
-define( 'MAX_EXECUTION_TIME', 20 ); // How many seconds to let the script run
-define( 'STATUS_INTERVAL',     3 ); // How many seconds between status bar updates
-
+/**
+ * Blogger Importer
+ *
+ * @package WordPress
+ * @subpackage Importer
+ */
+
+/**
+ * How many records per GData query
+ *
+ * @package WordPress
+ * @subpackage Blogger_Import
+ * @var int
+ * @since unknown
+ */
+define( 'MAX_RESULTS',        50 );
+
+/**
+ * How many seconds to let the script run
+ *
+ * @package WordPress
+ * @subpackage Blogger_Import
+ * @var int
+ * @since unknown
+ */
+define( 'MAX_EXECUTION_TIME', 20 );
+
+/**
+ * How many seconds between status bar updates
+ *
+ * @package WordPress
+ * @subpackage Blogger_Import
+ * @var int
+ * @since unknown
+ */
+define( 'STATUS_INTERVAL',     3 );
+
+/**
+ * Blogger Importer class
+ *
+ * @since unknown
+ */
 class Blogger_Import {
 
        // Shows the welcome screen and the magic auth link.
        function greet() {
-               $next_url = get_option('siteurl') . '/wp-admin/index.php?import=blogger&noheader=true';
+               $next_url = get_option('siteurl') . '/wp-admin/index.php?import=blogger&amp;noheader=true';
                $auth_url = "https://www.google.com/accounts/AuthSubRequest";
                $title = __('Import Blogger');
                $welcome = __('Howdy! This importer allows you to import posts and comments from your Blogger account into your WordPress blog.');
-               $prereqs = __('To use this importer, you must have a Google account, an upgraded (New, was Beta) blog, and it must be on blogspot or a custom domain (not FTP).');
+               $prereqs = __('To use this importer, you must have a Google account and an upgraded (New, was Beta) blog hosted on blogspot.com or a custom domain (not FTP).');
                $stepone = __('The first thing you need to do is tell Blogger to let WordPress access your account. You will be sent back here after providing authorization.');
                $auth = __('Authorize');
 
                echo "
-               <div class='wrap'><h2>$title</h2><p>$welcome</p><p>$prereqs</p><p>$stepone</p>
+               <div class='wrap'>
+               ".screen_icon()."
+               <h2>$title</h2>
+               <p>$welcome</p><p>$prereqs</p><p>$stepone</p>
                        <form action='$auth_url' method='get'>
                                <p class='submit' style='text-align:left;'>
-                                       <input type='submit' value='$auth' />
+                                       <input type='submit' class='button' value='$auth' />
                                        <input type='hidden' name='scope' value='http://www.blogger.com/feeds/' />
                                        <input type='hidden' name='session' value='1' />
                                        <input type='hidden' name='secure' value='0' />
@@ -31,7 +71,9 @@ class Blogger_Import {
        }
 
        function uh_oh($title, $message, $info) {
-               echo "<div class='wrap'><h2>$title</h2><p>$message</p><pre>$info</pre></div>";
+               echo "<div class='wrap'>";
+               screen_icon();
+               echo "<h2>$title</h2><p>$message</p><pre>$info</pre></div>";
        }
 
        function auth() {
@@ -178,12 +220,13 @@ class Blogger_Import {
                        $init .= "blogs[$i]=new blog($i,'$blogtitle','{$blog['mode']}'," . $this->get_js_status($i) . ');';
                        $pstat = "<div class='ind' id='pind$i'>&nbsp;</div><div id='pstat$i' class='stat'>$pdone/{$blog['total_posts']}</div>";
                        $cstat = "<div class='ind' id='cind$i'>&nbsp;</div><div id='cstat$i' class='stat'>$cdone/{$blog['total_comments']}</div>";
-                       $rows .= "<tr id='blog$i'><td class='blogtitle'>$blogtitle</td><td class='bloghost'>{$blog['host']}</td><td class='bar'>$pstat</td><td class='bar'>$cstat</td><td class='submit'><input type='submit' id='submit$i' value='$value' /><input type='hidden' name='blog' value='$i' /></td></tr>\n";
+                       $rows .= "<tr id='blog$i'><td class='blogtitle'>$blogtitle</td><td class='bloghost'>{$blog['host']}</td><td class='bar'>$pstat</td><td class='bar'>$cstat</td><td class='submit'><input type='submit' class='button' id='submit$i' value='$value' /><input type='hidden' name='blog' value='$i' /></td></tr>\n";
                }
 
-               echo "<div class='wrap'><h2>$title</h2><noscript>$noscript</noscript><table cellpadding='5px'><thead><td>$name</td><td>$url</td><td>$posts</td><td>$comments</td><td>$action</td></thead>\n$rows</table></form></div>";
+               echo "<div class='wrap'><h2>$title</h2><noscript>$noscript</noscript><table cellpadding='5px'><thead><tr><td>$name</td><td>$url</td><td>$posts</td><td>$comments</td><td>$action</td></tr></thead>\n$rows</table></div>";
                echo "
                <script type='text/javascript'>
+               /* <![CDATA[ */
                        var strings = {cont:'$continue',stop:'$stop',stopping:'$stopping',authors:'$authors',nothing:'$nothing'};
                        var blogs = {};
                        function blog(i, title, mode, status){
@@ -296,6 +339,7 @@ class Blogger_Import {
                        };
                        $init
                        jQuery.each(blogs, function(i, me){me.init();});
+               /* ]]> */
                </script>\n";
        }
 
@@ -381,7 +425,7 @@ class Blogger_Import {
                                                $AtomParser = new AtomParser();
                                                $AtomParser->parse( $entry );
                                                $result = $this->import_post($AtomParser->entry);
-                                               if ( is_wp_error( $result ) ) 
+                                               if ( is_wp_error( $result ) )
                                                        return $result;
                                                unset($AtomParser);
                                        }
@@ -485,7 +529,7 @@ class Blogger_Import {
        }
 
        function import_post( $entry ) {
-               global $wpdb, $importing_blog;
+               global $importing_blog;
 
                // The old permalink is all Blogger gives us to link comments to their posts.
                if ( isset( $entry->draft ) )
@@ -506,7 +550,7 @@ class Blogger_Import {
                $post_status  = isset( $entry->draft ) ? 'draft' : 'publish';
 
                // Clean up content
-               $post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content);
+               $post_content = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $post_content);
                $post_content = str_replace('<br>', '<br />', $post_content);
                $post_content = str_replace('<hr>', '<hr />', $post_content);
 
@@ -520,7 +564,7 @@ class Blogger_Import {
                        $post = compact('post_date', 'post_content', 'post_title', 'post_status');
 
                        $post_id = wp_insert_post($post);
-                       if ( is_wp_error( $post_id ) ) 
+                       if ( is_wp_error( $post_id ) )
                                return $post_id;
 
                        wp_create_categories( array_map( 'addslashes', $entry->categories ), $post_id );
@@ -559,7 +603,7 @@ class Blogger_Import {
                $comment_content = addslashes( $this->no_apos( html_entity_decode( $entry->content ) ) );
 
                // Clean up content
-               $comment_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $comment_content);
+               $comment_content = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $comment_content);
                $comment_content = str_replace('<br>', '<br />', $comment_content);
                $comment_content = str_replace('<hr>', '<hr />', $comment_content);
 
@@ -613,16 +657,16 @@ class Blogger_Import {
                $blogtitle = "{$blog['title']} ({$blog['host']})";
                $mapthis = __('Blogger username');
                $tothis = __('WordPress login');
-               $submit = js_escape( __('Save Changes &raquo;') );
+               $submit = js_escape( __('Save Changes') );
 
                foreach ( $blog['authors'] as $i => $author )
                        $rows .= "<tr><td><label for='authors[$i]'>{$author[0]}</label></td><td><select name='authors[$i]' id='authors[$i]'>" . $this->get_user_options($author[1]) . "</select></td></tr>";
 
-               return "<div class='wrap'><h2>$heading</h2><h3>$blogtitle</h3><p>$directions</p><form action='index.php?import=blogger&noheader=true&saveauthors=1' method='post'><input type='hidden' name='blog' value='$importing_blog' /><table cellpadding='5'><thead><td>$mapthis</td><td>$tothis</td></thead>$rows<tr><td></td><td class='submit'><input type='submit' class='authorsubmit' value='$submit' /></td></tr></table></form></div>";
+               return "<div class='wrap'><h2>$heading</h2><h3>$blogtitle</h3><p>$directions</p><form action='index.php?import=blogger&amp;noheader=true&saveauthors=1' method='post'><input type='hidden' name='blog' value='$importing_blog' /><table cellpadding='5'><thead><td>$mapthis</td><td>$tothis</td></thead>$rows<tr><td></td><td class='submit'><input type='submit' class='button authorsubmit' value='$submit' /></td></tr></table></form></div>";
        }
 
        function get_user_options($current) {
-               global $wpdb, $importer_users;
+               global $importer_users;
                if ( ! isset( $importer_users ) )
                        $importer_users = (array) get_users_of_blog();
 
@@ -641,7 +685,7 @@ class Blogger_Import {
                $host = $this->blogs[$importing_blog]['host'];
 
                // Get an array of posts => authors
-               $post_ids = (array) $wpdb->get_col("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'blogger_blog' AND meta_value = '$host'");
+               $post_ids = (array) $wpdb->get_col( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'blogger_blog' AND meta_value = %s", $host) );
                $post_ids = join( ',', $post_ids );
                $results = (array) $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = 'blogger_author' AND post_id IN ($post_ids)");
                foreach ( $results as $row )
@@ -658,7 +702,7 @@ class Blogger_Import {
                        $post_ids = (array) array_keys( $authors_posts, $this->blogs[$importing_blog]['authors'][$author][0] );
                        $post_ids = join( ',', $post_ids);
 
-                       $wpdb->query("UPDATE $wpdb->posts SET post_author = $user_id WHERE id IN ($post_ids)");
+                       $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_author = %d WHERE id IN ($post_ids)", $user_id) );
                        $this->blogs[$importing_blog]['authors'][$author][1] = $user_id;
                }
                $this->save_vars();
@@ -770,14 +814,14 @@ class Blogger_Import {
                                $this->$key = $value;
 
                if ( isset( $_REQUEST['blog'] ) ) {
-                       $blog = is_array($_REQUEST['blog']) ? array_shift( array_keys( $_REQUEST['blog'] ) ) : $_REQUEST['blog'];
+                       $blog = is_array($_REQUEST['blog']) ? array_shift( $keys = array_keys( $_REQUEST['blog'] ) ) : $_REQUEST['blog'];
                        $blog = (int) $blog;
                        $result = $this->import_blog( $blog );
                        if ( is_wp_error( $result ) )
                                echo $result->get_error_message();
                } elseif ( isset($_GET['token']) )
                        $this->auth();
-               elseif ( $this->token && $this->token_is_valid() )
+               elseif ( isset($this->token) && $this->token_is_valid() )
                        $this->show_blogs();
                else
                        $this->greet();
@@ -788,7 +832,7 @@ class Blogger_Import {
                        $restart = __('Restart');
                        $message = __('We have saved some information about your Blogger account in your WordPress database. Clearing this information will allow you to start over. Restarting will not affect any posts you have already imported. If you attempt to re-import a blog, duplicate posts and comments will be skipped.');
                        $submit = __('Clear account information');
-                       echo "<div class='wrap'><h2>$restart</h2><p>$message</p><form method='post' action='?import=blogger&noheader=true'><p class='submit' style='text-align:left;'><input type='submit' value='$submit' name='restart' /></p></form></div>";
+                       echo "<div class='wrap'><h2>$restart</h2><p>$message</p><form method='post' action='?import=blogger&amp;noheader=true'><p class='submit' style='text-align:left;'><input type='submit' class='button' value='$submit' name='restart' /></p></form></div>";
                }
        }
 
@@ -821,9 +865,6 @@ thead td { font-weight: bold; }
        position: relative;
        text-align: center;
 }
-.submit {
-       text-align: center !important;
-}
 </style>
 <?php
        }
@@ -840,7 +881,7 @@ thead td { font-weight: bold; }
 
 $blogger_import = new Blogger_Import();
 
-register_importer('blogger', __('Blogger'), __('Import posts, comments, and users from a Blogger blog'), array ($blogger_import, 'start'));
+register_importer('blogger', __('Blogger'), __('Import posts, comments, and users from a Blogger blog.'), array ($blogger_import, 'start'));
 
 class AtomEntry {
        var $links = array();