Blogger Importer - Version 0.5

Version Description

  • Merged in fix by SergeyBiryukov http://core.trac.wordpress.org/ticket/16012
  • Merged in rmccue change to get_total_results to also use SimplePie from http://core.trac.wordpress.org/attachment/ticket/7652/7652-blogger.diff
  • Reviewed in rmccue's changes in http://core.trac.wordpress.org/attachment/ticket/7652/7652-separate.diff issues with date handling functions so skipped those
  • Moved SimplePie functions in new class WP_SimplePie_Blog_Item incorporating get_draft_status and get_updated and convert date
  • Tested comments from source blog GMT-8, destination London (currently GMT-1), comment dates transferred correctly.
  • Fixed typo in oauth_get
  • Added screen_icon() to all pages
  • Added GeoTags as per spec on http://codex.wordpress.org/Geodata
  • Change by Otto42, rmccue to use Simplepie XML processing rather than Atomparser, http://core.trac.wordpress.org/ticket/14525 ref: http://core.trac.wordpress.org/attachment/ticket/7652/7652-blogger.diff (this also fixes http://core.trac.wordpress.org/ticket/15560)
  • Change by Otto42 to use OAuth rather than AuthSub authentication, should make authentication more reliable
  • Fix by Andy from Workshopshed to load comments and nested comments correctly
  • Fix by Andy from Workshopshed to correctly pass the blogger start-index and max-results parameters to oAuth functions and to process more than one batch http://core.trac.wordpress.org/ticket/19096
  • Fix by Andy from Workshopshed error about incorrect enqueuing of scripts also changed styles to work the same
  • Change by Andy from Workshopshed testing in debug mode and wrapped ajax return into a function to suppress debug messages
  • Fix by Andy from Workshopshed notices for undefined variables.
  • Change by Andy from Workshopshed Added tooltip to results table to show numbers of posts and comments skipped (duplicates / missing key)
  • Fix by Andy from Workshopshed incorrectly checking for duplicates based on only the date and username, this gave false positives when large numbers of comments, particularly anonymous ones.
Download this release

Release Info

Developer Otto42
Plugin Icon 128x128 Blogger Importer
Version 0.5
Comparing to
See all releases

Code changes from version 0.4 to 0.5

blogger-importer-blogitem.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Based on WP_SimplePieAtomPub_Item
5
+ * Expect this to become part of core wordpress at some point.
6
+ * See http://core.trac.wordpress.org/ticket/7652
7
+ *
8
+ * Todo GeoTag parsing
9
+ * http://codex.wordpress.org/Geodata
10
+ *
11
+ */
12
+
13
+ define('SIMPLEPIE_NAMESPACE_ATOMPUB', 'http://www.w3.org/2007/app');
14
+ define('SIMPLEPIE_NAMESPACE_GEOTAG', 'http://www.georss.org/georss');
15
+
16
+ /**
17
+ * SimplePie Helper for AtomPub
18
+ *
19
+ * @package WordPress
20
+ * @subpackage Publishing
21
+ * @since 3.1
22
+ */
23
+ if (!class_exists('WP_SimplePie_Blog_Item'))
24
+ {
25
+ class WP_SimplePie_Blog_Item extends SimplePie_Item
26
+ {
27
+ /**
28
+ * Constructor
29
+ */
30
+ function WP_SimplePieAtomPub_Item($feed, $data)
31
+ {
32
+ parent::SimplePie_Item($feed, $data);
33
+ }
34
+
35
+ /**
36
+ * Get the status of the entry
37
+ *
38
+ * @return bool True if the item is a draft, false otherwise
39
+ */
40
+ function get_draft_status()
41
+ {
42
+ $draft = false;
43
+ if (($control = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOMPUB, 'control')) && !empty($control[0]['child'][SIMPLEPIE_NAMESPACE_ATOMPUB]['draft'][0]['data']))
44
+ {
45
+ $draft = ('yes' == $control[0]['child'][SIMPLEPIE_NAMESPACE_ATOMPUB]['draft'][0]['data']);
46
+ }
47
+ return $draft;
48
+ }
49
+
50
+ //Tried using date functions from http://core.trac.wordpress.org/attachment/ticket/7652/7652-separate.diff
51
+ //but ended up with 1970s dates so returned to Otto's version which is much simplified
52
+ function get_updated()
53
+ {
54
+ $temparray = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated');
55
+ if (isset($temparray[0]['data']))
56
+ return $this->convert_date($temparray[0]['data']);
57
+ else
58
+ return null;
59
+ }
60
+
61
+ function get_published()
62
+ {
63
+ $temparray = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published');
64
+ if (isset($temparray[0]['data']))
65
+ return $this->convert_date($temparray[0]['data']);
66
+ else
67
+ return null;
68
+ }
69
+
70
+ function get_geotags()
71
+ {//Return an array of geo tags see http://codex.wordpress.org/Geodata
72
+ //example source
73
+ // <georss:featurename>R�dhuspladsen 3, 1550 Copenhagen, Denmark</georss:featurename>
74
+ // <georss:point>55.6760968 12.5683371</georss:point>
75
+
76
+
77
+ $latlong = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEOTAG, 'point');
78
+
79
+ if (isset($latlong[0]['data'])) {
80
+ preg_match('/([0-9.-]+).+?([0-9.-]+)/', $latlong[0]['data'], $matches);
81
+ $lat=(float)$matches[1];
82
+ $long=(float)$matches[2];
83
+ }
84
+
85
+ if (!isset($lat) |!isset($long)) {
86
+ return null; //Without lat long we can't have a valid location
87
+ }
88
+
89
+ $address = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEOTAG, 'featurename');
90
+ if (isset($address[0]['data']))
91
+ $geo_address = $address[0]['data'];
92
+ else
93
+ $geo_address = null;
94
+
95
+ $geo = array('geo_latitude' => $lat, 'geo_longitude' => $long, 'geo_address' => $geo_address );
96
+
97
+ return $geo;
98
+ }
99
+
100
+ function convert_date($date)
101
+ {
102
+ preg_match('#([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(?:\.[0-9]+)?(Z|[\+|\-][0-9]{2,4}){0,1}#', $date, $date_bits);
103
+ $offset = iso8601_timezone_to_offset($date_bits[7]);
104
+ $timestamp = gmmktime($date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]);
105
+ $timestamp -= $offset; // Convert from Blogger local time to GMT
106
+ $timestamp += get_option('gmt_offset') * 3600; // Convert from GMT to WP local time
107
+ return gmdate('Y-m-d H:i:s', $timestamp);
108
+ }
109
+
110
+ //Don't Sanitize the ID, the default get_id was cleaning our IDs and that meant that nested comments did not work
111
+ function get_id()
112
+ {
113
+ if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'id'))
114
+ {
115
+ return $return[0]['data'];
116
+ }
117
+ }
118
+
119
+ }
120
+
121
+ }
122
+
123
+ ?>
blogger-importer-sanitize.php ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * New class to sanitize trusted content from blogger import
5
+ * Based on the SimplePie_Sanitize class by Ryan Parman and Geoffrey Sneddon
6
+ *
7
+ */
8
+
9
+ class Blogger_Importer_Sanitize extends Simplepie_Sanitize
10
+ {
11
+ // Private vars
12
+ var $base;
13
+
14
+ // Options
15
+ var $image_handler = '';
16
+ var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'font', 'form', 'frame', 'frameset', 'html', 'input', 'marquee', 'meta', 'script', 'style');
17
+ //Allow iframe (new style) and embed, param and object(old style) so that we get youtube videos transferred
18
+ //Allow object and noscript for Amazon widgets
19
+ var $encode_instead_of_strip = false;
20
+ var $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'imageanchor', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
21
+ //Allow styles so we don't have to redo in Wordpress
22
+ //Brett Morgan from Google has confirmed that imageanchor is a made up attribute that is just used in the blogger editor so we can remove that
23
+ var $output_encoding = 'UTF-8';
24
+ var $enable_cache = true;
25
+ var $cache_location = './cache';
26
+ var $cache_name_function = 'md5';
27
+ var $cache_class = 'SimplePie_Cache';
28
+ var $file_class = 'SimplePie_File';
29
+ var $timeout = 10;
30
+ var $useragent = '';
31
+ var $force_fsockopen = false;
32
+
33
+ var $replace_url_attributes = array('a' => 'href', 'area' => 'href', 'blockquote' => 'cite', 'del' => 'cite', 'form' => 'action', 'img' => array('longdesc', 'src'), 'input' => 'src', 'ins' => 'cite',
34
+ 'q' => 'cite');
35
+
36
+ function _normalize_tag($matches)
37
+ {
38
+ return '<' . strtolower($matches[1]);
39
+ }
40
+
41
+ function sanitize($data, $type, $base = '')
42
+ {
43
+ //Simplified function
44
+ $data = trim($data);
45
+
46
+ // Remappings
47
+ $data = str_replace('<br>', '<br />', $data);
48
+ $data = str_replace('<hr>', '<hr />', $data);
49
+ //<span style="font-weight:bold;">Workshopshed:</span> > <b>Workshopshed:</b>
50
+ $data = preg_replace('|(<span style="font-weight:bold;">)(?<!<span style="font-weight:bold;">).*(.*)(</span>)|', '<strong>$2</strong>', $data);
51
+
52
+ //N.B. Don't strip comments as blogger uses <!--more--> which is the same as Wordpress
53
+
54
+ //Now clean up
55
+ foreach ($this->strip_htmltags as $tag)
56
+ {
57
+ $pcre = "/<($tag)" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . "(>(.*)<\/$tag" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>|(\/)?>)/siU';
58
+ while (preg_match($pcre, $data))
59
+ {
60
+ $data = preg_replace_callback($pcre, array(&$this, 'do_strip_htmltags'), $data);
61
+ }
62
+ }
63
+
64
+ foreach ($this->strip_attributes as $attrib)
65
+ {
66
+ $data = preg_replace('/(<[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*)' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . trim($attrib) . '(?:\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'|(?:[^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?' .
67
+ SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>/', '\1\2\3>', $data);
68
+ }
69
+
70
+ // Replace relative URLs
71
+ $this->base = $base;
72
+ foreach ($this->replace_url_attributes as $element => $attributes)
73
+ {
74
+ $data = $this->replace_urls($data, $element, $attributes);
75
+ }
76
+
77
+ // If image handling (caching, etc.) is enabled, cache and rewrite all the image tags.
78
+ if (isset($this->image_handler) && ((string )$this->image_handler) !== '' && $this->enable_cache)
79
+ {
80
+ $images = SimplePie_Misc::get_element('img', $data);
81
+ foreach ($images as $img)
82
+ {
83
+ if (isset($img['attribs']['src']['data']))
84
+ {
85
+ $image_url = call_user_func($this->cache_name_function, $img['attribs']['src']['data']);
86
+ $cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, $image_url, 'spi');
87
+ if ($cache->load())
88
+ {
89
+ $img['attribs']['src']['data'] = $this->image_handler . $image_url;
90
+ $data = str_replace($img['full'], SimplePie_Misc::element_implode($img), $data);
91
+ } else
92
+ {
93
+ $file = &new $this->file_class($img['attribs']['src']['data'], $this->timeout, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $this->useragent, $this->force_fsockopen);
94
+ $headers = $file->headers;
95
+ if ($file->success && ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
96
+ {
97
+ if ($cache->save(array('headers' => $file->headers, 'body' => $file->body)))
98
+ {
99
+ $img['attribs']['src']['data'] = $this->image_handler . $image_url;
100
+ $data = str_replace($img['full'], SimplePie_Misc::element_implode($img), $data);
101
+ } else
102
+ {
103
+ trigger_error("$this->cache_location is not writeable", E_USER_WARNING);
104
+ }
105
+ }
106
+ }
107
+ }
108
+ }
109
+ }
110
+
111
+ // Having (possibly) taken stuff out, there may now be whitespace at the beginning/end of the data
112
+ $data = trim($data);
113
+
114
+ // Normalise tags
115
+ $data = preg_replace_callback('|<(/?[A-Z]+)|', array(&$this, '_normalize_tag'), $data);
116
+
117
+ return $data;
118
+ }
119
+
120
+ function replace_urls($data, $tag, $attributes)
121
+ {
122
+ if (!is_array($this->strip_htmltags) || !in_array($tag, $this->strip_htmltags))
123
+ {
124
+ $elements = SimplePie_Misc::get_element($tag, $data);
125
+ foreach ($elements as $element)
126
+ {
127
+ if (is_array($attributes))
128
+ {
129
+ foreach ($attributes as $attribute)
130
+ {
131
+ if (isset($element['attribs'][$attribute]['data']))
132
+ {
133
+ $element['attribs'][$attribute]['data'] = SimplePie_Misc::absolutize_url($element['attribs'][$attribute]['data'], $this->base);
134
+ $new_element = SimplePie_Misc::element_implode($element);
135
+ $data = str_replace($element['full'], $new_element, $data);
136
+ $element['full'] = $new_element;
137
+ }
138
+ }
139
+ } elseif (isset($element['attribs'][$attributes]['data']))
140
+ {
141
+ $element['attribs'][$attributes]['data'] = SimplePie_Misc::absolutize_url($element['attribs'][$attributes]['data'], $this->base);
142
+ $data = str_replace($element['full'], SimplePie_Misc::element_implode($element), $data);
143
+ }
144
+ }
145
+ }
146
+ return $data;
147
+ }
148
+
149
+
150
+ }
151
+
152
+ ?>
blogger-importer.css ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ td { text-align: center; line-height: 2em;}
3
+ thead td { font-weight: bold; }
4
+ .bar {
5
+ width: 200px;
6
+ text-align: left;
7
+ line-height: 2em;
8
+ padding: 0px;
9
+ }
10
+ .ind {
11
+ position: absolute;
12
+ background-color: #83B4D8;
13
+ width: 1px;
14
+ z-index: 9;
15
+ }
16
+ .stat {
17
+ z-index: 10;
18
+ position: relative;
19
+ text-align: center;
20
+ }
21
+ td.submit {
22
+ margin:0;
23
+ padding:0;
24
+ }
25
+
26
+ td {
27
+ padding-left:10px;
28
+ padding-right:10px;
29
+ }
blogger-importer.php CHANGED
@@ -1,1104 +1,1029 @@
1
- <?php
2
- /*
3
- Plugin Name: Blogger Importer
4
- Plugin URI: http://wordpress.org/extend/plugins/blogger-importer/
5
- Description: Import posts, comments, tags, and attachments from a Blogger blog.
6
- Author: wordpressdotorg
7
- Author URI: http://wordpress.org/
8
- Version: 0.4
9
- Stable tag: 0.4
10
- License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11
- */
12
-
13
- if ( !defined('WP_LOAD_IMPORTERS') )
14
- return;
15
-
16
- // Load Importer API
17
- require_once ABSPATH . 'wp-admin/includes/import.php';
18
-
19
- if ( !class_exists( 'WP_Importer' ) ) {
20
- $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
21
- if ( file_exists( $class_wp_importer ) )
22
- require_once $class_wp_importer;
23
- }
24
-
25
- /**
26
- * How many records per GData query
27
- *
28
- * @package WordPress
29
- * @subpackage Blogger_Import
30
- * @var int
31
- * @since unknown
32
- */
33
- define( 'MAX_RESULTS', 50 );
34
-
35
- /**
36
- * How many seconds to let the script run
37
- *
38
- * @package WordPress
39
- * @subpackage Blogger_Import
40
- * @var int
41
- * @since unknown
42
- */
43
- define( 'MAX_EXECUTION_TIME', 20 );
44
-
45
- /**
46
- * How many seconds between status bar updates
47
- *
48
- * @package WordPress
49
- * @subpackage Blogger_Import
50
- * @var int
51
- * @since unknown
52
- */
53
- define( 'STATUS_INTERVAL', 3 );
54
-
55
- /**
56
- * Blogger Importer
57
- *
58
- * @package WordPress
59
- * @subpackage Importer
60
- */
61
- if ( class_exists( 'WP_Importer' ) ) {
62
- class Blogger_Import extends WP_Importer {
63
-
64
- // Shows the welcome screen and the magic auth link.
65
- function greet() {
66
- $next_url = get_option('siteurl') . '/wp-admin/index.php?import=blogger&amp;noheader=true';
67
- $auth_url = "https://www.google.com/accounts/AuthSubRequest";
68
- $title = __('Import Blogger', 'blogger-importer');
69
- $welcome = __('Howdy! This importer allows you to import posts and comments from your Blogger account into your WordPress site.', 'blogger-importer');
70
- $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).', 'blogger-importer');
71
- $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.', 'blogger-importer');
72
- $auth = esc_attr__('Authorize', 'blogger-importer');
73
-
74
- echo "
75
- <div class='wrap'>
76
- ".screen_icon()."
77
- <h2>$title</h2>
78
- <p>$welcome</p><p>$prereqs</p><p>$stepone</p>
79
- <form action='$auth_url' method='get'>
80
- <p class='submit' style='text-align:left;'>
81
- <input type='submit' class='button' value='$auth' />
82
- <input type='hidden' name='scope' value='http://www.blogger.com/feeds/' />
83
- <input type='hidden' name='session' value='1' />
84
- <input type='hidden' name='secure' value='0' />
85
- <input type='hidden' name='next' value='$next_url' />
86
- </p>
87
- </form>
88
- </div>\n";
89
- }
90
-
91
- function uh_oh($title, $message, $info) {
92
- echo "<div class='wrap'>";
93
- screen_icon();
94
- echo "<h2>$title</h2><p>$message</p><pre>$info</pre></div>";
95
- }
96
-
97
- function auth() {
98
- // We have a single-use token that must be upgraded to a session token.
99
- $token = urldecode( preg_replace( '/[^%-_0-9a-zA-Z]/', '', $_GET['token'] ) );
100
- $headers = array(
101
- "GET /accounts/AuthSubSessionToken HTTP/1.0",
102
- "Authorization: AuthSub token=\"$token\""
103
- );
104
- $request = join( "\r\n", $headers ) . "\r\n\r\n";
105
- $sock = $this->_get_auth_sock( );
106
- if ( ! $sock ) return false;
107
- $response = $this->_txrx( $sock, $request );
108
- preg_match( '/token=([%-_0-9a-z]+)/i', $response, $matches );
109
- if ( empty( $matches[1] ) ) {
110
- $this->uh_oh(
111
- __( 'Authorization failed' , 'blogger-importer'),
112
- __( 'Something went wrong. If the problem persists, send this info to support:' , 'blogger-importer'),
113
- htmlspecialchars($response)
114
- );
115
- return false;
116
- }
117
- $this->token = urldecode( $matches[1] );
118
-
119
- wp_redirect( remove_query_arg( array( 'token', 'noheader' ) ) );
120
- }
121
-
122
- function get_token_info() {
123
- $headers = array(
124
- "GET /accounts/AuthSubTokenInfo HTTP/1.0",
125
- "Authorization: AuthSub token=\"$this->token\""
126
- );
127
- $request = join( "\r\n", $headers ) . "\r\n\r\n";
128
- $sock = $this->_get_auth_sock( );
129
- if ( ! $sock ) return;
130
- $response = $this->_txrx( $sock, $request );
131
- return $this->parse_response($response);
132
- }
133
-
134
- function token_is_valid() {
135
- $info = $this->get_token_info();
136
-
137
- if ( $info['code'] == 200 )
138
- return true;
139
-
140
- return false;
141
- }
142
-
143
- function show_blogs($iter = 0) {
144
- if ( empty($this->blogs) ) {
145
- $headers = array(
146
- "GET /feeds/default/blogs HTTP/1.0",
147
- "Host: www.blogger.com",
148
- "Authorization: AuthSub token=\"$this->token\""
149
- );
150
- $request = join( "\r\n", $headers ) . "\r\n\r\n";
151
- $sock = $this->_get_blogger_sock( );
152
- if ( ! $sock ) return;
153
- $response = $this->_txrx( $sock, $request );
154
-
155
- // Quick and dirty XML mining.
156
- list( $headers, $xml ) = explode( "\r\n\r\n", $response );
157
- $p = xml_parser_create();
158
- xml_parse_into_struct($p, $xml, $vals, $index);
159
- xml_parser_free($p);
160
-
161
- $this->title = $vals[$index['TITLE'][0]]['value'];
162
-
163
- // Give it a few retries... this step often flakes out the first time.
164
- if ( empty( $index['ENTRY'] ) ) {
165
- if ( $iter < 3 ) {
166
- return $this->show_blogs($iter + 1);
167
- } else {
168
- $this->uh_oh(
169
- __('Trouble signing in', 'blogger-importer'),
170
- __('We were not able to gain access to your account. Try starting over.', 'blogger-importer'),
171
- ''
172
- );
173
- return false;
174
- }
175
- }
176
-
177
- foreach ( $index['ENTRY'] as $i ) {
178
- $blog = array();
179
- while ( ( $tag = $vals[$i] ) && ! ( $tag['tag'] == 'ENTRY' && $tag['type'] == 'close' ) ) {
180
- if ( $tag['tag'] == 'TITLE' ) {
181
- $blog['title'] = $tag['value'];
182
- } elseif ( $tag['tag'] == 'SUMMARY' ) {
183
- $blog['summary'] = $tag['value'];
184
- } elseif ( $tag['tag'] == 'LINK' ) {
185
- if ( $tag['attributes']['REL'] == 'alternate' && $tag['attributes']['TYPE'] == 'text/html' ) {
186
- $parts = parse_url( $tag['attributes']['HREF'] );
187
- $blog['host'] = $parts['host'];
188
- } elseif ( $tag['attributes']['REL'] == 'edit' ) {
189
- $blog['gateway'] = $tag['attributes']['HREF'];
190
- } elseif ( $tag['attributes']['REL'] == 'http://schemas.google.com/g/2005#post' ) {
191
- $parts = parse_url( $tag['attributes']['HREF'] );
192
- $blog['posts_host'] = $parts['host'];
193
- $blog['posts_path'] = $parts['path'];
194
- }
195
- }
196
- ++$i;
197
- }
198
- if ( ! empty ( $blog ) ) {
199
- $blog['total_posts'] = $this->get_total_results('posts', $blog['host']);
200
- $blog['total_comments'] = $this->get_total_results('comments', $blog['host']);
201
- $blog['mode'] = 'init';
202
- $this->blogs[] = $blog;
203
- }
204
- }
205
-
206
- if ( empty( $this->blogs ) ) {
207
- $this->uh_oh(
208
- __('No blogs found', 'blogger-importer'),
209
- __('We were able to log in but there were no blogs. Try a different account next time.', 'blogger-importer'),
210
- ''
211
- );
212
- return false;
213
- }
214
- }
215
- //echo '<pre>'.print_r($this,1).'</pre>';
216
- $start = esc_js( __('Import', 'blogger-importer') );
217
- $continue = esc_js( __('Continue', 'blogger-importer') );
218
- $stop = esc_js( __('Importing...', 'blogger-importer') );
219
- $authors = esc_js( __('Set Authors', 'blogger-importer') );
220
- $loadauth = esc_js( __('Preparing author mapping form...', 'blogger-importer') );
221
- $authhead = esc_js( __('Final Step: Author Mapping', 'blogger-importer') );
222
- $nothing = esc_js( __('Nothing was imported. Had you already imported this blog?', 'blogger-importer') );
223
- $stopping = ''; //Missing String used below.
224
- $title = __('Blogger Blogs', 'blogger-importer');
225
- $name = __('Blog Name', 'blogger-importer');
226
- $url = __('Blog URL', 'blogger-importer');
227
- $action = __('The Magic Button', 'blogger-importer');
228
- $posts = __('Posts', 'blogger-importer');
229
- $comments = __('Comments', 'blogger-importer');
230
- $noscript = __('This feature requires Javascript but it seems to be disabled. Please enable Javascript and then reload this page. Don&#8217;t worry, you can turn it back off when you&#8217;re done.', 'blogger-importer');
231
-
232
- $interval = STATUS_INTERVAL * 1000;
233
-
234
- foreach ( $this->blogs as $i => $blog ) {
235
- if ( $blog['mode'] == 'init' )
236
- $value = $start;
237
- elseif ( $blog['mode'] == 'posts' || $blog['mode'] == 'comments' )
238
- $value = $continue;
239
- else
240
- $value = $authors;
241
- $value = esc_attr($value);
242
- $blogtitle = esc_js( $blog['title'] );
243
- $pdone = isset($blog['posts_done']) ? (int) $blog['posts_done'] : 0;
244
- $cdone = isset($blog['comments_done']) ? (int) $blog['comments_done'] : 0;
245
- $init .= "blogs[$i]=new blog($i,'$blogtitle','{$blog['mode']}'," . $this->get_js_status($i) . ');';
246
- $pstat = "<div class='ind' id='pind$i'>&nbsp;</div><div id='pstat$i' class='stat'>$pdone/{$blog['total_posts']}</div>";
247
- $cstat = "<div class='ind' id='cind$i'>&nbsp;</div><div id='cstat$i' class='stat'>$cdone/{$blog['total_comments']}</div>";
248
- $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";
249
- }
250
-
251
- 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>";
252
- echo "
253
- <script type='text/javascript'>
254
- /* <![CDATA[ */
255
- var strings = {cont:'$continue',stop:'$stop',stopping:'$stopping',authors:'$authors',nothing:'$nothing'};
256
- var blogs = {};
257
- function blog(i, title, mode, status){
258
- this.blog = i;
259
- this.mode = mode;
260
- this.title = title;
261
- this.status = status;
262
- this.button = document.getElementById('submit'+this.blog);
263
- };
264
- blog.prototype = {
265
- start: function() {
266
- this.cont = true;
267
- this.kick();
268
- this.check();
269
- },
270
- kick: function() {
271
- ++this.kicks;
272
- var i = this.blog;
273
- jQuery.post('admin.php?import=blogger&noheader=true',{blog:this.blog},function(text,result){blogs[i].kickd(text,result)});
274
- },
275
- check: function() {
276
- ++this.checks;
277
- var i = this.blog;
278
- jQuery.post('admin.php?import=blogger&noheader=true&status=true',{blog:this.blog},function(text,result){blogs[i].checkd(text,result)});
279
- },
280
- kickd: function(text, result) {
281
- if ( result == 'error' ) {
282
- // TODO: exception handling
283
- if ( this.cont )
284
- setTimeout('blogs['+this.blog+'].kick()', 1000);
285
- } else {
286
- if ( text == 'done' ) {
287
- this.stop();
288
- this.done();
289
- } else if ( text == 'nothing' ) {
290
- this.stop();
291
- this.nothing();
292
- } else if ( text == 'continue' ) {
293
- this.kick();
294
- } else if ( this.mode = 'stopped' )
295
- jQuery(this.button).attr('value', strings.cont);
296
- }
297
- --this.kicks;
298
- },
299
- checkd: function(text, result) {
300
- if ( result == 'error' ) {
301
- // TODO: exception handling
302
- } else {
303
- eval('this.status='+text);
304
- jQuery('#pstat'+this.blog).empty().append(this.status.p1+'/'+this.status.p2);
305
- jQuery('#cstat'+this.blog).empty().append(this.status.c1+'/'+this.status.c2);
306
- this.update();
307
- if ( this.cont || this.kicks > 0 )
308
- setTimeout('blogs['+this.blog+'].check()', $interval);
309
- }
310
- --this.checks;
311
- },
312
- update: function() {
313
- jQuery('#pind'+this.blog).width(((this.status.p1>0&&this.status.p2>0)?(this.status.p1/this.status.p2*jQuery('#pind'+this.blog).parent().width()):1)+'px');
314
- jQuery('#cind'+this.blog).width(((this.status.c1>0&&this.status.c2>0)?(this.status.c1/this.status.c2*jQuery('#cind'+this.blog).parent().width()):1)+'px');
315
- },
316
- stop: function() {
317
- this.cont = false;
318
- },
319
- done: function() {
320
- this.mode = 'authors';
321
- jQuery(this.button).attr('value', strings.authors);
322
- },
323
- nothing: function() {
324
- this.mode = 'nothing';
325
- jQuery(this.button).remove();
326
- alert(strings.nothing);
327
- },
328
- getauthors: function() {
329
- if ( jQuery('div.wrap').length > 1 )
330
- jQuery('div.wrap').gt(0).remove();
331
- jQuery('div.wrap').empty().append('<h2>$authhead</h2><h3>' + this.title + '</h3>');
332
- jQuery('div.wrap').append('<p id=\"auth\">$loadauth</p>');
333
- jQuery('p#auth').load('index.php?import=blogger&noheader=true&authors=1',{blog:this.blog});
334
- },
335
- init: function() {
336
- this.update();
337
- var i = this.blog;
338
- jQuery(this.button).bind('click', function(){return blogs[i].click();});
339
- this.kicks = 0;
340
- this.checks = 0;
341
- },
342
- click: function() {
343
- if ( this.mode == 'init' || this.mode == 'stopped' || this.mode == 'posts' || this.mode == 'comments' ) {
344
- this.mode = 'started';
345
- this.start();
346
- jQuery(this.button).attr('value', strings.stop);
347
- } else if ( this.mode == 'started' ) {
348
- return false; // let it run...
349
- this.mode = 'stopped';
350
- this.stop();
351
- if ( this.checks > 0 || this.kicks > 0 ) {
352
- this.mode = 'stopping';
353
- jQuery(this.button).attr('value', strings.stopping);
354
- } else {
355
- jQuery(this.button).attr('value', strings.cont);
356
- }
357
- } else if ( this.mode == 'authors' ) {
358
- document.location = 'index.php?import=blogger&authors=1&blog='+this.blog;
359
- //this.mode = 'authors2';
360
- //this.getauthors();
361
- }
362
- return false;
363
- }
364
- };
365
- $init
366
- jQuery.each(blogs, function(i, me){me.init();});
367
- /* ]]> */
368
- </script>\n";
369
- }
370
-
371
- // Handy function for stopping the script after a number of seconds.
372
- function have_time() {
373
- global $importer_started;
374
- if ( time() - $importer_started > MAX_EXECUTION_TIME )
375
- die('continue');
376
- return true;
377
- }
378
-
379
- function get_total_results($type, $host) {
380
- $headers = array(
381
- "GET /feeds/$type/default?max-results=1&start-index=2 HTTP/1.0",
382
- "Host: $host",
383
- "Authorization: AuthSub token=\"$this->token\""
384
- );
385
- $request = join( "\r\n", $headers ) . "\r\n\r\n";
386
- $sock = $this->_get_blogger_sock( $host );
387
- if ( ! $sock ) return;
388
- $response = $this->_txrx( $sock, $request );
389
- $response = $this->parse_response( $response );
390
- $parser = xml_parser_create();
391
- xml_parse_into_struct($parser, $response['body'], $struct, $index);
392
- xml_parser_free($parser);
393
- $total_results = $struct[$index['OPENSEARCH:TOTALRESULTS'][0]]['value'];
394
- return (int) $total_results;
395
- }
396
-
397
- function import_blog($blogID) {
398
- global $importing_blog;
399
- $importing_blog = $blogID;
400
-
401
- if ( isset($_GET['authors']) )
402
- return print($this->get_author_form());
403
-
404
- header('Content-Type: text/plain');
405
-
406
- if ( isset($_GET['status']) )
407
- die($this->get_js_status());
408
-
409
- if ( isset($_GET['saveauthors']) )
410
- die($this->save_authors());
411
-
412
- $blog = $this->blogs[$blogID];
413
- $total_results = $this->get_total_results('posts', $blog['host']);
414
- $this->blogs[$importing_blog]['total_posts'] = $total_results;
415
-
416
- $start_index = $total_results - MAX_RESULTS + 1;
417
-
418
- if ( isset( $this->blogs[$importing_blog]['posts_start_index'] ) )
419
- $start_index = (int) $this->blogs[$importing_blog]['posts_start_index'];
420
- elseif ( $total_results > MAX_RESULTS )
421
- $start_index = $total_results - MAX_RESULTS + 1;
422
- else
423
- $start_index = 1;
424
-
425
- // This will be positive until we have finished importing posts
426
- if ( $start_index > 0 ) {
427
- // Grab all the posts
428
- $this->blogs[$importing_blog]['mode'] = 'posts';
429
- $query = "start-index=$start_index&max-results=" . MAX_RESULTS;
430
- do {
431
- $index = $struct = $entries = array();
432
- $headers = array(
433
- "GET {$blog['posts_path']}?$query HTTP/1.0",
434
- "Host: {$blog['posts_host']}",
435
- "Authorization: AuthSub token=\"$this->token\""
436
- );
437
- $request = join( "\r\n", $headers ) . "\r\n\r\n";
438
- $sock = $this->_get_blogger_sock( $blog['posts_host'] );
439
- if ( ! $sock ) return; // TODO: Error handling
440
- $response = $this->_txrx( $sock, $request );
441
-
442
- $response = $this->parse_response( $response );
443
-
444
- // Extract the entries and send for insertion
445
- preg_match_all( '/<entry[^>]*>.*?<\/entry>/s', $response['body'], $matches );
446
- if ( count( $matches[0] ) ) {
447
- $entries = array_reverse($matches[0]);
448
- foreach ( $entries as $entry ) {
449
- $entry = "<feed>$entry</feed>";
450
- $AtomParser = new AtomParser();
451
- $AtomParser->parse( $entry );
452
- $result = $this->import_post($AtomParser->entry);
453
- if ( is_wp_error( $result ) )
454
- return $result;
455
- unset($AtomParser);
456
- }
457
- } else break;
458
-
459
- // Get the 'previous' query string which we'll use on the next iteration
460
- $query = '';
461
- $links = preg_match_all('/<link([^>]*)>/', $response['body'], $matches);
462
- if ( count( $matches[1] ) )
463
- foreach ( $matches[1] as $match )
464
- if ( preg_match('/rel=.previous./', $match) )
465
- $query = @html_entity_decode( preg_replace('/^.*href=[\'"].*\?(.+)[\'"].*$/', '$1', $match), ENT_COMPAT, get_option('blog_charset') );
466
-
467
- if ( $query ) {
468
- parse_str($query, $q);
469
- $this->blogs[$importing_blog]['posts_start_index'] = (int) $q['start-index'];
470
- } else
471
- $this->blogs[$importing_blog]['posts_start_index'] = 0;
472
- $this->save_vars();
473
- } while ( !empty( $query ) && $this->have_time() );
474
- }
475
-
476
- $total_results = $this->get_total_results( 'comments', $blog['host'] );
477
- $this->blogs[$importing_blog]['total_comments'] = $total_results;
478
-
479
- if ( isset( $this->blogs[$importing_blog]['comments_start_index'] ) )
480
- $start_index = (int) $this->blogs[$importing_blog]['comments_start_index'];
481
- elseif ( $total_results > MAX_RESULTS )
482
- $start_index = $total_results - MAX_RESULTS + 1;
483
- else
484
- $start_index = 1;
485
-
486
- if ( $start_index > 0 ) {
487
- // Grab all the comments
488
- $this->blogs[$importing_blog]['mode'] = 'comments';
489
- $query = "start-index=$start_index&max-results=" . MAX_RESULTS;
490
- do {
491
- $index = $struct = $entries = array();
492
- $headers = array(
493
- "GET /feeds/comments/default?$query HTTP/1.0",
494
- "Host: {$blog['host']}",
495
- "Authorization: AuthSub token=\"$this->token\""
496
- );
497
- $request = join( "\r\n", $headers ) . "\r\n\r\n";
498
- $sock = $this->_get_blogger_sock( $blog['host'] );
499
- if ( ! $sock ) return; // TODO: Error handling
500
- $response = $this->_txrx( $sock, $request );
501
-
502
- $response = $this->parse_response( $response );
503
-
504
- // Extract the comments and send for insertion
505
- preg_match_all( '/<entry[^>]*>.*?<\/entry>/s', $response['body'], $matches );
506
- if ( count( $matches[0] ) ) {
507
- $entries = array_reverse( $matches[0] );
508
- foreach ( $entries as $entry ) {
509
- $entry = "<feed>$entry</feed>";
510
- $AtomParser = new AtomParser();
511
- $AtomParser->parse( $entry );
512
- $this->import_comment($AtomParser->entry);
513
- unset($AtomParser);
514
- }
515
- }
516
-
517
- // Get the 'previous' query string which we'll use on the next iteration
518
- $query = '';
519
- $links = preg_match_all('/<link([^>]*)>/', $response['body'], $matches);
520
- if ( count( $matches[1] ) )
521
- foreach ( $matches[1] as $match )
522
- if ( preg_match('/rel=.previous./', $match) )
523
- $query = @html_entity_decode( preg_replace('/^.*href=[\'"].*\?(.+)[\'"].*$/', '$1', $match), ENT_COMPAT, get_option('blog_charset') );
524
-
525
- parse_str($query, $q);
526
-
527
- $this->blogs[$importing_blog]['comments_start_index'] = (int) $q['start-index'];
528
- $this->save_vars();
529
- } while ( !empty( $query ) && $this->have_time() );
530
- }
531
- $this->blogs[$importing_blog]['mode'] = 'authors';
532
- $this->save_vars();
533
- if ( !$this->blogs[$importing_blog]['posts_done'] && !$this->blogs[$importing_blog]['comments_done'] )
534
- die('nothing');
535
- do_action('import_done', 'blogger');
536
- die('done');
537
- }
538
-
539
- function convert_date( $date ) {
540
- preg_match('#([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(?:\.[0-9]+)?(Z|[\+|\-][0-9]{2,4}){0,1}#', $date, $date_bits);
541
- $offset = iso8601_timezone_to_offset( $date_bits[7] );
542
- $timestamp = gmmktime($date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]);
543
- $timestamp -= $offset; // Convert from Blogger local time to GMT
544
- $timestamp += get_option('gmt_offset') * 3600; // Convert from GMT to WP local time
545
- return gmdate('Y-m-d H:i:s', $timestamp);
546
- }
547
-
548
- function no_apos( $string ) {
549
- return str_replace( '&apos;', "'", $string);
550
- }
551
-
552
- function min_whitespace( $string ) {
553
- return preg_replace( '|\s+|', ' ', $string );
554
- }
555
-
556
- function _normalize_tag( $matches ) {
557
- return '<' . strtolower( $matches[1] );
558
- }
559
-
560
- function import_post( $entry ) {
561
- global $importing_blog;
562
-
563
- // The old permalink is all Blogger gives us to link comments to their posts.
564
- if ( isset( $entry->draft ) )
565
- $rel = 'self';
566
- else
567
- $rel = 'alternate';
568
- foreach ( $entry->links as $link ) {
569
- if ( $link['rel'] == $rel ) {
570
- $parts = parse_url( $link['href'] );
571
- $entry->old_permalink = $parts['path'];
572
- break;
573
- }
574
- }
575
-
576
- $post_date = $this->convert_date( $entry->published );
577
- $post_content = trim( addslashes( $this->no_apos( @html_entity_decode( $entry->content, ENT_COMPAT, get_option('blog_charset') ) ) ) );
578
- $post_title = trim( addslashes( $this->no_apos( $this->min_whitespace( $entry->title ) ) ) );
579
- $post_status = isset( $entry->draft ) ? 'draft' : 'publish';
580
-
581
- // Clean up content
582
- $post_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content);
583
- $post_content = str_replace('<br>', '<br />', $post_content);
584
- $post_content = str_replace('<hr>', '<hr />', $post_content);
585
-
586
- // Checks for duplicates
587
- if ( isset( $this->blogs[$importing_blog]['posts'][$entry->old_permalink] ) ) {
588
- ++$this->blogs[$importing_blog]['posts_skipped'];
589
- } elseif ( $post_id = post_exists( $post_title, $post_content, $post_date ) ) {
590
- $this->blogs[$importing_blog]['posts'][$entry->old_permalink] = $post_id;
591
- ++$this->blogs[$importing_blog]['posts_skipped'];
592
- } else {
593
- $post = compact('post_date', 'post_content', 'post_title', 'post_status');
594
-
595
- $post_id = wp_insert_post($post);
596
- if ( is_wp_error( $post_id ) )
597
- return $post_id;
598
-
599
- wp_create_categories( array_map( 'addslashes', $entry->categories ), $post_id );
600
-
601
- $author = $this->no_apos( strip_tags( $entry->author ) );
602
-
603
- add_post_meta( $post_id, 'blogger_blog', $this->blogs[$importing_blog]['host'], true );
604
- add_post_meta( $post_id, 'blogger_author', $author, true );
605
- add_post_meta( $post_id, 'blogger_permalink', $entry->old_permalink, true );
606
-
607
- $this->blogs[$importing_blog]['posts'][$entry->old_permalink] = $post_id;
608
- ++$this->blogs[$importing_blog]['posts_done'];
609
- }
610
- $this->save_vars();
611
- return;
612
- }
613
-
614
- function import_comment( $entry ) {
615
- global $importing_blog;
616
-
617
- // Drop the #fragment and we have the comment's old post permalink.
618
- foreach ( $entry->links as $link ) {
619
- if ( $link['rel'] == 'alternate' ) {
620
- $parts = parse_url( $link['href'] );
621
- $entry->old_permalink = $parts['fragment'];
622
- $entry->old_post_permalink = $parts['path'];
623
- break;
624
- }
625
- }
626
-
627
- $comment_post_ID = (int) $this->blogs[$importing_blog]['posts'][$entry->old_post_permalink];
628
- preg_match('#<name>(.+?)</name>.*(?:\<uri>(.+?)</uri>)?#', $entry->author, $matches);
629
- $comment_author = addslashes( $this->no_apos( strip_tags( (string) $matches[1] ) ) );
630
- $comment_author_url = addslashes( $this->no_apos( strip_tags( (string) $matches[2] ) ) );
631
- $comment_date = $this->convert_date( $entry->updated );
632
- $comment_content = addslashes( $this->no_apos( @html_entity_decode( $entry->content, ENT_COMPAT, get_option('blog_charset') ) ) );
633
-
634
- // Clean up content
635
- $comment_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $comment_content);
636
- $comment_content = str_replace('<br>', '<br />', $comment_content);
637
- $comment_content = str_replace('<hr>', '<hr />', $comment_content);
638
-
639
- // Checks for duplicates
640
- if (
641
- isset( $this->blogs[$importing_blog]['comments'][$entry->old_permalink] ) ||
642
- comment_exists( $comment_author, $comment_date )
643
- ) {
644
- ++$this->blogs[$importing_blog]['comments_skipped'];
645
- } else {
646
- $comment = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_date', 'comment_content');
647
-
648
- $comment = wp_filter_comment($comment);
649
- $comment_id = wp_insert_comment($comment);
650
-
651
- $this->blogs[$importing_blog]['comments'][$entry->old_permalink] = $comment_id;
652
-
653
- ++$this->blogs[$importing_blog]['comments_done'];
654
- }
655
- $this->save_vars();
656
- }
657
-
658
- function get_js_status($blog = false) {
659
- global $importing_blog;
660
- if ( $blog === false )
661
- $blog = $this->blogs[$importing_blog];
662
- else
663
- $blog = $this->blogs[$blog];
664
- $p1 = isset( $blog['posts_done'] ) ? (int) $blog['posts_done'] : 0;
665
- $p2 = isset( $blog['total_posts'] ) ? (int) $blog['total_posts'] : 0;
666
- $c1 = isset( $blog['comments_done'] ) ? (int) $blog['comments_done'] : 0;
667
- $c2 = isset( $blog['total_comments'] ) ? (int) $blog['total_comments'] : 0;
668
- return "{p1:$p1,p2:$p2,c1:$c1,c2:$c2}";
669
- }
670
-
671
- function get_author_form($blog = false) {
672
- global $importing_blog, $wpdb, $current_user;
673
- if ( $blog === false )
674
- $blog = & $this->blogs[$importing_blog];
675
- else
676
- $blog = & $this->blogs[$blog];
677
-
678
- if ( !isset( $blog['authors'] ) ) {
679
- $post_ids = array_values($blog['posts']);
680
- $authors = (array) $wpdb->get_col("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = 'blogger_author' AND post_id IN (" . join( ',', $post_ids ) . ")");
681
- $blog['authors'] = array_map(null, $authors, array_fill(0, count($authors), $current_user->ID));
682
- $this->save_vars();
683
- }
684
-
685
- $directions = sprintf( __('All posts were imported with the current user as author. Use this form to move each Blogger user&#8217;s posts to a different WordPress user. You may <a href="%s">add users</a> and then return to this page and complete the user mapping. This form may be used as many times as you like until you activate the &#8220;Restart&#8221; function below.', 'blogger-importer'), 'users.php' );
686
- $heading = __('Author mapping', 'blogger-importer');
687
- $blogtitle = "{$blog['title']} ({$blog['host']})";
688
- $mapthis = __('Blogger username', 'blogger-importer');
689
- $tothis = __('WordPress login', 'blogger-importer');
690
- $submit = esc_js( __('Save Changes', 'blogger-importer') );
691
-
692
- foreach ( $blog['authors'] as $i => $author )
693
- $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>";
694
-
695
- 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='" . esc_attr($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>";
696
- }
697
-
698
- function get_user_options($current) {
699
- global $importer_users;
700
- if ( ! isset( $importer_users ) )
701
- $importer_users = (array) get_users_of_blog();
702
-
703
- foreach ( $importer_users as $user ) {
704
- $sel = ( $user->user_id == $current ) ? " selected='selected'" : '';
705
- $options .= "<option value='$user->user_id'$sel>$user->display_name</option>";
706
- }
707
-
708
- return $options;
709
- }
710
-
711
- function save_authors() {
712
- global $importing_blog, $wpdb;
713
- $authors = (array) $_POST['authors'];
714
-
715
- $host = $this->blogs[$importing_blog]['host'];
716
-
717
- // Get an array of posts => authors
718
- $post_ids = (array) $wpdb->get_col( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'blogger_blog' AND meta_value = %s", $host) );
719
- $post_ids = join( ',', $post_ids );
720
- $results = (array) $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = 'blogger_author' AND post_id IN ($post_ids)");
721
- foreach ( $results as $row )
722
- $authors_posts[$row->post_id] = $row->meta_value;
723
-
724
- foreach ( $authors as $author => $user_id ) {
725
- $user_id = (int) $user_id;
726
-
727
- // Skip authors that haven't been changed
728
- if ( $user_id == $this->blogs[$importing_blog]['authors'][$author][1] )
729
- continue;
730
-
731
- // Get a list of the selected author's posts
732
- $post_ids = (array) array_keys( $authors_posts, $this->blogs[$importing_blog]['authors'][$author][0] );
733
- $post_ids = join( ',', $post_ids);
734
-
735
- $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_author = %d WHERE id IN ($post_ids)", $user_id) );
736
- $this->blogs[$importing_blog]['authors'][$author][1] = $user_id;
737
- }
738
- $this->save_vars();
739
-
740
- wp_redirect('edit.php');
741
- }
742
-
743
- function _get_auth_sock() {
744
- // Connect to https://www.google.com
745
- if ( !$sock = @ fsockopen('ssl://www.google.com', 443, $errno, $errstr) ) {
746
- $this->uh_oh(
747
- __('Could not connect to https://www.google.com', 'blogger-importer'),
748
- __('There was a problem opening a secure connection to Google. This is what went wrong:', 'blogger-importer'),
749
- "$errstr ($errno)"
750
- );
751
- return false;
752
- }
753
- return $sock;
754
- }
755
-
756
- function _get_blogger_sock($host = 'www2.blogger.com') {
757
- if ( !$sock = @ fsockopen($host, 80, $errno, $errstr) ) {
758
- $this->uh_oh(
759
- sprintf( __('Could not connect to %s', 'blogger-importer'), $host ),
760
- __('There was a problem opening a connection to Blogger. This is what went wrong:', 'blogger-importer'),
761
- "$errstr ($errno)"
762
- );
763
- return false;
764
- }
765
- return $sock;
766
- }
767
-
768
- function _txrx( $sock, $request ) {
769
- fwrite( $sock, $request );
770
- while ( ! feof( $sock ) )
771
- $response .= @ fread ( $sock, 8192 );
772
- fclose( $sock );
773
- return $response;
774
- }
775
-
776
- function revoke($token) {
777
- $headers = array(
778
- "GET /accounts/AuthSubRevokeToken HTTP/1.0",
779
- "Authorization: AuthSub token=\"$token\""
780
- );
781
- $request = join( "\r\n", $headers ) . "\r\n\r\n";
782
- $sock = $this->_get_auth_sock( );
783
- if ( ! $sock ) return false;
784
- $this->_txrx( $sock, $request );
785
- }
786
-
787
- function restart() {
788
- global $wpdb;
789
- $options = get_option( 'blogger_importer' );
790
-
791
- if ( isset( $options['token'] ) )
792
- $this->revoke( $options['token'] );
793
-
794
- delete_option('blogger_importer');
795
- $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key = 'blogger_author'");
796
- wp_redirect('?import=blogger');
797
- }
798
-
799
- // Returns associative array of code, header, cookies, body. Based on code from php.net.
800
- function parse_response($this_response) {
801
- // Split response into header and body sections
802
- list($response_headers, $response_body) = explode("\r\n\r\n", $this_response, 2);
803
- $response_header_lines = explode("\r\n", $response_headers);
804
-
805
- // First line of headers is the HTTP response code
806
- $http_response_line = array_shift($response_header_lines);
807
- if (preg_match('@^HTTP/[0-9]\.[0-9] ([0-9]{3})@',$http_response_line, $matches)) { $response_code = $matches[1]; }
808
-
809
- // put the rest of the headers in an array
810
- $response_header_array = array();
811
- foreach($response_header_lines as $header_line) {
812
- list($header,$value) = explode(': ', $header_line, 2);
813
- $response_header_array[$header] .= $value."\n";
814
- }
815
-
816
- $cookie_array = array();
817
- $cookies = explode("\n", $response_header_array["Set-Cookie"]);
818
- foreach($cookies as $this_cookie) { array_push($cookie_array, "Cookie: ".$this_cookie); }
819
-
820
- return array("code" => $response_code, "header" => $response_header_array, "cookies" => $cookie_array, "body" => $response_body);
821
- }
822
-
823
- // Step 9: Congratulate the user
824
- function congrats() {
825
- $blog = (int) $_GET['blog'];
826
- echo '<h1>'.__('Congratulations!', 'blogger-importer').'</h1><p>'.__('Now that you have imported your Blogger blog into WordPress, what are you going to do? Here are some suggestions:', 'blogger-importer').'</p><ul><li>'.__('That was hard work! Take a break.', 'blogger-importer').'</li>';
827
- if ( count($this->import['blogs']) > 1 )
828
- echo '<li>'.__('In case you haven&#8217;t done it already, you can import the posts from your other blogs:', 'blogger-importer'). $this->show_blogs() . '</li>';
829
- if ( $n = count($this->import['blogs'][$blog]['newusers']) )
830
- echo '<li>'.sprintf(__('Go to <a href="%s" target="%s">Authors &amp; Users</a>, where you can modify the new user(s) 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.', 'blogger-importer'), 'users.php', '_parent').'</li>';
831
- echo '<li>'.__('For security, click the link below to reset this importer.', 'blogger-importer').'</li>';
832
- echo '</ul>';
833
- }
834
-
835
- // Figures out what to do, then does it.
836
- function start() {
837
- if ( isset($_POST['restart']) )
838
- $this->restart();
839
-
840
- $options = get_option('blogger_importer');
841
-
842
- if ( is_array($options) )
843
- foreach ( $options as $key => $value )
844
- $this->$key = $value;
845
-
846
- if ( isset( $_REQUEST['blog'] ) ) {
847
- $blog = is_array($_REQUEST['blog']) ? array_shift( $keys = array_keys( $_REQUEST['blog'] ) ) : $_REQUEST['blog'];
848
- $blog = (int) $blog;
849
- $result = $this->import_blog( $blog );
850
- if ( is_wp_error( $result ) )
851
- echo $result->get_error_message();
852
- } elseif ( isset($_GET['token']) )
853
- $this->auth();
854
- elseif ( isset($this->token) && $this->token_is_valid() )
855
- $this->show_blogs();
856
- else
857
- $this->greet();
858
-
859
- $saved = $this->save_vars();
860
-
861
- if ( $saved && !isset($_GET['noheader']) ) {
862
- $restart = __('Restart', 'blogger-importer');
863
- $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.', 'blogger-importer');
864
- $submit = esc_attr__('Clear account information', 'blogger-importer');
865
- 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>";
866
- }
867
- }
868
-
869
- function save_vars() {
870
- $vars = get_object_vars($this);
871
- update_option( 'blogger_importer', $vars );
872
-
873
- return !empty($vars);
874
- }
875
-
876
- function admin_head() {
877
- ?>
878
- <style type="text/css">
879
- td { text-align: center; line-height: 2em;}
880
- thead td { font-weight: bold; }
881
- .bar {
882
- width: 200px;
883
- text-align: left;
884
- line-height: 2em;
885
- padding: 0px;
886
- }
887
- .ind {
888
- position: absolute;
889
- background-color: #83B4D8;
890
- width: 1px;
891
- z-index: 9;
892
- }
893
- .stat {
894
- z-index: 10;
895
- position: relative;
896
- text-align: center;
897
- }
898
- </style>
899
- <?php
900
- }
901
-
902
- function Blogger_Import() {
903
- global $importer_started;
904
- $importer_started = time();
905
- if ( isset( $_GET['import'] ) && $_GET['import'] == 'blogger' ) {
906
- wp_enqueue_script('jquery');
907
- add_action('admin_head', array(&$this, 'admin_head'));
908
- }
909
- }
910
- }
911
-
912
- $blogger_import = new Blogger_Import();
913
-
914
- register_importer('blogger', __('Blogger', 'blogger-importer'), __('Import posts, comments, and users from a Blogger blog.', 'blogger-importer'), array ($blogger_import, 'start'));
915
-
916
- class AtomEntry {
917
- var $links = array();
918
- var $categories = array();
919
- }
920
-
921
- class AtomParser {
922
-
923
- var $ATOM_CONTENT_ELEMENTS = array('content','summary','title','subtitle','rights');
924
- var $ATOM_SIMPLE_ELEMENTS = array('id','updated','published','draft','author');
925
-
926
- var $depth = 0;
927
- var $indent = 2;
928
- var $in_content;
929
- var $ns_contexts = array();
930
- var $ns_decls = array();
931
- var $is_xhtml = false;
932
- var $skipped_div = false;
933
-
934
- var $entry;
935
-
936
- function AtomParser() {
937
- $this->entry = new AtomEntry();
938
- }
939
-
940
- function _map_attrs_func( $k, $v ) {
941
- return "$k=\"$v\"";
942
- }
943
-
944
- function _map_xmlns_func( $p, $n ) {
945
- $xd = "xmlns";
946
- if ( strlen( $n[0] ) > 0 )
947
- $xd .= ":{$n[0]}";
948
-
949
- return "{$xd}=\"{$n[1]}\"";
950
- }
951
-
952
- function parse($xml) {
953
-
954
- global $app_logging;
955
- array_unshift($this->ns_contexts, array());
956
-
957
- $parser = xml_parser_create_ns();
958
- xml_set_object($parser, $this);
959
- xml_set_element_handler($parser, "start_element", "end_element");
960
- xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
961
- xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,0);
962
- xml_set_character_data_handler($parser, "cdata");
963
- xml_set_default_handler($parser, "_default");
964
- xml_set_start_namespace_decl_handler($parser, "start_ns");
965
- xml_set_end_namespace_decl_handler($parser, "end_ns");
966
-
967
- $contents = "";
968
-
969
- xml_parse($parser, $xml);
970
-
971
- xml_parser_free($parser);
972
-
973
- return true;
974
- }
975
-
976
- function start_element($parser, $name, $attrs) {
977
-
978
- $tag = array_pop(split(":", $name));
979
-
980
- array_unshift($this->ns_contexts, $this->ns_decls);
981
-
982
- $this->depth++;
983
-
984
- if (!empty($this->in_content)) {
985
- $attrs_prefix = array();
986
-
987
- // resolve prefixes for attributes
988
- foreach($attrs as $key => $value) {
989
- $attrs_prefix[$this->ns_to_prefix($key)] = $this->xml_escape($value);
990
- }
991
- $attrs_str = join(' ', array_map( array( &$this, '_map_attrs_func' ), array_keys($attrs_prefix), array_values($attrs_prefix)));
992
- if (strlen($attrs_str) > 0) {
993
- $attrs_str = " " . $attrs_str;
994
- }
995
-
996
- $xmlns_str = join(' ', array_map( array( &$this, '_map_xmlns_func' ), array_keys($this->ns_contexts[0]), array_values($this->ns_contexts[0])));
997
- if (strlen($xmlns_str) > 0) {
998
- $xmlns_str = " " . $xmlns_str;
999
- }
1000
-
1001
- // handle self-closing tags (case: a new child found right-away, no text node)
1002
- if (count($this->in_content) == 2) {
1003
- array_push($this->in_content, ">");
1004
- }
1005
-
1006
- array_push($this->in_content, "<". $this->ns_to_prefix($name) ."{$xmlns_str}{$attrs_str}");
1007
- } else if (in_array($tag, $this->ATOM_CONTENT_ELEMENTS) || in_array($tag, $this->ATOM_SIMPLE_ELEMENTS)) {
1008
- $this->in_content = array();
1009
- $this->is_xhtml = $attrs['type'] == 'xhtml';
1010
- array_push($this->in_content, array($tag,$this->depth));
1011
- } else if ($tag == 'link') {
1012
- array_push($this->entry->links, $attrs);
1013
- } else if ($tag == 'category') {
1014
- array_push($this->entry->categories, $attrs['term']);
1015
- }
1016
-
1017
- $this->ns_decls = array();
1018
- }
1019
-
1020
- function end_element($parser, $name) {
1021
-
1022
- $tag = array_pop(split(":", $name));
1023
-
1024
- if (!empty($this->in_content)) {
1025
- if ($this->in_content[0][0] == $tag &&
1026
- $this->in_content[0][1] == $this->depth) {
1027
- array_shift($this->in_content);
1028
- if ($this->is_xhtml) {
1029
- $this->in_content = array_slice($this->in_content, 2, count($this->in_content)-3);
1030
- }
1031
- $this->entry->$tag = join('',$this->in_content);
1032
- $this->in_content = array();
1033
- } else {
1034
- $endtag = $this->ns_to_prefix($name);
1035
- if (strpos($this->in_content[count($this->in_content)-1], '<' . $endtag) !== false) {
1036
- array_push($this->in_content, "/>");
1037
- } else {
1038
- array_push($this->in_content, "</$endtag>");
1039
- }
1040
- }
1041
- }
1042
-
1043
- array_shift($this->ns_contexts);
1044
-
1045
- #print str_repeat(" ", $this->depth * $this->indent) . "end_element('$name')" ."\n";
1046
-
1047
- $this->depth--;
1048
- }
1049
-
1050
- function start_ns($parser, $prefix, $uri) {
1051
- #print str_repeat(" ", $this->depth * $this->indent) . "starting: " . $prefix . ":" . $uri . "\n";
1052
- array_push($this->ns_decls, array($prefix,$uri));
1053
- }
1054
-
1055
- function end_ns($parser, $prefix) {
1056
- #print str_repeat(" ", $this->depth * $this->indent) . "ending: #" . $prefix . "#\n";
1057
- }
1058
-
1059
- function cdata($parser, $data) {
1060
- #print str_repeat(" ", $this->depth * $this->indent) . "data: #" . $data . "#\n";
1061
- if (!empty($this->in_content)) {
1062
- // handle self-closing tags (case: text node found, need to close element started)
1063
- if (strpos($this->in_content[count($this->in_content)-1], '<') !== false) {
1064
- array_push($this->in_content, ">");
1065
- }
1066
- array_push($this->in_content, $this->xml_escape($data));
1067
- }
1068
- }
1069
-
1070
- function _default($parser, $data) {
1071
- # when does this gets called?
1072
- }
1073
-
1074
-
1075
- function ns_to_prefix($qname) {
1076
- $components = split(":", $qname);
1077
- $name = array_pop($components);
1078
-
1079
- if (!empty($components)) {
1080
- $ns = join(":",$components);
1081
- foreach ($this->ns_contexts as $context) {
1082
- foreach ($context as $mapping) {
1083
- if ($mapping[1] == $ns && strlen($mapping[0]) > 0) {
1084
- return "$mapping[0]:$name";
1085
- }
1086
- }
1087
- }
1088
- }
1089
- return $name;
1090
- }
1091
-
1092
- function xml_escape($string)
1093
- {
1094
- return str_replace(array('&','"',"'",'<','>'),
1095
- array('&amp;','&quot;','&apos;','&lt;','&gt;'),
1096
- $string );
1097
- }
1098
- }
1099
- } // class_exists( 'WP_Importer' )
1100
-
1101
- function blogger_importer_init() {
1102
- load_plugin_textdomain( 'blogger-importer', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
1103
- }
1104
- add_action( 'init', 'blogger_importer_init' );
1
+ <?php
2
+ /*
3
+ Plugin Name: Blogger Importer
4
+ Plugin URI: http://wordpress.org/extend/plugins/blogger-importer/
5
+ Description: Import posts, comments, and tags from a Blogger blog and migrate authors to Wordpress users.
6
+ Author: wordpressdotorg
7
+ Author URI: http://wordpress.org/
8
+ Version: 0.5
9
+ License: GPLv2
10
+ License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11
+ */
12
+
13
+ if (!defined('WP_LOAD_IMPORTERS'))
14
+ return;
15
+
16
+ // Load Importer API
17
+ require_once ABSPATH . 'wp-admin/includes/import.php';
18
+
19
+ // Load Simple Pie
20
+ require_once ABSPATH . WPINC . '/class-feed.php';
21
+ require_once 'blogger-importer-sanitize.php';
22
+ require_once 'blogger-importer-blogitem.php';
23
+
24
+ // Load OAuth library
25
+ require_once 'oauth.php';
26
+
27
+ if (!class_exists('WP_Importer'))
28
+ {
29
+ $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
30
+ if (file_exists($class_wp_importer))
31
+ require_once $class_wp_importer;
32
+ }
33
+
34
+ /**
35
+ * How many records per GData query
36
+ *
37
+ * @package WordPress
38
+ * @subpackage Blogger_Import
39
+ * @var int
40
+ * @since unknown
41
+ */
42
+ define('MAX_RESULTS', 25);
43
+
44
+ /**
45
+ * How many seconds to let the script run
46
+ *
47
+ * @package WordPress
48
+ * @subpackage Blogger_Import
49
+ * @var int
50
+ * @since unknown
51
+ */
52
+ define('MAX_EXECUTION_TIME', 20);
53
+
54
+ /**
55
+ * How many seconds between status bar updates
56
+ *
57
+ * @package WordPress
58
+ * @subpackage Blogger_Import
59
+ * @var int
60
+ * @since unknown
61
+ */
62
+ define('STATUS_INTERVAL', 3);
63
+
64
+ /**
65
+ * Blogger Importer
66
+ *
67
+ * @package WordPress
68
+ * @subpackage Importer
69
+ */
70
+ if (class_exists('WP_Importer'))
71
+ {
72
+ class Blogger_Import extends WP_Importer
73
+ {
74
+
75
+ function Blogger_Import()
76
+ {
77
+ global $importer_started;
78
+ $importer_started = time();
79
+ if (isset($_GET['import']) && $_GET['import'] == 'blogger')
80
+ {
81
+ add_action('admin_print_scripts', array(&$this, 'queue_scripts'));
82
+ add_action('admin_print_styles', array(&$this, 'queue_style'));
83
+ }
84
+ }
85
+
86
+ function queue_scripts($hook)
87
+ {
88
+ wp_enqueue_script('jquery');
89
+ }
90
+
91
+ function queue_style()
92
+ {
93
+ wp_enqueue_style('BloggerImporter', plugins_url('/blogger-importer.css', __file__));
94
+ }
95
+
96
+ // Shows the welcome screen and the magic auth link.
97
+ function greet()
98
+ {
99
+ $next_url = get_option('siteurl') . '/wp-admin/index.php?import=blogger&amp;noheader=true';
100
+ $auth_url = $this->get_oauth_link();
101
+ $title = __('Import Blogger', 'blogger-importer');
102
+ $welcome = __('Howdy! This importer allows you to import posts and comments from your Blogger account into your WordPress site.', 'blogger-importer');
103
+ $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).', 'blogger-importer');
104
+ $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.', 'blogger-importer');
105
+ $auth = esc_attr__('Authorize', 'blogger-importer');
106
+
107
+ echo "
108
+ <div class='wrap'>
109
+ " . screen_icon() . "
110
+ <h2>$title</h2>
111
+ <p>$welcome</p><p>$prereqs</p><p>$stepone</p>
112
+ <form action='{$auth_url['url']}' method='get'>
113
+ <p class='submit' style='text-align:left;'>
114
+ <input type='submit' class='button' value='$auth' />
115
+ <input type='hidden' name='oauth_token' value='{$auth_url['oauth_token']}' />
116
+ <input type='hidden' name='oauth_callback' value='{$auth_url['oauth_callback']}' />
117
+ </p>
118
+ </form>
119
+ </div>\n";
120
+ }
121
+
122
+ function get_oauth_link()
123
+ {
124
+ // Establish an Blogger_OAuth consumer
125
+ $base_url = get_option('siteurl') . '/wp-admin';
126
+ $request_token_endpoint = 'https://www.google.com/accounts/OAuthGetRequestToken';
127
+ $authorize_endpoint = 'https://www.google.com/accounts/OAuthAuthorizeToken';
128
+
129
+ $test_consumer = new Blogger_OAuthConsumer('anonymous', 'anonymous', null); // anonymous is a google thing to allow non-registered apps to work
130
+
131
+ //prepare to get request token
132
+ $sig_method = new Blogger_OAuthSignatureMethod_HMAC_SHA1();
133
+ $parsed = parse_url($request_token_endpoint);
134
+ $params = array('callback' => $base_url, 'scope' => 'http://www.blogger.com/feeds/', 'xoauth_displayname' => 'WordPress');
135
+
136
+ $req_req = Blogger_OAuthRequest::from_consumer_and_token($test_consumer, null, "GET", $request_token_endpoint, $params);
137
+ $req_req->sign_request($sig_method, $test_consumer, null);
138
+
139
+ // go get the request tokens from Google
140
+ $req_token = wp_remote_retrieve_body(wp_remote_get($req_req->to_url(), array('sslverify' => false)));
141
+
142
+ // parse the tokens
143
+ parse_str($req_token, $tokens);
144
+
145
+ $oauth_token = $tokens['oauth_token'];
146
+ $oauth_token_secret = $tokens['oauth_token_secret'];
147
+
148
+ $callback_url = "$base_url/index.php?import=blogger&noheader=true&token=$oauth_token&token_secret=$oauth_token_secret";
149
+
150
+ return array('url' => $authorize_endpoint, 'oauth_token' => $oauth_token, 'oauth_callback' => $callback_url);
151
+ }
152
+
153
+ function uh_oh($title, $message, $info)
154
+ {
155
+ echo "<div class='wrap'>";
156
+ screen_icon();
157
+ echo "<h2>$title</h2><p>$message</p><pre>$info</pre></div>";
158
+ }
159
+
160
+ function auth()
161
+ {
162
+ // we have a authorized request token now, so upgrade it to an access token
163
+ $token = $_GET['token'];
164
+ $token_secret = $_GET['token_secret'];
165
+
166
+ $oauth_access_token_endpoint = 'https://www.google.com/accounts/OAuthGetAccessToken';
167
+
168
+ // auth the token
169
+ $test_consumer = new Blogger_OAuthConsumer('anonymous', 'anonymous', null);
170
+ $auth_token = new Blogger_OAuthConsumer($token, $token_secret);
171
+ $access_token_req = new Blogger_OAuthRequest("GET", $oauth_access_token_endpoint);
172
+ $access_token_req = $access_token_req->from_consumer_and_token($test_consumer, $auth_token, "GET", $oauth_access_token_endpoint);
173
+
174
+ $access_token_req->sign_request(new Blogger_OAuthSignatureMethod_HMAC_SHA1(), $test_consumer, $auth_token);
175
+
176
+ $after_access_request = wp_remote_retrieve_body(wp_remote_get($access_token_req->to_url(), array('sslverify' => false)));
177
+
178
+ parse_str($after_access_request, $access_tokens);
179
+
180
+ $this->token = $access_tokens['oauth_token'];
181
+ $this->token_secret = $access_tokens['oauth_token_secret'];
182
+
183
+ wp_redirect(remove_query_arg(array('token', 'noheader')));
184
+ }
185
+
186
+ // get a URL using the oauth token for authentication (returns false on failure)
187
+ function oauth_get($url, $params = null)
188
+ {
189
+ $test_consumer = new Blogger_OAuthConsumer('anonymous', 'anonymous', null);
190
+ $goog = new Blogger_OAuthConsumer($this->token, $this->token_secret, null);
191
+ $request = new Blogger_OAuthRequest("GET", $url, $params);
192
+
193
+ //Ref: Not importing properly http://core.trac.wordpress.org/ticket/19096
194
+ $blog_req = $request->from_consumer_and_token($test_consumer, $goog, 'GET', $url, $params);
195
+
196
+ $blog_req->sign_request(new Blogger_OAuthSignatureMethod_HMAC_SHA1(), $test_consumer, $goog);
197
+
198
+ $data = wp_remote_get($blog_req->to_url(), array('sslverify' => false));
199
+
200
+ if (wp_remote_retrieve_response_code($data) == 200)
201
+ {
202
+ $response = wp_remote_retrieve_body($data);
203
+ } else
204
+ {
205
+ $response == false;
206
+ }
207
+
208
+ return $response;
209
+ }
210
+
211
+ function show_blogs($iter = 0)
212
+ {
213
+ if (empty($this->blogs))
214
+ {
215
+ $xml = $this->oauth_get('https://www.blogger.com/feeds/default/blogs');
216
+
217
+ // Give it a few retries... this step often flakes out the first time.
218
+ if (empty($xml))
219
+ {
220
+ if ($iter < 3)
221
+ {
222
+ return $this->show_blogs($iter + 1);
223
+ } else
224
+ {
225
+ $this->uh_oh(__('Trouble signing in', 'blogger-importer'), __('We were not able to gain access to your account. Try starting over.', 'blogger-importer'), '');
226
+ return false;
227
+ }
228
+ }
229
+
230
+ $feed = new SimplePie();
231
+ $feed->set_raw_data($xml);
232
+ $feed->init();
233
+
234
+ foreach ($feed->get_items() as $item)
235
+ {
236
+ $blog = array(); //reset
237
+ $blog['title'] = $item->get_title();
238
+ $blog['summary'] = $item->get_description();
239
+
240
+ //ID is of the form tag:blogger.com,1999:blog-417730729915399755
241
+ //We need that number from the end
242
+ $rawid = explode('-', $item->get_id());
243
+ $blog['id'] = $rawid[count($rawid) - 1];
244
+
245
+ $parts = parse_url($item->get_link(0, 'alternate'));
246
+ $blog['host'] = $parts['host'];
247
+ $blog['gateway'] = $item->get_link(0, 'edit');
248
+ $blog['posts_url'] = $item->get_link(0, 'http://schemas.google.com/g/2005#post');
249
+
250
+ //AGC:20/4/2012 Developers guide suggests that the correct feed is located as follows
251
+ //See https://developers.google.com/blogger/docs/1.0/developers_guide_php
252
+ $blog['comments_url'] = "http://www.blogger.com/feeds/{$blog['id']}/comments/default";
253
+
254
+ if (!empty($blog))
255
+ {
256
+ $blog['total_posts'] = $this->get_total_results($blog['posts_url']);
257
+ $blog['total_comments'] = $this->get_total_results($blog['comments_url']);
258
+
259
+ $blog['mode'] = 'init';
260
+ $this->blogs[] = $blog;
261
+ }
262
+
263
+ }
264
+
265
+ if (empty($this->blogs))
266
+ {
267
+ $this->uh_oh(__('No blogs found', 'blogger-importer'), __('We were able to log in but there were no blogs. Try a different account next time.', 'blogger-importer'), '');
268
+ return false;
269
+ }
270
+ }
271
+
272
+ //Should probably be using WP_LIST_TABLE here rather than manually rendering a table in html
273
+ //http://wpengineer.com/2426/wp_list_table-a-step-by-step-guide/
274
+ //echo '<pre>'.print_r($this,1).'</pre>';
275
+ $start = esc_js(__('Import', 'blogger-importer'));
276
+ $continue = esc_js(__('Continue', 'blogger-importer'));
277
+ $stop = esc_js(__('Importing...', 'blogger-importer'));
278
+ $authors = esc_js(__('Set Authors', 'blogger-importer'));
279
+ $loadauth = esc_js(__('Preparing author mapping form...', 'blogger-importer'));
280
+ $authhead = esc_js(__('Final Step: Author Mapping', 'blogger-importer'));
281
+ $nothing = esc_js(__('Nothing was imported. Had you already imported this blog?', 'blogger-importer'));
282
+ $stopping = ''; //Missing String used below.
283
+ $title = __('Blogger Blogs', 'blogger-importer');
284
+ $name = __('Blog Name', 'blogger-importer');
285
+ $url = __('Blog URL', 'blogger-importer');
286
+ $action = __('The Magic Button', 'blogger-importer');
287
+ $posts = __('Posts', 'blogger-importer');
288
+ $comments = __('Comments', 'blogger-importer');
289
+ $noscript = __('This feature requires Javascript but it seems to be disabled. Please enable Javascript and then reload this page. Don&#8217;t worry, you can turn it back off when you&#8217;re done.',
290
+ 'blogger-importer');
291
+
292
+ $interval = STATUS_INTERVAL * 1000;
293
+ $init = '';
294
+ $rows = '';
295
+
296
+ foreach ($this->blogs as $i => $blog)
297
+ {
298
+ if ($blog['mode'] == 'init')
299
+ $value = $start;
300
+ elseif ($blog['mode'] == 'posts' || $blog['mode'] == 'comments')
301
+ $value = $continue;
302
+ else
303
+ $value = $authors;
304
+ $value = esc_attr($value);
305
+ $blogtitle = esc_js($blog['title']);
306
+ $pdone = isset($blog['posts_done']) ? (int)$blog['posts_done'] : 0;
307
+ $cdone = isset($blog['comments_done']) ? (int)$blog['comments_done'] : 0;
308
+ $init .= "blogs[$i]=new blog($i,'$blogtitle','{$blog['mode']}','" . $this->get_js_status($i) . '\');';
309
+ $pstat = "<div class='ind' id='pind$i'>&nbsp;</div><div id='pstat$i' class='stat'>$pdone/{$blog['total_posts']}</div>";
310
+ $cstat = "<div class='ind' id='cind$i'>&nbsp;</div><div id='cstat$i' class='stat'>$cdone/{$blog['total_comments']}</div>";
311
+ $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";
312
+ }
313
+
314
+ echo "<div class='wrap'>". screen_icon() ."<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>";
315
+ echo "
316
+ <script type='text/javascript'>
317
+ /* <![CDATA[ */
318
+ var strings = {cont:'$continue',stop:'$stop',stopping:'$stopping',authors:'$authors',nothing:'$nothing'};
319
+ var blogs = {};
320
+ function blog(i, title, mode, status){
321
+ this.blog = i;
322
+ this.mode = mode;
323
+ this.title = title;
324
+ eval('this.status='+status);
325
+ this.button = document.getElementById('submit'+this.blog);
326
+ };
327
+ blog.prototype = {
328
+ start: function() {
329
+ this.cont = true;
330
+ this.kick();
331
+ this.check();
332
+ },
333
+ kick: function() {
334
+ ++this.kicks;
335
+ var i = this.blog;
336
+ jQuery.post('admin.php?import=blogger&noheader=true',{blog:this.blog},function(text,result){blogs[i].kickd(text,result)});
337
+ },
338
+ check: function() {
339
+ ++this.checks;
340
+ var i = this.blog;
341
+ jQuery.post('admin.php?import=blogger&noheader=true&status=true',{blog:this.blog},function(text,result){blogs[i].checkd(text,result)});
342
+ },
343
+ kickd: function(text, result) {
344
+ if ( result == 'error' ) {
345
+ // TODO: exception handling
346
+ if ( this.cont )
347
+ setTimeout('blogs['+this.blog+'].kick()', 1000);
348
+ } else {
349
+ if ( text == 'done' ) {
350
+ this.stop();
351
+ this.done();
352
+ } else if ( text == 'nothing' ) {
353
+ this.stop();
354
+ this.nothing();
355
+ this.done();
356
+ } else if ( text == 'continue' ) {
357
+ this.kick();
358
+ } else if ( this.mode = 'stopped' )
359
+ jQuery(this.button).attr('value', strings.cont);
360
+ }
361
+ --this.kicks;
362
+ },
363
+ checkd: function(text, result) {
364
+ if ( result == 'error' ) {
365
+ // TODO: exception handling
366
+ } else {
367
+ eval('this.status='+text);
368
+ jQuery('#pstat'+this.blog).empty().append(this.status.p1+'/'+this.status.p2);
369
+ jQuery('#cstat'+this.blog).empty().append(this.status.c1+'/'+this.status.c2);
370
+ this.update();
371
+ if ( this.cont || this.kicks > 0 )
372
+ setTimeout('blogs['+this.blog+'].check()', $interval);
373
+ }
374
+ --this.checks;
375
+ },
376
+ update: function() {
377
+ jQuery('#pind'+this.blog).width(((this.status.p1>0&&this.status.p2>0)?(this.status.p1/this.status.p2*jQuery('#pind'+this.blog).parent().width()):1)+'px');
378
+ jQuery('#pstat'+this.blog).attr('title', 'Posts skipped '+this.status.p3);
379
+ jQuery('#cind'+this.blog).width(((this.status.c1>0&&this.status.c2>0)?(this.status.c1/this.status.c2*jQuery('#cind'+this.blog).parent().width()):1)+'px');
380
+ jQuery('#cstat'+this.blog).attr('title', 'Comments skipped '+this.status.c3);
381
+
382
+ },
383
+ stop: function() {
384
+ this.cont = false;
385
+ },
386
+ done: function() {
387
+ this.mode = 'authors';
388
+ jQuery(this.button).attr('value', strings.authors);
389
+ },
390
+ nothing: function() {
391
+ this.mode = 'nothing';
392
+ jQuery(this.button).remove();
393
+ alert(strings.nothing);
394
+ },
395
+ getauthors: function() {
396
+ if ( jQuery('div.wrap').length > 1 )
397
+ jQuery('div.wrap').gt(0).remove();
398
+ jQuery('div.wrap').empty().append('<h2>$authhead</h2><h3>' + this.title + '</h3>');
399
+ jQuery('div.wrap').append('<p id=\"auth\">$loadauth</p>');
400
+ jQuery('p#auth').load('index.php?import=blogger&noheader=true&authors=1',{blog:this.blog});
401
+ },
402
+ init: function() {
403
+ this.update();
404
+ var i = this.blog;
405
+ jQuery(this.button).bind('click', function(){return blogs[i].click();});
406
+ this.kicks = 0;
407
+ this.checks = 0;
408
+ },
409
+ click: function() {
410
+ if ( this.mode == 'init' || this.mode == 'stopped' || this.mode == 'posts' || this.mode == 'comments' ) {
411
+ this.mode = 'started';
412
+ this.start();
413
+ jQuery(this.button).attr('value', strings.stop);
414
+ } else if ( this.mode == 'started' ) {
415
+ return false; // let it run...
416
+ this.mode = 'stopped';
417
+ this.stop();
418
+ if ( this.checks > 0 || this.kicks > 0 ) {
419
+ this.mode = 'stopping';
420
+ jQuery(this.button).attr('value', strings.stopping);
421
+ } else {
422
+ jQuery(this.button).attr('value', strings.cont);
423
+ }
424
+ } else if ( this.mode == 'authors' ) {
425
+ document.location = 'index.php?import=blogger&authors=1&blog='+this.blog;
426
+ //this.mode = 'authors2';
427
+ //this.getauthors();
428
+ }
429
+ return false;
430
+ }
431
+ };
432
+ $init
433
+ jQuery.each(blogs, function(i, me){me.init();});
434
+ /* ]]> */
435
+ </script>\n";
436
+ }
437
+
438
+ // Handy function for stopping the script after a number of seconds.
439
+ function have_time()
440
+ {
441
+ global $importer_started;
442
+ if (time() - $importer_started > MAX_EXECUTION_TIME)
443
+ self::ajax_die('continue');
444
+ return true;
445
+ }
446
+
447
+ function get_total_results($url)
448
+ {
449
+ $response = $this->oauth_get($url, array('max-results' => 1, 'start-index' => 2));
450
+
451
+ $feed = new SimplePie();
452
+ $feed->set_raw_data($response);
453
+ $feed->init();
454
+ $results = $feed->get_channel_tags('http://a9.com/-/spec/opensearchrss/1.0/', 'totalResults');
455
+
456
+ $total_results = $results[0]['data'];
457
+ unset($feed);
458
+ return (int)$total_results;
459
+ }
460
+
461
+ function import_blog($blogID)
462
+ {
463
+ global $importing_blog;
464
+ $importing_blog = $blogID;
465
+
466
+ if (isset($_GET['authors']))
467
+ return print ($this->get_author_form());
468
+
469
+ if (isset($_GET['status']))
470
+ self::ajax_die($this->get_js_status());
471
+
472
+ if (isset($_GET['saveauthors']))
473
+ self::ajax_die($this->save_authors());
474
+
475
+ //Simpler counting for posts as we load them forwards
476
+ if (isset($this->blogs[$importing_blog]['posts_start_index']))
477
+ $start_index = (int)$this->blogs[$importing_blog]['posts_start_index'];
478
+ else
479
+ $start_index = 1;
480
+
481
+ // This will be positive until we have finished importing posts
482
+ if ($start_index > 0)
483
+ {
484
+ // Grab all the posts
485
+ $this->blogs[$importing_blog]['mode'] = 'posts';
486
+ do
487
+ {
488
+
489
+ $index = $struct = $entries = array();
490
+
491
+ $url = $this->blogs[$importing_blog]['posts_url'];
492
+
493
+ $response = $this->oauth_get($url, array('max-results' => MAX_RESULTS, 'start-index' => $start_index));
494
+
495
+ if ($response == false)
496
+ break;
497
+
498
+ // parse the feed
499
+ $feed = new SimplePie();
500
+ $feed->set_item_class('WP_SimplePie_Blog_Item');
501
+ $feed->set_sanitize_class('Blogger_Importer_Sanitize');
502
+ $feed->set_raw_data($response);
503
+ $feed->init();
504
+
505
+ foreach ($feed->get_items() as $item)
506
+ {
507
+
508
+ $blogentry = new BloggerEntry();
509
+
510
+ $blogentry->id = $item->get_id();
511
+ $blogentry->published = $item->get_published();
512
+ $blogentry->updated = $item->get_updated();
513
+ $blogentry->isDraft = $item->get_draft_status($item);
514
+ $blogentry->title = $item->get_title();
515
+ $blogentry->content = $item->get_content();
516
+ $blogentry->author = $item->get_author()->get_name();
517
+ $blogentry->geotags = $item->get_geotags();
518
+
519
+ $linktypes = array('replies', 'edit', 'self', 'alternate');
520
+ foreach ($linktypes as $type)
521
+ {
522
+ $links = $item->get_links($type);
523
+
524
+ if (!is_null($links))
525
+ {
526
+ foreach ($links as $link)
527
+ {
528
+ $blogentry->links[] = array('rel' => $type, 'href' => $link);
529
+ }
530
+ }
531
+ }
532
+
533
+ $cats = $item->get_categories();
534
+
535
+ if (!is_null($cats))
536
+ {
537
+ foreach ($cats as $cat)
538
+ {
539
+ $blogentry->categories[] = $cat->term;
540
+ }
541
+ }
542
+
543
+ $result = $this->import_post($blogentry);
544
+
545
+ //Ref: Not importing properly http://core.trac.wordpress.org/ticket/19096
546
+ //Simplified this section to count what is loaded rather than parsing the results again
547
+ $start_index++;
548
+ }
549
+
550
+ $this->blogs[$importing_blog]['posts_start_index'] = $start_index;
551
+
552
+ $this->save_vars();
553
+
554
+ } while ($this->blogs[$importing_blog]['total_posts'] > $start_index && $this->have_time()); //have time function will "die" if it's out of time
555
+ }
556
+
557
+
558
+ if (isset($this->blogs[$importing_blog]['comments_start_index']))
559
+ $start_index = (int)$this->blogs[$importing_blog]['comments_start_index'];
560
+ else
561
+ $start_index = 1;
562
+
563
+ if ($start_index > 0 && $this->blogs[$importing_blog]['total_comments'] > 0)
564
+ {
565
+
566
+ $this->blogs[$importing_blog]['mode'] = 'comments';
567
+ do
568
+ {
569
+ $index = $struct = $entries = array();
570
+
571
+ //So we can link up the comments as we go we need to load them in reverse order
572
+ //Reverse the start index as the GData Blogger feed can't be sorted
573
+ $batch = ((floor(($this->blogs[$importing_blog]['total_comments'] - $start_index) / MAX_RESULTS) * MAX_RESULTS) + 1);
574
+
575
+ $response = $this->oauth_get($this->blogs[$importing_blog]['comments_url'], array('max-results' => MAX_RESULTS, 'start-index' => $batch));
576
+
577
+ // parse the feed
578
+ $feed = new SimplePie();
579
+ $feed->set_item_class('WP_SimplePie_Blog_Item');
580
+ // Use the standard "stricter" sanitize class for comments
581
+ $feed->set_raw_data($response);
582
+ $feed->init();
583
+
584
+ //Reverse the batch so we load the oldest comments first and hence can link up nested comments
585
+ $comments = array_reverse($feed->get_items());
586
+
587
+ if (!is_null($comments))
588
+ {
589
+ foreach ($comments as $item)
590
+ {
591
+
592
+ $blogentry = new BloggerEntry();
593
+ $blogentry->id = $item->get_id();
594
+ $blogentry->updated = $item->get_updated();
595
+ $blogentry->content = $item->get_content();
596
+ $blogentry->author = $item->get_author()->get_name();
597
+ $blogentry->authoruri = $item->get_author()->get_link();
598
+ $blogentry->authoremail = $item->get_author()->get_email();
599
+
600
+ $temp = $item->get_item_tags('http://purl.org/syndication/thread/1.0', 'in-reply-to');
601
+
602
+ foreach ($temp as $t)
603
+ {
604
+ if (isset($t['attribs']['']['source']))
605
+ {
606
+ $blogentry->source = $t['attribs']['']['source'];
607
+ }
608
+ }
609
+
610
+ //Get the links
611
+ $linktypes = array('edit', 'self', 'alternate', 'related');
612
+ foreach ($linktypes as $type)
613
+ {
614
+ $links = $item->get_links($type);
615
+ if (!is_null($links))
616
+ {
617
+ foreach ($links as $link)
618
+ {
619
+ $blogentry->links[] = array('rel' => $type, 'href' => $link);
620
+ }
621
+ }
622
+ }
623
+
624
+ $this->import_comment($blogentry);
625
+ $start_index++;
626
+ }
627
+ }
628
+
629
+ $this->blogs[$importing_blog]['comments_start_index'] = $start_index;
630
+ $this->save_vars();
631
+ } while ($this->blogs[$importing_blog]['total_comments'] > $start_index && $this->have_time());
632
+ }
633
+
634
+ $this->blogs[$importing_blog]['mode'] = 'authors';
635
+ $this->save_vars();
636
+
637
+ if (!$this->blogs[$importing_blog]['posts_done'] && !$this->blogs[$importing_blog]['comments_done'])
638
+ self::ajax_die('nothing');
639
+
640
+ do_action('import_done', 'blogger');
641
+ self::ajax_die('done');
642
+ }
643
+
644
+ function no_apos($string)
645
+ {
646
+ return str_replace('&apos;', "'", $string);
647
+ }
648
+
649
+ function min_whitespace($string)
650
+ {
651
+ return preg_replace('|\s+|', ' ', $string);
652
+ }
653
+
654
+ function _normalize_tag($matches)
655
+ {
656
+ return '<' . strtolower($matches[1]);
657
+ }
658
+
659
+ function import_post($entry)
660
+ {
661
+ global $importing_blog;
662
+
663
+ foreach ($entry->links as $link)
664
+ {
665
+ // save the self link as meta
666
+ if ($link['rel'] == 'self')
667
+ {
668
+ $postself = $link['href'];
669
+ $parts = parse_url($link['href']);
670
+ $entry->old_permalink = $parts['path'];
671
+ }
672
+
673
+ // get the old URI for the page when available
674
+ if ($link['rel'] == 'alternate')
675
+ {
676
+ $parts = parse_url($link['href']);
677
+ $entry->bookmark = $parts['path'];
678
+ }
679
+
680
+ // save the replies feed link as meta (ignore the comment form one)
681
+ if ($link['rel'] == 'replies' && false === strpos($link['href'], '#comment-form'))
682
+ {
683
+ $postreplies = $link['href'];
684
+ }
685
+ }
686
+
687
+ //Check if we are double cleaning here? Does the Simplepie already do all this?
688
+ $post_date = $entry->published;
689
+ $post_content = trim(addslashes($this->no_apos(@html_entity_decode($entry->content, ENT_COMPAT, get_option('blog_charset')))));
690
+ $post_title = trim(addslashes($this->no_apos($this->min_whitespace($entry->title))));
691
+
692
+ $post_status = $entry->isDraft ? 'draft' : 'publish';
693
+
694
+ // N.B. Clean up of $post_content is now part of the sanitize class
695
+
696
+ // Checks for duplicates
697
+ if (isset($this->blogs[$importing_blog]['posts'][$entry->old_permalink]))
698
+ {
699
+ $this->blogs[$importing_blog]['posts_skipped']++;
700
+ } elseif ($post_id = post_exists($post_title, $post_content, $post_date))
701
+ {
702
+ $this->blogs[$importing_blog]['posts'][$entry->old_permalink] = $post_id;
703
+ $this->blogs[$importing_blog]['posts_skipped']++;
704
+ } else
705
+ {
706
+ $post = compact('post_date', 'post_content', 'post_title', 'post_status');
707
+
708
+ $post_id = wp_insert_post($post);
709
+ if (is_wp_error($post_id))
710
+ return $post_id;
711
+
712
+ wp_create_categories(array_map('addslashes', $entry->categories), $post_id);
713
+
714
+ $author = $this->no_apos(strip_tags($entry->author));
715
+
716
+ add_post_meta($post_id, 'blogger_blog', $this->blogs[$importing_blog]['host'], true);
717
+ add_post_meta($post_id, 'blogger_author', $author, true);
718
+
719
+ //Use the page id if available or the blogger internal id if it's a draft
720
+ if ($entry->isDraft | !isset($entry->bookmark))
721
+ add_post_meta($post_id, 'blogger_permalink', $entry->old_permalink, true);
722
+ else
723
+ add_post_meta($post_id, 'blogger_permalink', $entry->bookmark, true);
724
+
725
+ add_post_meta($post_id, '_blogger_self', $postself, true);
726
+
727
+ if (isset($entry->geotags)) {
728
+ add_post_meta($post_id,'geo_latitude',$entry->geotags['geo_latitude']);
729
+ add_post_meta($post_id,'geo_longitude',$entry->geotags['geo_longitude']);
730
+ if (isset($entry->geotags['geo_address'])) {
731
+ add_post_meta($post_id,'geo_address',$entry->geotags['geo_address']);
732
+ }
733
+ }
734
+
735
+ $this->blogs[$importing_blog]['posts'][$entry->old_permalink] = $post_id;
736
+
737
+ $this->blogs[$importing_blog]['posts_done']++;
738
+ }
739
+ $this->save_vars();
740
+ return;
741
+ }
742
+
743
+ function import_comment($entry)
744
+ {
745
+ global $importing_blog;
746
+
747
+ $parts = parse_url($entry->source);
748
+ $entry->old_post_permalink = $parts['path']; //Will be something like this '/feeds/417730729915399755/posts/default/8397846992898424746'
749
+
750
+ // Drop the #fragment and we have the comment's old post permalink.
751
+ foreach ($entry->links as $link)
752
+ {
753
+ if ($link['rel'] == 'alternate')
754
+ {
755
+ $parts = parse_url($link['href']);
756
+ $entry->old_permalink = $parts['fragment'];
757
+ }
758
+ //Parent post for nested links
759
+ if ($link['rel'] == 'related')
760
+ {
761
+ $parts = parse_url($link['href']);
762
+ $entry->related = $parts['path'];
763
+ }
764
+ if ($link['rel'] == 'self')
765
+ {
766
+ $parts = parse_url($link['href']);
767
+ $entry->self = $parts['path'];
768
+ }
769
+ }
770
+
771
+ //Check for duplicated cleanup here
772
+ $comment_post_ID = (int)$this->blogs[$importing_blog]['posts'][$entry->old_post_permalink];
773
+ $comment_author = addslashes($this->no_apos(strip_tags($entry->author)));
774
+ $comment_author_url = addslashes($this->no_apos(strip_tags($entry->authoruri)));
775
+ $comment_author_email = addslashes($this->no_apos(strip_tags($entry->authoremail)));
776
+ $comment_date = $entry->updated;
777
+
778
+ // Clean up content
779
+ // Again, check if the Simplepie is already handling all of the cleaning
780
+ $comment_content = addslashes($this->no_apos(@html_entity_decode($entry->content, ENT_COMPAT, get_option('blog_charset'))));
781
+ $comment_content = preg_replace_callback('|<(/?[A-Z]+)|', array(&$this, '_normalize_tag'), $comment_content);
782
+ $comment_content = str_replace('<br>', '<br />', $comment_content);
783
+ $comment_content = str_replace('<hr>', '<hr />', $comment_content);
784
+
785
+ // Nested comment?
786
+ if (!is_null($entry->related))
787
+ {
788
+ $comment_parent = $this->blogs[$importing_blog]['comments'][$entry->related];
789
+ }
790
+
791
+ // if the post does not exist then we need stop and not add the comment
792
+ if ($comment_post_ID != 0)
793
+ {
794
+ // Checks for duplicates
795
+ if (isset($this->blogs[$importing_blog][$entry->id]) || $this->comment_exists($comment_post_ID, $comment_author, $comment_date))
796
+ {
797
+ $this->blogs[$importing_blog]['comments_skipped']++;
798
+ } else
799
+ {
800
+ $comment = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_date', 'comment_content', 'comment_parent');
801
+
802
+ $comment = wp_filter_comment($comment);
803
+ $comment_id = wp_insert_comment($comment);
804
+
805
+ $this->blogs[$importing_blog]['comments'][$entry->id] = $comment_id;
806
+ $this->blogs[$importing_blog]['comments'][$entry->self] = $comment_id; //For nested comments
807
+
808
+ $this->blogs[$importing_blog]['comments_done']++;
809
+ }
810
+ } else
811
+ {
812
+ $this->blogs[$importing_blog]['comments_skipped']++;
813
+ }
814
+ $this->save_vars();
815
+ }
816
+
817
+ function ajax_die($data)
818
+ {
819
+ ob_clean(); //Discard any debug messages or other fluff already sent
820
+ header('Content-Type: text/plain');
821
+ die($data);
822
+ }
823
+
824
+
825
+ function get_js_status($blog = false)
826
+ {
827
+ global $importing_blog;
828
+ if ($blog === false)
829
+ $blog = $this->blogs[$importing_blog];
830
+ else
831
+ $blog = $this->blogs[$blog];
832
+
833
+ $p1 = isset($blog['posts_done']) ? (int)$blog['posts_done'] : 0;
834
+ $p2 = isset($blog['total_posts']) ? (int)$blog['total_posts'] : 0;
835
+ $p3 = isset($blog['posts_skipped']) ? (int)$blog['posts_skipped'] : 0;
836
+ $c1 = isset($blog['comments_done']) ? (int)$blog['comments_done'] : 0;
837
+ $c2 = isset($blog['total_comments']) ? (int)$blog['total_comments'] : 0;
838
+ $c3 = isset($blog['comments_skipped']) ? (int)$blog['comments_skipped'] : 0;
839
+ return "{p1:$p1,p2:$p2,p3:$p3,c1:$c1,c2:$c2,c3:$c3}";
840
+ }
841
+
842
+ function get_author_form($blog = false)
843
+ {
844
+ global $importing_blog, $wpdb, $current_user;
845
+ if ($blog === false)
846
+ $blog = &$this->blogs[$importing_blog];
847
+ else
848
+ $blog = &$this->blogs[$blog];
849
+
850
+ if (!isset($blog['authors']))
851
+ {
852
+ $post_ids = array_values($blog['posts']);
853
+ $authors = (array )$wpdb->get_col("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = 'blogger_author' AND post_id IN (" . join(',', $post_ids) . ")");
854
+ $blog['authors'] = array_map(null, $authors, array_fill(0, count($authors), $current_user->ID));
855
+ $this->save_vars();
856
+ }
857
+
858
+ $directions = sprintf(__('All posts were imported with the current user as author. Use this form to move each Blogger user&#8217;s posts to a different WordPress user. You may <a href="%s">add users</a> and then return to this page and complete the user mapping. This form may be used as many times as you like until you activate the &#8220;Restart&#8221; function below.',
859
+ 'blogger-importer'), 'users.php');
860
+ $heading = __('Author mapping', 'blogger-importer');
861
+ $blogtitle = "{$blog['title']} ({$blog['host']})";
862
+ $mapthis = __('Blogger username', 'blogger-importer');
863
+ $tothis = __('WordPress login', 'blogger-importer');
864
+ $submit = esc_js(__('Save Changes', 'blogger-importer'));
865
+ $rows = '';
866
+
867
+ foreach ($blog['authors'] as $i => $author)
868
+ $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>";
869
+
870
+ return "<div class='wrap'>".screen_icon()."<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='" .
871
+ esc_attr($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>";
872
+ }
873
+
874
+ function get_user_options($current)
875
+ {
876
+ global $importer_users;
877
+ if (!isset($importer_users))
878
+ $importer_users = (array )get_users(); //Function: get_users_of_blog() Deprecated in version 3.1. Use get_users() instead.
879
+
880
+ $options = '';
881
+
882
+ foreach ($importer_users as $user)
883
+ {
884
+ $sel = ($user->ID == $current) ? " selected='selected'" : '';
885
+ $options .= "<option value='$user->ID'$sel>$user->display_name</option>";
886
+ }
887
+
888
+ return $options;
889
+ }
890
+
891
+ function save_authors()
892
+ {
893
+ global $importing_blog, $wpdb;
894
+ $blog = &$this->blogs[$importing_blog]; //Get a reference to blogs so we don't have to write it longhand
895
+
896
+ $authors = (array )$_POST['authors'];
897
+
898
+ $host = $blog['host'];
899
+
900
+ // Get an array of posts => authors
901
+ $post_ids = (array )$wpdb->get_col($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'blogger_blog' AND meta_value = %s", $host));
902
+ $post_ids = join(',', $post_ids);
903
+ $results = (array )$wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = 'blogger_author' AND post_id IN ($post_ids)");
904
+ foreach ($results as $row)
905
+ $authors_posts[$row->post_id] = $row->meta_value;
906
+
907
+ foreach ($authors as $author => $user_id)
908
+ {
909
+ $user_id = (int)$user_id;
910
+
911
+ // Skip authors that haven't been changed
912
+ if ($user_id == $blog['authors'][$author][1])
913
+ continue;
914
+
915
+ // Get a list of the selected author's posts
916
+ $post_ids = (array )array_keys($authors_posts, $blog['authors'][$author][0]);
917
+ $post_ids = join(',', $post_ids);
918
+
919
+ $wpdb->query($wpdb->prepare("UPDATE $wpdb->posts SET post_author = %d WHERE id IN ($post_ids)", $user_id));
920
+ $blog['authors'][$author][1] = $user_id;
921
+ }
922
+ $this->save_vars();
923
+
924
+ wp_redirect('edit.php');
925
+ }
926
+
927
+ function restart()
928
+ {
929
+ global $wpdb;
930
+ $options = get_option('blogger_importer');
931
+
932
+ delete_option('blogger_importer');
933
+ $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key = 'blogger_author'");
934
+ wp_redirect('?import=blogger');
935
+ }
936
+
937
+ // Step 9: Congratulate the user
938
+ function congrats()
939
+ {
940
+ $blog = (int)$_GET['blog'];
941
+ echo '<h1>' . __('Congratulations!', 'blogger-importer') . '</h1><p>' . __('Now that you have imported your Blogger blog into WordPress, what are you going to do? Here are some suggestions:',
942
+ 'blogger-importer') . '</p><ul><li>' . __('That was hard work! Take a break.', 'blogger-importer') . '</li>';
943
+ if (count($this->import['blogs']) > 1)
944
+ echo '<li>' . __('In case you haven&#8217;t done it already, you can import the posts from your other blogs:', 'blogger-importer') . $this->show_blogs() . '</li>';
945
+ if ($n = count($this->import['blogs'][$blog]['newusers']))
946
+ echo '<li>' . sprintf(__('Go to <a href="%s" target="%s">Authors &amp; Users</a>, where you can modify the new user(s) 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.',
947
+ 'blogger-importer'), 'users.php', '_parent') . '</li>';
948
+ echo '<li>' . __('For security, click the link below to reset this importer.', 'blogger-importer') . '</li>';
949
+ echo '</ul>';
950
+ }
951
+
952
+ // Figures out what to do, then does it.
953
+ function start()
954
+ {
955
+ if (isset($_POST['restart']))
956
+ $this->restart();
957
+
958
+ $options = get_option('blogger_importer');
959
+
960
+ if (is_array($options))
961
+ foreach ($options as $key => $value)
962
+ $this->$key = $value;
963
+
964
+ if (isset($_REQUEST['blog']))
965
+ {
966
+ $blog = is_array($_REQUEST['blog']) ? array_shift($keys = array_keys($_REQUEST['blog'])) : $_REQUEST['blog'];
967
+ $blog = (int)$blog;
968
+ $result = $this->import_blog($blog);
969
+ if (is_wp_error($result))
970
+ echo $result->get_error_message();
971
+ } elseif (isset($_GET['token']) && isset($_GET['token_secret']))
972
+ $this->auth();
973
+ elseif (isset($this->token) && isset($this->token_secret))
974
+ $this->show_blogs();
975
+ else
976
+ $this->greet();
977
+
978
+ $saved = $this->save_vars();
979
+
980
+ if ($saved && !isset($_GET['noheader']))
981
+ {
982
+ $restart = __('Restart', 'blogger-importer');
983
+ $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.',
984
+ 'blogger-importer');
985
+ $submit = esc_attr__('Clear account information', 'blogger-importer');
986
+ 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>";
987
+ }
988
+ }
989
+
990
+ function save_vars()
991
+ {
992
+ $vars = get_object_vars($this);
993
+ update_option('blogger_importer', $vars);
994
+
995
+ return !empty($vars);
996
+ }
997
+
998
+ function comment_exists($post_id, $comment_author, $comment_date)
999
+ {
1000
+ //Do we have 2 comments for the same author at the same time, on the same post?
1001
+ //returns comment id
1002
+ global $wpdb;
1003
+
1004
+ $comment_author = stripslashes($comment_author);
1005
+ $comment_date = stripslashes($comment_date);
1006
+
1007
+ return $wpdb->get_var($wpdb->prepare("SELECT comment_ID FROM $wpdb->comments
1008
+ WHERE comment_post_ID = %s and comment_author = %s AND comment_date = %s", $post_id, $comment_author, $comment_date));
1009
+ }
1010
+
1011
+ }
1012
+
1013
+ class BloggerEntry
1014
+ {
1015
+ var $links = array();
1016
+ var $categories = array();
1017
+ }
1018
+
1019
+ } // class_exists( 'WP_Importer' )
1020
+
1021
+ function blogger_importer_init()
1022
+ {
1023
+ load_plugin_textdomain('blogger-importer', false, dirname(plugin_basename(__file__)) . '/languages');
1024
+
1025
+ $blogger_import = new Blogger_Import();
1026
+ register_importer('blogger', __('Blogger', 'blogger-importer'), __('Import categories, posts and comments then maps users from a Blogger blog.', 'blogger-importer'), array($blogger_import, 'start'));
1027
+
1028
+ }
1029
+ add_action('admin_init', 'blogger_importer_init');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
languages/blogger-importer.pot CHANGED
@@ -1,130 +1,121 @@
1
- # Copyright (C) 2010 Blogger Importer
2
  # This file is distributed under the same license as the Blogger Importer package.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: Blogger Importer 0.4\n"
6
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/blogger-importer\n"
7
- "POT-Creation-Date: 2011-06-10 14:30:39+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
11
- "PO-Revision-Date: 2010-MO-DA HO:MI+ZONE\n"
12
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
  "Language-Team: LANGUAGE <LL@li.org>\n"
14
 
15
- #: blogger-importer.php:68
16
  msgid "Import Blogger"
17
  msgstr ""
18
 
19
- #: blogger-importer.php:69
20
  msgid ""
21
  "Howdy! This importer allows you to import posts and comments from your "
22
  "Blogger account into your WordPress site."
23
  msgstr ""
24
 
25
- #: blogger-importer.php:70
26
  msgid ""
27
  "To use this importer, you must have a Google account and an upgraded (New, "
28
  "was Beta) blog hosted on blogspot.com or a custom domain (not FTP)."
29
  msgstr ""
30
 
31
- #: blogger-importer.php:71
32
  msgid ""
33
  "The first thing you need to do is tell Blogger to let WordPress access your "
34
  "account. You will be sent back here after providing authorization."
35
  msgstr ""
36
 
37
- #: blogger-importer.php:72
38
  msgid "Authorize"
39
  msgstr ""
40
 
41
- #: blogger-importer.php:111
42
- msgid "Authorization failed"
43
- msgstr ""
44
-
45
- #: blogger-importer.php:112
46
- msgid ""
47
- "Something went wrong. If the problem persists, send this info to support:"
48
- msgstr ""
49
-
50
- #: blogger-importer.php:169
51
  msgid "Trouble signing in"
52
  msgstr ""
53
 
54
- #: blogger-importer.php:170
55
  msgid "We were not able to gain access to your account. Try starting over."
56
  msgstr ""
57
 
58
- #: blogger-importer.php:208
59
  msgid "No blogs found"
60
  msgstr ""
61
 
62
- #: blogger-importer.php:209
63
  msgid ""
64
  "We were able to log in but there were no blogs. Try a different account next "
65
  "time."
66
  msgstr ""
67
 
68
- #: blogger-importer.php:216
69
  msgid "Import"
70
  msgstr ""
71
 
72
- #: blogger-importer.php:217
73
  msgid "Continue"
74
  msgstr ""
75
 
76
- #: blogger-importer.php:218
77
  msgid "Importing..."
78
  msgstr ""
79
 
80
- #: blogger-importer.php:219
81
  msgid "Set Authors"
82
  msgstr ""
83
 
84
- #: blogger-importer.php:220
85
  msgid "Preparing author mapping form..."
86
  msgstr ""
87
 
88
- #: blogger-importer.php:221
89
  msgid "Final Step: Author Mapping"
90
  msgstr ""
91
 
92
- #: blogger-importer.php:222
93
  msgid "Nothing was imported. Had you already imported this blog?"
94
  msgstr ""
95
 
96
- #: blogger-importer.php:224
97
  msgid "Blogger Blogs"
98
  msgstr ""
99
 
100
- #: blogger-importer.php:225
101
  msgid "Blog Name"
102
  msgstr ""
103
 
104
- #: blogger-importer.php:226
105
  msgid "Blog URL"
106
  msgstr ""
107
 
108
- #: blogger-importer.php:227
109
  msgid "The Magic Button"
110
  msgstr ""
111
 
112
- #: blogger-importer.php:228
113
  msgid "Posts"
114
  msgstr ""
115
 
116
- #: blogger-importer.php:229
117
  msgid "Comments"
118
  msgstr ""
119
 
120
- #: blogger-importer.php:230
121
  msgid ""
122
  "This feature requires Javascript but it seems to be disabled. Please enable "
123
  "Javascript and then reload this page. Don&#8217;t worry, you can turn it "
124
  "back off when you&#8217;re done."
125
  msgstr ""
126
 
127
- #: blogger-importer.php:685
128
  msgid ""
129
  "All posts were imported with the current user as author. Use this form to "
130
  "move each Blogger user&#8217;s posts to a different WordPress user. You may "
@@ -133,62 +124,43 @@ msgid ""
133
  "activate the &#8220;Restart&#8221; function below."
134
  msgstr ""
135
 
136
- #: blogger-importer.php:686
137
  msgid "Author mapping"
138
  msgstr ""
139
 
140
- #: blogger-importer.php:688
141
  msgid "Blogger username"
142
  msgstr ""
143
 
144
- #: blogger-importer.php:689
145
  msgid "WordPress login"
146
  msgstr ""
147
 
148
- #: blogger-importer.php:690
149
  msgid "Save Changes"
150
  msgstr ""
151
 
152
- #: blogger-importer.php:747
153
- msgid "Could not connect to https://www.google.com"
154
- msgstr ""
155
-
156
- #: blogger-importer.php:748
157
- msgid ""
158
- "There was a problem opening a secure connection to Google. This is what went "
159
- "wrong:"
160
- msgstr ""
161
-
162
- #: blogger-importer.php:759
163
- msgid "Could not connect to %s"
164
- msgstr ""
165
-
166
- #: blogger-importer.php:760
167
- msgid ""
168
- "There was a problem opening a connection to Blogger. This is what went wrong:"
169
- msgstr ""
170
-
171
- #: blogger-importer.php:826
172
  msgid "Congratulations!"
173
  msgstr ""
174
 
175
- #: blogger-importer.php:826
176
  msgid ""
177
  "Now that you have imported your Blogger blog into WordPress, what are you "
178
  "going to do? Here are some suggestions:"
179
  msgstr ""
180
 
181
- #: blogger-importer.php:826
182
  msgid "That was hard work! Take a break."
183
  msgstr ""
184
 
185
- #: blogger-importer.php:828
186
  msgid ""
187
  "In case you haven&#8217;t done it already, you can import the posts from "
188
  "your other blogs:"
189
  msgstr ""
190
 
191
- #: blogger-importer.php:830
192
  msgid ""
193
  "Go to <a href=\"%s\" target=\"%s\">Authors &amp; Users</a>, where you can "
194
  "modify the new user(s) or delete them. If you want to make all of the "
@@ -196,15 +168,15 @@ msgid ""
196
  "authors."
197
  msgstr ""
198
 
199
- #: blogger-importer.php:831
200
  msgid "For security, click the link below to reset this importer."
201
  msgstr ""
202
 
203
- #: blogger-importer.php:862
204
  msgid "Restart"
205
  msgstr ""
206
 
207
- #: blogger-importer.php:863
208
  msgid ""
209
  "We have saved some information about your Blogger account in your WordPress "
210
  "database. Clearing this information will allow you to start over. Restarting "
@@ -212,16 +184,17 @@ msgid ""
212
  "import a blog, duplicate posts and comments will be skipped."
213
  msgstr ""
214
 
215
- #: blogger-importer.php:864
216
  msgid "Clear account information"
217
  msgstr ""
218
 
219
- #: blogger-importer.php:914
220
  msgid "Blogger"
221
  msgstr ""
222
 
223
- #: blogger-importer.php:914
224
- msgid "Import posts, comments, and users from a Blogger blog."
 
225
  msgstr ""
226
 
227
  #. Plugin Name of the plugin/theme
@@ -233,7 +206,9 @@ msgid "http://wordpress.org/extend/plugins/blogger-importer/"
233
  msgstr ""
234
 
235
  #. Description of the plugin/theme
236
- msgid "Import posts, comments, tags, and attachments from a Blogger blog."
 
 
237
  msgstr ""
238
 
239
  #. Author of the plugin/theme
1
+ # Copyright (C) 2012 Blogger Importer
2
  # This file is distributed under the same license as the Blogger Importer package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: Blogger Importer 0.5\n"
6
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/blogger-importer\n"
7
+ "POT-Creation-Date: 2012-06-13 16:29:40+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
11
+ "PO-Revision-Date: 2012-MO-DA HO:MI+ZONE\n"
12
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
  "Language-Team: LANGUAGE <LL@li.org>\n"
14
 
15
+ #: blogger-importer.php:101
16
  msgid "Import Blogger"
17
  msgstr ""
18
 
19
+ #: blogger-importer.php:102
20
  msgid ""
21
  "Howdy! This importer allows you to import posts and comments from your "
22
  "Blogger account into your WordPress site."
23
  msgstr ""
24
 
25
+ #: blogger-importer.php:103
26
  msgid ""
27
  "To use this importer, you must have a Google account and an upgraded (New, "
28
  "was Beta) blog hosted on blogspot.com or a custom domain (not FTP)."
29
  msgstr ""
30
 
31
+ #: blogger-importer.php:104
32
  msgid ""
33
  "The first thing you need to do is tell Blogger to let WordPress access your "
34
  "account. You will be sent back here after providing authorization."
35
  msgstr ""
36
 
37
+ #: blogger-importer.php:105
38
  msgid "Authorize"
39
  msgstr ""
40
 
41
+ #: blogger-importer.php:225
 
 
 
 
 
 
 
 
 
42
  msgid "Trouble signing in"
43
  msgstr ""
44
 
45
+ #: blogger-importer.php:225
46
  msgid "We were not able to gain access to your account. Try starting over."
47
  msgstr ""
48
 
49
+ #: blogger-importer.php:267
50
  msgid "No blogs found"
51
  msgstr ""
52
 
53
+ #: blogger-importer.php:267
54
  msgid ""
55
  "We were able to log in but there were no blogs. Try a different account next "
56
  "time."
57
  msgstr ""
58
 
59
+ #: blogger-importer.php:275
60
  msgid "Import"
61
  msgstr ""
62
 
63
+ #: blogger-importer.php:276
64
  msgid "Continue"
65
  msgstr ""
66
 
67
+ #: blogger-importer.php:277
68
  msgid "Importing..."
69
  msgstr ""
70
 
71
+ #: blogger-importer.php:278
72
  msgid "Set Authors"
73
  msgstr ""
74
 
75
+ #: blogger-importer.php:279
76
  msgid "Preparing author mapping form..."
77
  msgstr ""
78
 
79
+ #: blogger-importer.php:280
80
  msgid "Final Step: Author Mapping"
81
  msgstr ""
82
 
83
+ #: blogger-importer.php:281
84
  msgid "Nothing was imported. Had you already imported this blog?"
85
  msgstr ""
86
 
87
+ #: blogger-importer.php:283
88
  msgid "Blogger Blogs"
89
  msgstr ""
90
 
91
+ #: blogger-importer.php:284
92
  msgid "Blog Name"
93
  msgstr ""
94
 
95
+ #: blogger-importer.php:285
96
  msgid "Blog URL"
97
  msgstr ""
98
 
99
+ #: blogger-importer.php:286
100
  msgid "The Magic Button"
101
  msgstr ""
102
 
103
+ #: blogger-importer.php:287
104
  msgid "Posts"
105
  msgstr ""
106
 
107
+ #: blogger-importer.php:288
108
  msgid "Comments"
109
  msgstr ""
110
 
111
+ #: blogger-importer.php:289
112
  msgid ""
113
  "This feature requires Javascript but it seems to be disabled. Please enable "
114
  "Javascript and then reload this page. Don&#8217;t worry, you can turn it "
115
  "back off when you&#8217;re done."
116
  msgstr ""
117
 
118
+ #: blogger-importer.php:858
119
  msgid ""
120
  "All posts were imported with the current user as author. Use this form to "
121
  "move each Blogger user&#8217;s posts to a different WordPress user. You may "
124
  "activate the &#8220;Restart&#8221; function below."
125
  msgstr ""
126
 
127
+ #: blogger-importer.php:860
128
  msgid "Author mapping"
129
  msgstr ""
130
 
131
+ #: blogger-importer.php:862
132
  msgid "Blogger username"
133
  msgstr ""
134
 
135
+ #: blogger-importer.php:863
136
  msgid "WordPress login"
137
  msgstr ""
138
 
139
+ #: blogger-importer.php:864
140
  msgid "Save Changes"
141
  msgstr ""
142
 
143
+ #: blogger-importer.php:941
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  msgid "Congratulations!"
145
  msgstr ""
146
 
147
+ #: blogger-importer.php:941
148
  msgid ""
149
  "Now that you have imported your Blogger blog into WordPress, what are you "
150
  "going to do? Here are some suggestions:"
151
  msgstr ""
152
 
153
+ #: blogger-importer.php:942
154
  msgid "That was hard work! Take a break."
155
  msgstr ""
156
 
157
+ #: blogger-importer.php:944
158
  msgid ""
159
  "In case you haven&#8217;t done it already, you can import the posts from "
160
  "your other blogs:"
161
  msgstr ""
162
 
163
+ #: blogger-importer.php:946
164
  msgid ""
165
  "Go to <a href=\"%s\" target=\"%s\">Authors &amp; Users</a>, where you can "
166
  "modify the new user(s) or delete them. If you want to make all of the "
168
  "authors."
169
  msgstr ""
170
 
171
+ #: blogger-importer.php:948
172
  msgid "For security, click the link below to reset this importer."
173
  msgstr ""
174
 
175
+ #: blogger-importer.php:982
176
  msgid "Restart"
177
  msgstr ""
178
 
179
+ #: blogger-importer.php:983
180
  msgid ""
181
  "We have saved some information about your Blogger account in your WordPress "
182
  "database. Clearing this information will allow you to start over. Restarting "
184
  "import a blog, duplicate posts and comments will be skipped."
185
  msgstr ""
186
 
187
+ #: blogger-importer.php:985
188
  msgid "Clear account information"
189
  msgstr ""
190
 
191
+ #: blogger-importer.php:1026
192
  msgid "Blogger"
193
  msgstr ""
194
 
195
+ #: blogger-importer.php:1026
196
+ msgid ""
197
+ "Import categories, posts and comments then maps users from a Blogger blog."
198
  msgstr ""
199
 
200
  #. Plugin Name of the plugin/theme
206
  msgstr ""
207
 
208
  #. Description of the plugin/theme
209
+ msgid ""
210
+ "Import posts, comments and tags from a Blogger blog and migrate authors to "
211
+ "Wordpress users."
212
  msgstr ""
213
 
214
  #. Author of the plugin/theme
oauth.php ADDED
@@ -0,0 +1,926 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Original File from: http://oauth.googlecode.com/svn/code/php/
4
+ License: MIT License:
5
+
6
+ The MIT License
7
+
8
+ Copyright (c) 2007 Andy Smith
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in
18
+ all copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
+ THE SOFTWARE.
27
+
28
+
29
+ Modified for use in WordPress by Otto
30
+
31
+ Changes: All classes renamed to Blogger_* to prevent conflicts with other plugins/code using the same OAuth library.
32
+
33
+ */
34
+ // vim: foldmethod=marker
35
+
36
+ /* Generic exception class
37
+ */
38
+ class Blogger_OAuthException extends Exception {
39
+ // pass
40
+ }
41
+
42
+ class Blogger_OAuthConsumer {
43
+ public $key;
44
+ public $secret;
45
+
46
+ function __construct($key, $secret, $callback_url=NULL) {
47
+ $this->key = $key;
48
+ $this->secret = $secret;
49
+ $this->callback_url = $callback_url;
50
+ }
51
+
52
+ function __toString() {
53
+ return "Blogger_OAuthConsumer[key=$this->key,secret=$this->secret]";
54
+ }
55
+ }
56
+
57
+ class Blogger_OAuthToken {
58
+ // access tokens and request tokens
59
+ public $key;
60
+ public $secret;
61
+
62
+ /**
63
+ * key = the token
64
+ * secret = the token secret
65
+ */
66
+ function __construct($key, $secret) {
67
+ $this->key = $key;
68
+ $this->secret = $secret;
69
+ }
70
+
71
+ /**
72
+ * generates the basic string serialization of a token that a server
73
+ * would respond to request_token and access_token calls with
74
+ */
75
+ function to_string() {
76
+ return "oauth_token=" .
77
+ Blogger_OAuthUtil::urlencode_rfc3986($this->key) .
78
+ "&oauth_token_secret=" .
79
+ Blogger_OAuthUtil::urlencode_rfc3986($this->secret);
80
+ }
81
+
82
+ function __toString() {
83
+ return $this->to_string();
84
+ }
85
+ }
86
+
87
+ /**
88
+ * A class for implementing a Signature Method
89
+ * See section 9 ("Signing Requests") in the spec
90
+ */
91
+ abstract class Blogger_OAuthSignatureMethod {
92
+ /**
93
+ * Needs to return the name of the Signature Method (ie HMAC-SHA1)
94
+ * @return string
95
+ */
96
+ abstract public function get_name();
97
+
98
+ /**
99
+ * Build up the signature
100
+ * NOTE: The output of this function MUST NOT be urlencoded.
101
+ * the encoding is handled in Blogger_OAuthRequest when the final
102
+ * request is serialized
103
+ * @param Blogger_OAuthRequest $request
104
+ * @param Blogger_OAuthConsumer $consumer
105
+ * @param Blogger_OAuthToken $token
106
+ * @return string
107
+ */
108
+ abstract public function build_signature($request, $consumer, $token);
109
+
110
+ /**
111
+ * Verifies that a given signature is correct
112
+ * @param Blogger_OAuthRequest $request
113
+ * @param Blogger_OAuthConsumer $consumer
114
+ * @param Blogger_OAuthToken $token
115
+ * @param string $signature
116
+ * @return bool
117
+ */
118
+ public function check_signature($request, $consumer, $token, $signature) {
119
+ $built = $this->build_signature($request, $consumer, $token);
120
+
121
+ // Check for zero length, although unlikely here
122
+ if (strlen($built) == 0 || strlen($signature) == 0) {
123
+ return false;
124
+ }
125
+
126
+ if (strlen($built) != strlen($signature)) {
127
+ return false;
128
+ }
129
+
130
+ // Avoid a timing leak with a (hopefully) time insensitive compare
131
+ $result = 0;
132
+ for ($i = 0; $i < strlen($signature); $i++) {
133
+ $result |= ord($built{$i}) ^ ord($signature{$i});
134
+ }
135
+
136
+ return $result == 0;
137
+ }
138
+ }
139
+
140
+ /**
141
+ * The HMAC-SHA1 signature method uses the HMAC-SHA1 signature algorithm as defined in [RFC2104]
142
+ * where the Signature Base String is the text and the key is the concatenated values (each first
143
+ * encoded per Parameter Encoding) of the Consumer Secret and Token Secret, separated by an '&'
144
+ * character (ASCII code 38) even if empty.
145
+ * - Chapter 9.2 ("HMAC-SHA1")
146
+ */
147
+ class Blogger_OAuthSignatureMethod_HMAC_SHA1 extends Blogger_OAuthSignatureMethod {
148
+ function get_name() {
149
+ return "HMAC-SHA1";
150
+ }
151
+
152
+ public function build_signature($request, $consumer, $token) {
153
+ $base_string = $request->get_signature_base_string();
154
+ $request->base_string = $base_string;
155
+
156
+ $key_parts = array(
157
+ $consumer->secret,
158
+ ($token) ? $token->secret : ""
159
+ );
160
+
161
+ $key_parts = Blogger_OAuthUtil::urlencode_rfc3986($key_parts);
162
+ $key = implode('&', $key_parts);
163
+
164
+ return base64_encode(hash_hmac('sha1', $base_string, $key, true));
165
+ }
166
+ }
167
+
168
+ /**
169
+ * The PLAINTEXT method does not provide any security protection and SHOULD only be used
170
+ * over a secure channel such as HTTPS. It does not use the Signature Base String.
171
+ * - Chapter 9.4 ("PLAINTEXT")
172
+ */
173
+ class Blogger_OAuthSignatureMethod_PLAINTEXT extends Blogger_OAuthSignatureMethod {
174
+ public function get_name() {
175
+ return "PLAINTEXT";
176
+ }
177
+
178
+ /**
179
+ * oauth_signature is set to the concatenated encoded values of the Consumer Secret and
180
+ * Token Secret, separated by a '&' character (ASCII code 38), even if either secret is
181
+ * empty. The result MUST be encoded again.
182
+ * - Chapter 9.4.1 ("Generating Signatures")
183
+ *
184
+ * Please note that the second encoding MUST NOT happen in the SignatureMethod, as
185
+ * Blogger_OAuthRequest handles this!
186
+ */
187
+ public function build_signature($request, $consumer, $token) {
188
+ $key_parts = array(
189
+ $consumer->secret,
190
+ ($token) ? $token->secret : ""
191
+ );
192
+
193
+ $key_parts = Blogger_OAuthUtil::urlencode_rfc3986($key_parts);
194
+ $key = implode('&', $key_parts);
195
+ $request->base_string = $key;
196
+
197
+ return $key;
198
+ }
199
+ }
200
+
201
+ /**
202
+ * The RSA-SHA1 signature method uses the RSASSA-PKCS1-v1_5 signature algorithm as defined in
203
+ * [RFC3447] section 8.2 (more simply known as PKCS#1), using SHA-1 as the hash function for
204
+ * EMSA-PKCS1-v1_5. It is assumed that the Consumer has provided its RSA public key in a
205
+ * verified way to the Service Provider, in a manner which is beyond the scope of this
206
+ * specification.
207
+ * - Chapter 9.3 ("RSA-SHA1")
208
+ */
209
+ abstract class Blogger_OAuthSignatureMethod_RSA_SHA1 extends Blogger_OAuthSignatureMethod {
210
+ public function get_name() {
211
+ return "RSA-SHA1";
212
+ }
213
+
214
+ // Up to the SP to implement this lookup of keys. Possible ideas are:
215
+ // (1) do a lookup in a table of trusted certs keyed off of consumer
216
+ // (2) fetch via http using a url provided by the requester
217
+ // (3) some sort of specific discovery code based on request
218
+ //
219
+ // Either way should return a string representation of the certificate
220
+ protected abstract function fetch_public_cert(&$request);
221
+
222
+ // Up to the SP to implement this lookup of keys. Possible ideas are:
223
+ // (1) do a lookup in a table of trusted certs keyed off of consumer
224
+ //
225
+ // Either way should return a string representation of the certificate
226
+ protected abstract function fetch_private_cert(&$request);
227
+
228
+ public function build_signature($request, $consumer, $token) {
229
+ $base_string = $request->get_signature_base_string();
230
+ $request->base_string = $base_string;
231
+
232
+ // Fetch the private key cert based on the request
233
+ $cert = $this->fetch_private_cert($request);
234
+
235
+ // Pull the private key ID from the certificate
236
+ $privatekeyid = openssl_get_privatekey($cert);
237
+
238
+ // Sign using the key
239
+ $ok = openssl_sign($base_string, $signature, $privatekeyid);
240
+
241
+ // Release the key resource
242
+ openssl_free_key($privatekeyid);
243
+
244
+ return base64_encode($signature);
245
+ }
246
+
247
+ public function check_signature($request, $consumer, $token, $signature) {
248
+ $decoded_sig = base64_decode($signature);
249
+
250
+ $base_string = $request->get_signature_base_string();
251
+
252
+ // Fetch the public key cert based on the request
253
+ $cert = $this->fetch_public_cert($request);
254
+
255
+ // Pull the public key ID from the certificate
256
+ $publickeyid = openssl_get_publickey($cert);
257
+
258
+ // Check the computed signature against the one passed in the query
259
+ $ok = openssl_verify($base_string, $decoded_sig, $publickeyid);
260
+
261
+ // Release the key resource
262
+ openssl_free_key($publickeyid);
263
+
264
+ return $ok == 1;
265
+ }
266
+ }
267
+
268
+ class Blogger_OAuthRequest {
269
+ protected $parameters;
270
+ protected $http_method;
271
+ protected $http_url;
272
+ // for debug purposes
273
+ public $base_string;
274
+ public static $version = '1.0';
275
+ public static $POST_INPUT = 'php://input';
276
+
277
+ function __construct($http_method, $http_url, $parameters=NULL) {
278
+ $parameters = ($parameters) ? $parameters : array();
279
+ $parameters = array_merge( Blogger_OAuthUtil::parse_parameters(parse_url($http_url, PHP_URL_QUERY)), $parameters);
280
+ $this->parameters = $parameters;
281
+ $this->http_method = $http_method;
282
+ $this->http_url = $http_url;
283
+ }
284
+
285
+
286
+ /**
287
+ * attempt to build up a request from what was passed to the server
288
+ */
289
+ public static function from_request($http_method=NULL, $http_url=NULL, $parameters=NULL) {
290
+ $scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on")
291
+ ? 'http'
292
+ : 'https';
293
+ $http_url = ($http_url) ? $http_url : $scheme .
294
+ '://' . $_SERVER['SERVER_NAME'] .
295
+ ':' .
296
+ $_SERVER['SERVER_PORT'] .
297
+ $_SERVER['REQUEST_URI'];
298
+ $http_method = ($http_method) ? $http_method : $_SERVER['REQUEST_METHOD'];
299
+
300
+ // We weren't handed any parameters, so let's find the ones relevant to
301
+ // this request.
302
+ // If you run XML-RPC or similar you should use this to provide your own
303
+ // parsed parameter-list
304
+ if (!$parameters) {
305
+ // Find request headers
306
+ $request_headers = Blogger_OAuthUtil::get_headers();
307
+
308
+ // Parse the query-string to find GET parameters
309
+ $parameters = Blogger_OAuthUtil::parse_parameters($_SERVER['QUERY_STRING']);
310
+
311
+ // It's a POST request of the proper content-type, so parse POST
312
+ // parameters and add those overriding any duplicates from GET
313
+ if ($http_method == "POST"
314
+ && isset($request_headers['Content-Type'])
315
+ && strstr($request_headers['Content-Type'],
316
+ 'application/x-www-form-urlencoded')
317
+ ) {
318
+ $post_data = Blogger_OAuthUtil::parse_parameters(
319
+ file_get_contents(self::$POST_INPUT)
320
+ );
321
+ $parameters = array_merge($parameters, $post_data);
322
+ }
323
+
324
+ // We have a Authorization-header with Blogger_OAuth data. Parse the header
325
+ // and add those overriding any duplicates from GET or POST
326
+ if (isset($request_headers['Authorization']) && substr($request_headers['Authorization'], 0, 6) == 'Blogger_OAuth ') {
327
+ $header_parameters = Blogger_OAuthUtil::split_header(
328
+ $request_headers['Authorization']
329
+ );
330
+ $parameters = array_merge($parameters, $header_parameters);
331
+ }
332
+
333
+ }
334
+
335
+ return new Blogger_OAuthRequest($http_method, $http_url, $parameters);
336
+ }
337
+
338
+ /**
339
+ * pretty much a helper function to set up the request
340
+ */
341
+ public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=NULL) {
342
+ $parameters = ($parameters) ? $parameters : array();
343
+ $defaults = array("oauth_version" => Blogger_OAuthRequest::$version,
344
+ "oauth_nonce" => Blogger_OAuthRequest::generate_nonce(),
345
+ "oauth_timestamp" => Blogger_OAuthRequest::generate_timestamp(),
346
+ "oauth_consumer_key" => $consumer->key);
347
+ if ($token)
348
+ $defaults['oauth_token'] = $token->key;
349
+
350
+ $parameters = array_merge($defaults, $parameters);
351
+
352
+ return new Blogger_OAuthRequest($http_method, $http_url, $parameters);
353
+ }
354
+
355
+ public function set_parameter($name, $value, $allow_duplicates = true) {
356
+ if ($allow_duplicates && isset($this->parameters[$name])) {
357
+ // We have already added parameter(s) with this name, so add to the list
358
+ if (is_scalar($this->parameters[$name])) {
359
+ // This is the first duplicate, so transform scalar (string)
360
+ // into an array so we can add the duplicates
361
+ $this->parameters[$name] = array($this->parameters[$name]);
362
+ }
363
+
364
+ $this->parameters[$name][] = $value;
365
+ } else {
366
+ $this->parameters[$name] = $value;
367
+ }
368
+ }
369
+
370
+ public function get_parameter($name) {
371
+ return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
372
+ }
373
+
374
+ public function get_parameters() {
375
+ return $this->parameters;
376
+ }
377
+
378
+ public function unset_parameter($name) {
379
+ unset($this->parameters[$name]);
380
+ }
381
+
382
+ /**
383
+ * The request parameters, sorted and concatenated into a normalized string.
384
+ * @return string
385
+ */
386
+ public function get_signable_parameters() {
387
+ // Grab all parameters
388
+ $params = $this->parameters;
389
+
390
+ // Remove oauth_signature if present
391
+ // Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.")
392
+ if (isset($params['oauth_signature'])) {
393
+ unset($params['oauth_signature']);
394
+ }
395
+
396
+ return Blogger_OAuthUtil::build_http_query($params);
397
+ }
398
+
399
+ /**
400
+ * Returns the base string of this request
401
+ *
402
+ * The base string defined as the method, the url
403
+ * and the parameters (normalized), each urlencoded
404
+ * and the concated with &.
405
+ */
406
+ public function get_signature_base_string() {
407
+ $parts = array(
408
+ $this->get_normalized_http_method(),
409
+ $this->get_normalized_http_url(),
410
+ $this->get_signable_parameters()
411
+ );
412
+
413
+ $parts = Blogger_OAuthUtil::urlencode_rfc3986($parts);
414
+
415
+ return implode('&', $parts);
416
+ }
417
+
418
+ /**
419
+ * just uppercases the http method
420
+ */
421
+ public function get_normalized_http_method() {
422
+ return strtoupper($this->http_method);
423
+ }
424
+
425
+ /**
426
+ * parses the url and rebuilds it to be
427
+ * scheme://host/path
428
+ */
429
+ public function get_normalized_http_url() {
430
+ $parts = parse_url($this->http_url);
431
+
432
+ $scheme = (isset($parts['scheme'])) ? $parts['scheme'] : 'http';
433
+ $port = (isset($parts['port'])) ? $parts['port'] : (($scheme == 'https') ? '443' : '80');
434
+ $host = (isset($parts['host'])) ? strtolower($parts['host']) : '';
435
+ $path = (isset($parts['path'])) ? $parts['path'] : '';
436
+
437
+ if (($scheme == 'https' && $port != '443')
438
+ || ($scheme == 'http' && $port != '80')) {
439
+ $host = "$host:$port";
440
+ }
441
+ return "$scheme://$host$path";
442
+ }
443
+
444
+ /**
445
+ * builds a url usable for a GET request
446
+ */
447
+ public function to_url() {
448
+ $post_data = $this->to_postdata();
449
+ $out = $this->get_normalized_http_url();
450
+ if ($post_data) {
451
+ $out .= '?'.$post_data;
452
+ }
453
+ return $out;
454
+ }
455
+
456
+ /**
457
+ * builds the data one would send in a POST request
458
+ */
459
+ public function to_postdata() {
460
+ return Blogger_OAuthUtil::build_http_query($this->parameters);
461
+ }
462
+
463
+ /**
464
+ * builds the Authorization: header
465
+ */
466
+ public function to_header($realm=null) {
467
+ $first = true;
468
+ if($realm) {
469
+ $out = 'Authorization: Blogger_OAuth realm="' . Blogger_OAuthUtil::urlencode_rfc3986($realm) . '"';
470
+ $first = false;
471
+ } else
472
+ $out = 'Authorization: Blogger_OAuth';
473
+
474
+ $total = array();
475
+ foreach ($this->parameters as $k => $v) {
476
+ if (substr($k, 0, 5) != "oauth") continue;
477
+ if (is_array($v)) {
478
+ throw new Blogger_OAuthException('Arrays not supported in headers');
479
+ }
480
+ $out .= ($first) ? ' ' : ',';
481
+ $out .= Blogger_OAuthUtil::urlencode_rfc3986($k) .
482
+ '="' .
483
+ Blogger_OAuthUtil::urlencode_rfc3986($v) .
484
+ '"';
485
+ $first = false;
486
+ }
487
+ return $out;
488
+ }
489
+
490
+ public function __toString() {
491
+ return $this->to_url();
492
+ }
493
+
494
+
495
+ public function sign_request($signature_method, $consumer, $token) {
496
+ $this->set_parameter(
497
+ "oauth_signature_method",
498
+ $signature_method->get_name(),
499
+ false
500
+ );
501
+ $signature = $this->build_signature($signature_method, $consumer, $token);
502
+ $this->set_parameter("oauth_signature", $signature, false);
503
+ }
504
+
505
+ public function build_signature($signature_method, $consumer, $token) {
506
+ $signature = $signature_method->build_signature($this, $consumer, $token);
507
+ return $signature;
508
+ }
509
+
510
+ /**
511
+ * util function: current timestamp
512
+ */
513
+ private static function generate_timestamp() {
514
+ return time();
515
+ }
516
+
517
+ /**
518
+ * util function: current nonce
519
+ */
520
+ private static function generate_nonce() {
521
+ $mt = microtime();
522
+ $rand = mt_rand();
523
+
524
+ return md5($mt . $rand); // md5s look nicer than numbers
525
+ }
526
+ }
527
+
528
+ class Blogger_OAuthServer {
529
+ protected $timestamp_threshold = 300; // in seconds, five minutes
530
+ protected $version = '1.0'; // hi blaine
531
+ protected $signature_methods = array();
532
+
533
+ protected $data_store;
534
+
535
+ function __construct($data_store) {
536
+ $this->data_store = $data_store;
537
+ }
538
+
539
+ public function add_signature_method($signature_method) {
540
+ $this->signature_methods[$signature_method->get_name()] =
541
+ $signature_method;
542
+ }
543
+
544
+ // high level functions
545
+
546
+ /**
547
+ * process a request_token request
548
+ * returns the request token on success
549
+ */
550
+ public function fetch_request_token(&$request) {
551
+ $this->get_version($request);
552
+
553
+ $consumer = $this->get_consumer($request);
554
+
555
+ // no token required for the initial token request
556
+ $token = NULL;
557
+
558
+ $this->check_signature($request, $consumer, $token);
559
+
560
+ // Rev A change
561
+ $callback = $request->get_parameter('oauth_callback');
562
+ $new_token = $this->data_store->new_request_token($consumer, $callback);
563
+
564
+ return $new_token;
565
+ }
566
+
567
+ /**
568
+ * process an access_token request
569
+ * returns the access token on success
570
+ */
571
+ public function fetch_access_token(&$request) {
572
+ $this->get_version($request);
573
+
574
+ $consumer = $this->get_consumer($request);
575
+
576
+ // requires authorized request token
577
+ $token = $this->get_token($request, $consumer, "request");
578
+
579
+ $this->check_signature($request, $consumer, $token);
580
+
581
+ // Rev A change
582
+ $verifier = $request->get_parameter('oauth_verifier');
583
+ $new_token = $this->data_store->new_access_token($token, $consumer, $verifier);
584
+
585
+ return $new_token;
586
+ }
587
+
588
+ /**
589
+ * verify an api call, checks all the parameters
590
+ */
591
+ public function verify_request(&$request) {
592
+ $this->get_version($request);
593
+ $consumer = $this->get_consumer($request);
594
+ $token = $this->get_token($request, $consumer, "access");
595
+ $this->check_signature($request, $consumer, $token);
596
+ return array($consumer, $token);
597
+ }
598
+
599
+ // Internals from here
600
+ /**
601
+ * version 1
602
+ */
603
+ private function get_version(&$request) {
604
+ $version = $request->get_parameter("oauth_version");
605
+ if (!$version) {
606
+ // Service Providers MUST assume the protocol version to be 1.0 if this parameter is not present.
607
+ // Chapter 7.0 ("Accessing Protected Ressources")
608
+ $version = '1.0';
609
+ }
610
+ if ($version !== $this->version) {
611
+ throw new Blogger_OAuthException("Blogger_OAuth version '$version' not supported");
612
+ }
613
+ return $version;
614
+ }
615
+
616
+ /**
617
+ * figure out the signature with some defaults
618
+ */
619
+ private function get_signature_method($request) {
620
+ $signature_method = $request instanceof Blogger_OAuthRequest
621
+ ? $request->get_parameter("oauth_signature_method")
622
+ : NULL;
623
+
624
+ if (!$signature_method) {
625
+ // According to chapter 7 ("Accessing Protected Ressources") the signature-method
626
+ // parameter is required, and we can't just fallback to PLAINTEXT
627
+ throw new Blogger_OAuthException('No signature method parameter. This parameter is required');
628
+ }
629
+
630
+ if (!in_array($signature_method,
631
+ array_keys($this->signature_methods))) {
632
+ throw new Blogger_OAuthException(
633
+ "Signature method '$signature_method' not supported " .
634
+ "try one of the following: " .
635
+ implode(", ", array_keys($this->signature_methods))
636
+ );
637
+ }
638
+ return $this->signature_methods[$signature_method];
639
+ }
640
+
641
+ /**
642
+ * try to find the consumer for the provided request's consumer key
643
+ */
644
+ private function get_consumer($request) {
645
+ $consumer_key = $request instanceof Blogger_OAuthRequest
646
+ ? $request->get_parameter("oauth_consumer_key")
647
+ : NULL;
648
+
649
+ if (!$consumer_key) {
650
+ throw new Blogger_OAuthException("Invalid consumer key");
651
+ }
652
+
653
+ $consumer = $this->data_store->lookup_consumer($consumer_key);
654
+ if (!$consumer) {
655
+ throw new Blogger_OAuthException("Invalid consumer");
656
+ }
657
+
658
+ return $consumer;
659
+ }
660
+
661
+ /**
662
+ * try to find the token for the provided request's token key
663
+ */
664
+ private function get_token($request, $consumer, $token_type="access") {
665
+ $token_field = $request instanceof Blogger_OAuthRequest
666
+ ? $request->get_parameter('oauth_token')
667
+ : NULL;
668
+
669
+ $token = $this->data_store->lookup_token(
670
+ $consumer, $token_type, $token_field
671
+ );
672
+ if (!$token) {
673
+ throw new Blogger_OAuthException("Invalid $token_type token: $token_field");
674
+ }
675
+ return $token;
676
+ }
677
+
678
+ /**
679
+ * all-in-one function to check the signature on a request
680
+ * should guess the signature method appropriately
681
+ */
682
+ private function check_signature($request, $consumer, $token) {
683
+ // this should probably be in a different method
684
+ $timestamp = $request instanceof Blogger_OAuthRequest
685
+ ? $request->get_parameter('oauth_timestamp')
686
+ : NULL;
687
+ $nonce = $request instanceof Blogger_OAuthRequest
688
+ ? $request->get_parameter('oauth_nonce')
689
+ : NULL;
690
+
691
+ $this->check_timestamp($timestamp);
692
+ $this->check_nonce($consumer, $token, $nonce, $timestamp);
693
+
694
+ $signature_method = $this->get_signature_method($request);
695
+
696
+ $signature = $request->get_parameter('oauth_signature');
697
+ $valid_sig = $signature_method->check_signature(
698
+ $request,
699
+ $consumer,
700
+ $token,
701
+ $signature
702
+ );
703
+
704
+ if (!$valid_sig) {
705
+ throw new Blogger_OAuthException("Invalid signature");
706
+ }
707
+ }
708
+
709
+ /**
710
+ * check that the timestamp is new enough
711
+ */
712
+ private function check_timestamp($timestamp) {
713
+ if( ! $timestamp )
714
+ throw new Blogger_OAuthException(
715
+ 'Missing timestamp parameter. The parameter is required'
716
+ );
717
+
718
+ // verify that timestamp is recentish
719
+ $now = time();
720
+ if (abs($now - $timestamp) > $this->timestamp_threshold) {
721
+ throw new Blogger_OAuthException(
722
+ "Expired timestamp, yours $timestamp, ours $now"
723
+ );
724
+ }
725
+ }
726
+
727
+ /**
728
+ * check that the nonce is not repeated
729
+ */
730
+ private function check_nonce($consumer, $token, $nonce, $timestamp) {
731
+ if( ! $nonce )
732
+ throw new Blogger_OAuthException(
733
+ 'Missing nonce parameter. The parameter is required'
734
+ );
735
+
736
+ // verify that the nonce is uniqueish
737
+ $found = $this->data_store->lookup_nonce(
738
+ $consumer,
739
+ $token,
740
+ $nonce,
741
+ $timestamp
742
+ );
743
+ if ($found) {
744
+ throw new Blogger_OAuthException("Nonce already used: $nonce");
745
+ }
746
+ }
747
+
748
+ }
749
+
750
+ class Blogger_OAuthDataStore {
751
+ function lookup_consumer($consumer_key) {
752
+ // implement me
753
+ }
754
+
755
+ function lookup_token($consumer, $token_type, $token) {
756
+ // implement me
757
+ }
758
+
759
+ function lookup_nonce($consumer, $token, $nonce, $timestamp) {
760
+ // implement me
761
+ }
762
+
763
+ function new_request_token($consumer, $callback = null) {
764
+ // return a new token attached to this consumer
765
+ }
766
+
767
+ function new_access_token($token, $consumer, $verifier = null) {
768
+ // return a new access token attached to this consumer
769
+ // for the user associated with this token if the request token
770
+ // is authorized
771
+ // should also invalidate the request token
772
+ }
773
+
774
+ }
775
+
776
+ class Blogger_OAuthUtil {
777
+ public static function urlencode_rfc3986($input) {
778
+ if (is_array($input)) {
779
+ return array_map(array('Blogger_OAuthUtil', 'urlencode_rfc3986'), $input);
780
+ } else if (is_scalar($input)) {
781
+ return str_replace(
782
+ '+',
783
+ ' ',
784
+ str_replace('%7E', '~', rawurlencode($input))
785
+ );
786
+ } else {
787
+ return '';
788
+ }
789
+ }
790
+
791
+
792
+ // This decode function isn't taking into consideration the above
793
+ // modifications to the encoding process. However, this method doesn't
794
+ // seem to be used anywhere so leaving it as is.
795
+ public static function urldecode_rfc3986($string) {
796
+ return urldecode($string);
797
+ }
798
+
799
+ // Utility function for turning the Authorization: header into
800
+ // parameters, has to do some unescaping
801
+ // Can filter out any non-oauth parameters if needed (default behaviour)
802
+ // May 28th, 2010 - method updated to tjerk.meesters for a speed improvement.
803
+ // see http://code.google.com/p/oauth/issues/detail?id=163
804
+ public static function split_header($header, $only_allow_oauth_parameters = true) {
805
+ $params = array();
806
+ if (preg_match_all('/('.($only_allow_oauth_parameters ? 'oauth_' : '').'[a-z_-]*)=(:?"([^"]*)"|([^,]*))/', $header, $matches)) {
807
+ foreach ($matches[1] as $i => $h) {
808
+ $params[$h] = Blogger_OAuthUtil::urldecode_rfc3986(empty($matches[3][$i]) ? $matches[4][$i] : $matches[3][$i]);
809
+ }
810
+ if (isset($params['realm'])) {
811
+ unset($params['realm']);
812
+ }
813
+ }
814
+ return $params;
815
+ }
816
+
817
+ // helper to try to sort out headers for people who aren't running apache
818
+ public static function get_headers() {
819
+ if (function_exists('apache_request_headers')) {
820
+ // we need this to get the actual Authorization: header
821
+ // because apache tends to tell us it doesn't exist
822
+ $headers = apache_request_headers();
823
+
824
+ // sanitize the output of apache_request_headers because
825
+ // we always want the keys to be Cased-Like-This and arh()
826
+ // returns the headers in the same case as they are in the
827
+ // request
828
+ $out = array();
829
+ foreach ($headers AS $key => $value) {
830
+ $key = str_replace(
831
+ " ",
832
+ "-",
833
+ ucwords(strtolower(str_replace("-", " ", $key)))
834
+ );
835
+ $out[$key] = $value;
836
+ }
837
+ } else {
838
+ // otherwise we don't have apache and are just going to have to hope
839
+ // that $_SERVER actually contains what we need
840
+ $out = array();
841
+ if( isset($_SERVER['CONTENT_TYPE']) )
842
+ $out['Content-Type'] = $_SERVER['CONTENT_TYPE'];
843
+ if( isset($_ENV['CONTENT_TYPE']) )
844
+ $out['Content-Type'] = $_ENV['CONTENT_TYPE'];
845
+
846
+ foreach ($_SERVER as $key => $value) {
847
+ if (substr($key, 0, 5) == "HTTP_") {
848
+ // this is chaos, basically it is just there to capitalize the first
849
+ // letter of every word that is not an initial HTTP and strip HTTP
850
+ // code from przemek
851
+ $key = str_replace(
852
+ " ",
853
+ "-",
854
+ ucwords(strtolower(str_replace("_", " ", substr($key, 5))))
855
+ );
856
+ $out[$key] = $value;
857
+ }
858
+ }
859
+ }
860
+ return $out;
861
+ }
862
+
863
+ // This function takes a input like a=b&a=c&d=e and returns the parsed
864
+ // parameters like this
865
+ // array('a' => array('b','c'), 'd' => 'e')
866
+ public static function parse_parameters( $input ) {
867
+ if (!isset($input) || !$input) return array();
868
+
869
+ $pairs = explode('&', $input);
870
+
871
+ $parsed_parameters = array();
872
+ foreach ($pairs as $pair) {
873
+ $split = explode('=', $pair, 2);
874
+ $parameter = Blogger_OAuthUtil::urldecode_rfc3986($split[0]);
875
+ $value = isset($split[1]) ? Blogger_OAuthUtil::urldecode_rfc3986($split[1]) : '';
876
+
877
+ if (isset($parsed_parameters[$parameter])) {
878
+ // We have already recieved parameter(s) with this name, so add to the list
879
+ // of parameters with this name
880
+
881
+ if (is_scalar($parsed_parameters[$parameter])) {
882
+ // This is the first duplicate, so transform scalar (string) into an array
883
+ // so we can add the duplicates
884
+ $parsed_parameters[$parameter] = array($parsed_parameters[$parameter]);
885
+ }
886
+
887
+ $parsed_parameters[$parameter][] = $value;
888
+ } else {
889
+ $parsed_parameters[$parameter] = $value;
890
+ }
891
+ }
892
+ return $parsed_parameters;
893
+ }
894
+
895
+ public static function build_http_query($params) {
896
+ if (!$params) return '';
897
+
898
+ // Urlencode both keys and values
899
+ $keys = Blogger_OAuthUtil::urlencode_rfc3986(array_keys($params));
900
+ $values = Blogger_OAuthUtil::urlencode_rfc3986(array_values($params));
901
+ $params = array_combine($keys, $values);
902
+
903
+ // Parameters are sorted by name, using lexicographical byte value ordering.
904
+ // Ref: Spec: 9.1.1 (1)
905
+ uksort($params, 'strcmp');
906
+
907
+ $pairs = array();
908
+ foreach ($params as $parameter => $value) {
909
+ if (is_array($value)) {
910
+ // If two or more parameters share the same name, they are sorted by their value
911
+ // Ref: Spec: 9.1.1 (1)
912
+ // June 12th, 2010 - changed to sort because of issue 164 by hidetaka
913
+ sort($value, SORT_STRING);
914
+ foreach ($value as $duplicate_value) {
915
+ $pairs[] = $parameter . '=' . $duplicate_value;
916
+ }
917
+ } else {
918
+ $pairs[] = $parameter . '=' . $value;
919
+ }
920
+ }
921
+ // For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
922
+ // Each name-value pair is separated by an '&' character (ASCII code 38)
923
+ return implode('&', $pairs);
924
+ }
925
+ }
926
+
readme.txt CHANGED
@@ -1,43 +1,132 @@
1
- === Plugin Name ===
2
- Contributors: wordpressdotorg
3
- Donate link:
4
- Tags: importer, blogger
5
- Requires at least: 3.0
6
- Tested up to: 3.4
7
- Stable tag: 0.4
8
-
9
- Import posts, comments, and users from a Blogger blog.
10
-
11
- == Description ==
12
-
13
- This is the Blogger Importer available from the WordPress Tools->Import screen. It imports posts, comments, and users from a Blogger site into a WordPress installation.
14
-
15
- == Installation ==
16
-
17
- 1. Upload the `blogger-importer` folder to the `/wp-content/plugins/` directory
18
- 1. Activate the plugin through the 'Plugins' menu in WordPress
19
- 1. Go to the Tools -> Import screen, Click on Blogger
20
-
21
- == Frequently Asked Questions ==
22
-
23
- == Screenshots ==
24
-
25
- == Changelog ==
26
-
27
- = 0.4 =
28
- * Fix for tracking images being added by Blogger to non-authenticated feeds http://core.trac.wordpress.org/ticket/17623
29
-
30
- = 0.3 =
31
- * Bugfix for 403 Invalid AuthSub Token http://core.trac.wordpress.org/ticket/14629
32
-
33
- = 0.1 =
34
- * Initial release
35
-
36
- == Upgrade Notice ==
37
-
38
- = 0.4 =
39
- * Fix for tracking images being added by Blogger to non-authenticated feeds http://core.trac.wordpress.org/ticket/17623
40
-
41
- = 0.3 =
42
- * Bugfix for 403 Invalid AuthSub Token
43
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Plugin Name ===
2
+ Contributors: wordpressdotorg, Otto42, Workshopshed, SergeyBiryukov, rmccue
3
+ Donate link:
4
+ Tags: importer, blogger
5
+ Requires at least: 3.0
6
+ Tested up to: 3.4
7
+ Stable tag: 0.5
8
+ License: GPLv2 or later
9
+
10
+ Imports posts, comments, and categories (blogger tags) from a Blogger blog then migrates authors to Wordpress users.
11
+
12
+ == Description ==
13
+
14
+ The Blogger Importer imports your blog data from a Blogger site into a WordPress.org installation.
15
+
16
+ = Items imported =
17
+
18
+ * Categories
19
+ * Posts (published, scheduled and draft)
20
+ * Comments (not spam)
21
+
22
+ = Items not imported =
23
+
24
+ * Pages
25
+ * Images (the images will appear in your new blog but will link to the old blogspot or picassa web locations)
26
+
27
+ == Installation ==
28
+
29
+ 1. Upload the `blogger-importer` folder to the `/wp-content/plugins/` directory
30
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
31
+
32
+ = How to use =
33
+
34
+ 1. Blogger Importer is available from the WordPress Tools->Import screen.
35
+ 1. Press Authorise
36
+ 1. If you are not already logged into Google you will be asked to login
37
+ 1. You will be asked to grant Wordpress access to your Blogger information, to continue press Grant Access
38
+ 1. You will be presented with a list of all your blogs
39
+ 1. Select the appropriate blog and press the import button
40
+ 1. Wait whilst the posts and comments are imported
41
+ 1. Press the Set Authors button
42
+ 1. Select the appropriate mapping for the authors
43
+ 1. Review categories, posts and comments
44
+
45
+ You can now remove the importer plugin if you no longer need to use it.
46
+
47
+ == Frequently Asked Questions ==
48
+
49
+ = How do I re-import? =
50
+
51
+ Press the clear account information button, then re-connect to blogger and re-import, the importer is designed not to re-import the same posts. If you need to do a full re-import then delete the posts and then empty the trash before re-importing.
52
+
53
+ = How do I know which posts were imported? =
54
+
55
+ Each of the posts loaded is tagged with a meta tags indicating where the posts were loaded from. The permalink will be set to the visible URL if the post was published or the internal ID if it was still a draft or scheduled post
56
+
57
+ * blogger_author
58
+ * blogger_blog
59
+ * blogger_permalink
60
+
61
+ = Why does it keep stopping? =
62
+
63
+ The importer is designed not to overload blogger or your site so only imports in batches and will run for a fixed number of seconds before pausing, the admin screen will refresh every few seconds to show how many it has done so far. Press continue to continue importing posts and comments.
64
+
65
+ = After importing there are a lot of categories =
66
+
67
+ Blogger does not distinguish between tags and categories so you will likely want to review what was imported and then use the categories to tags converter
68
+
69
+ = What about pages? =
70
+
71
+ This importer does not handle blogger pages, you will need to manually transfer them.
72
+
73
+ = What about images? =
74
+
75
+ The importer will simply load the tags for the images as they appear in your source data, so you will have references to blogspot and picassa based images. If you do not migrate these with a separate tool then these will be lost when you delete your old blogger blog.
76
+
77
+ = Are the permalinks the same? =
78
+
79
+ No, Wordpress and Blogger handle the permalinks differently. However, it is possible to use the redirection plugin to map the old URLs across to the new URLs.
80
+
81
+ = What about future posts? =
82
+
83
+ The scheduled posts will be transferred and will be published as specified. However, Blogger and Wordpress handle drafts differently, Wordpress does not support dates on draft posts so you will need to use a plugin if you wish to plan your writing schedule.
84
+
85
+ = My posts and comments moved across but some things are stripped out =
86
+
87
+ The importer uses the SimplePie classes to process the data, these in turn use a Simplepie_Sanitize class to remove potentially malicious code from the source data.
88
+
89
+ == Screenshots ==
90
+
91
+ == Reference ==
92
+
93
+ * https://developers.google.com/blogger/docs/1.0/developers_guide_php
94
+ * https://developers.google.com/gdata/articles/oauth
95
+
96
+ == Changelog ==
97
+
98
+ = 0.5 =
99
+ * Merged in fix by SergeyBiryukov http://core.trac.wordpress.org/ticket/16012
100
+ * Merged in rmccue change to get_total_results to also use SimplePie from http://core.trac.wordpress.org/attachment/ticket/7652/7652-blogger.diff
101
+ * Reviewed in rmccue's changes in http://core.trac.wordpress.org/attachment/ticket/7652/7652-separate.diff issues with date handling functions so skipped those
102
+ * Moved SimplePie functions in new class WP_SimplePie_Blog_Item incorporating get_draft_status and get_updated and convert date
103
+ * Tested comments from source blog GMT-8, destination London (currently GMT-1), comment dates transferred correctly.
104
+ * Fixed typo in oauth_get
105
+ * Added screen_icon() to all pages
106
+ * Added GeoTags as per spec on http://codex.wordpress.org/Geodata
107
+ * Change by Otto42, rmccue to use Simplepie XML processing rather than Atomparser, http://core.trac.wordpress.org/ticket/14525 ref: http://core.trac.wordpress.org/attachment/ticket/7652/7652-blogger.diff (this also fixes http://core.trac.wordpress.org/ticket/15560)
108
+ * Change by Otto42 to use OAuth rather than AuthSub authentication, should make authentication more reliable
109
+ * Fix by Andy from Workshopshed to load comments and nested comments correctly
110
+ * Fix by Andy from Workshopshed to correctly pass the blogger start-index and max-results parameters to oAuth functions and to process more than one batch http://core.trac.wordpress.org/ticket/19096
111
+ * Fix by Andy from Workshopshed error about incorrect enqueuing of scripts also changed styles to work the same
112
+ * Change by Andy from Workshopshed testing in debug mode and wrapped ajax return into a function to suppress debug messages
113
+ * Fix by Andy from Workshopshed notices for undefined variables.
114
+ * Change by Andy from Workshopshed Added tooltip to results table to show numbers of posts and comments skipped (duplicates / missing key)
115
+ * Fix by Andy from Workshopshed incorrectly checking for duplicates based on only the date and username, this gave false positives when large numbers of comments, particularly anonymous ones.
116
+
117
+ = 0.4 =
118
+ * Fix for tracking images being added by Blogger to non-authenticated feeds http://core.trac.wordpress.org/ticket/17623
119
+
120
+ = 0.3 =
121
+ * Bugfix for 403 Invalid AuthSub Token http://core.trac.wordpress.org/ticket/14629
122
+
123
+ = 0.1 =
124
+ * Initial release
125
+
126
+ == Upgrade Notice ==
127
+
128
+ = 0.5 =
129
+
130
+ Merged in fixes found in Trac
131
+ This version is a significant re-write based on previous versions.
132
+