Blogger Importer - Version 0.9

Version Description

  • Complete rewrite to use XML files instead.
Download this release

Release Info

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

Code changes from version 0.8 to 0.9

blogger-entry.php CHANGED
@@ -1,9 +1,6 @@
1
  <?php
2
-
3
  /**
4
- * @author Andy Clark
5
- * @copyright 2013
6
- * A data object representing the data to be added into Wordpress
7
  */
8
 
9
  if (!class_exists('BloggerEntry'))
@@ -44,22 +41,23 @@ if (!class_exists('BloggerEntry'))
44
  $post_date = $this->published;
45
  $post_content = $this->content;
46
  $post_title = $this->title;
 
47
  $post_status = $this->isDraft ? 'draft' : 'publish';
48
  //AGC:24/10/2013 Turn off the pingbacks
49
- $post_pingback = Blogger_Import::POST_PINGBACK;
50
 
51
  // N.B. Clean up of $post_content is now part of the sanitize class
52
  // Check for duplication part of calling function
53
- $post = compact('post_date', 'post_content', 'post_title', 'post_status', 'post_pingback');
54
 
55
  $post_id = wp_insert_post($post);
56
  if (is_wp_error($post_id))
57
  return $post_id;
58
-
59
  wp_create_categories(array_map('addslashes', $this->categories), $post_id);
60
 
61
  add_post_meta($post_id, 'blogger_blog', $this->blogurl, true);
62
- add_post_meta($post_id, 'blogger_author', $this->author, true);
63
 
64
  if (!$this->isDraft && isset($this->bookmark))
65
  add_post_meta($post_id, 'blogger_permalink', $this->bookmark, true);
1
  <?php
 
2
  /**
3
+ * A data object representing the data to be added into WordPress
 
 
4
  */
5
 
6
  if (!class_exists('BloggerEntry'))
41
  $post_date = $this->published;
42
  $post_content = $this->content;
43
  $post_title = $this->title;
44
+ $post_author = $this->author;
45
  $post_status = $this->isDraft ? 'draft' : 'publish';
46
  //AGC:24/10/2013 Turn off the pingbacks
47
+ $post_pingback = Blogger_Importer::POST_PINGBACK;
48
 
49
  // N.B. Clean up of $post_content is now part of the sanitize class
50
  // Check for duplication part of calling function
51
+ $post = compact('post_date', 'post_content', 'post_author', 'post_title', 'post_status', 'post_pingback');
52
 
53
  $post_id = wp_insert_post($post);
54
  if (is_wp_error($post_id))
55
  return $post_id;
56
+
57
  wp_create_categories(array_map('addslashes', $this->categories), $post_id);
58
 
59
  add_post_meta($post_id, 'blogger_blog', $this->blogurl, true);
60
+ add_post_meta($post_id, 'blogger_author', $this->bloggerauthor, true);
61
 
62
  if (!$this->isDraft && isset($this->bookmark))
63
  add_post_meta($post_id, 'blogger_permalink', $this->bookmark, true);
blogger-importer-blog.php DELETED
@@ -1,812 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * @author Andy Clark
5
- * @copyright 2013
6
- * The overall blog, stats and methods for importing
7
- */
8
-
9
- class Blogger_Importer_Blog
10
- {
11
- //We have 2 fields with the same name but different case, that should be eliminated, however need to ensure can be upgraded ok
12
- var $ID; //Wordpress ID for the blog
13
- var $id; //Blogger ID for the blog
14
- var $comments_url;
15
-
16
- function init_defaults($totalposts,$totalcomments)
17
- {
18
- $this->total_posts = $totalposts;
19
- $this->total_comments = $totalcomments;
20
-
21
- $this->posts_done = $this->count_imported_posts();
22
- $this->comments_done = $this->count_imported_comments();
23
-
24
- //Initialise other vars
25
- $this->posts_skipped = 0;
26
- $this->comments_skipped = 0;
27
-
28
- $this->images_done = $this->count_imported_images();
29
- $this->images_progress = 0;
30
- $this->images_skipped = 0;
31
- $this->links_done = 0; //Can't count these as we don't store them in separately in the DB
32
- $this->links_progress = 0;
33
-
34
- $this->mode = 'init';
35
- }
36
-
37
- //Return the blog from the options or false for failure
38
- static function read_option($blogID)
39
- {
40
- $blog = false;
41
- $blogopt = get_option('blogger_importer_blog_'.$blogID);
42
- if (is_array($blogopt)) {
43
- $blog = new Blogger_Importer_Blog();
44
- foreach ($blogopt as $key => $value)
45
- $blog->$key = $value;
46
- }
47
- return $blog;
48
- }
49
-
50
- function import_blog($connector)
51
- {
52
- //AGC: Moved the parameter parsing out to start and the importing into separate functions.
53
- //25/1/2013 Suppress post revisions whilst we are importing
54
- //10/3/2014 Added start action as proposed by katazina
55
- remove_post_type_support('post', 'revisions');
56
-
57
- if (!$this->posts_done && !$this->comments_done)
58
- do_action('import_start', 'blogger');
59
-
60
- $this->importer_started = time();
61
-
62
- if (!$this->import_posts($connector))
63
- return ('continue');
64
- if (!$this->import_comments($connector))
65
- return ('continue');
66
-
67
- if (Blogger_Import::IMPORT_IMG)
68
- {
69
- if (!$this->process_images())
70
- return('continue');
71
- }
72
-
73
- if (!$this->process_links())
74
- return('continue');
75
-
76
- $this->mode = 'authors';
77
- $this->save_vars();
78
-
79
- if (!$this->posts_done && !$this->comments_done)
80
- return('nothing');
81
-
82
- //Thought: Should this be passing an ID so we know which blog just got imported.
83
- do_action('import_done', 'blogger');
84
-
85
- return('done');
86
- }
87
-
88
-
89
- function import_posts($connector)
90
- {
91
- //Simpler counting for posts as we load them forwards
92
- if (isset($this->posts_start_index))
93
- $start_index = (int)$this->posts_start_index;
94
- else
95
- $start_index = 1;
96
-
97
- if ($this->total_posts > $start_index)
98
- {
99
- // Grab all the posts
100
- $this->mode = 'posts';
101
- do
102
- {
103
- $index = $struct = $entries = array();
104
-
105
- $url = $this->posts_url;
106
-
107
- //Thought, how do we decouple this method from the source?
108
- //Perhaps the "get data function" can somehow be passed through as a parameter to this.
109
- //This decoupling would then allow an easier re-code for say when the blogger data arrives as a file not as a URL
110
- $response = $connector->oauth_get($url, array('max-results' => Blogger_Import::MAX_RESULTS, 'start-index' => $start_index));
111
-
112
- if ($response == false)
113
- break;
114
-
115
- // parse the feed
116
- $feed = new SimplePie();
117
-
118
- //set_xxxx methods depreciated (and not working?) replaced with get_registry as per docs
119
- $reg = $feed->get_registry();
120
-
121
- $reg->register('Sanitize', 'Blogger_Importer_Sanitize');
122
- $feed->sanitize = $reg->create('Sanitize'); //Should not really need to do this but there seems to be an issue with the SimplePie class?
123
- $reg->register('Item', 'WP_SimplePie_Blog_Item');
124
-
125
- $feed->set_raw_data($response);
126
- $feed->init();
127
-
128
- foreach ($feed->get_items() as $item)
129
- {
130
- $blogentry = new BloggerEntry();
131
-
132
- $blogentry->blogurl = $this->host;
133
- $blogentry->id = $item->get_id();
134
- $blogentry->published = $item->get_published();
135
- $blogentry->updated = $item->get_updated();
136
- $blogentry->isDraft = $item->get_draft_status();
137
- $blogentry->title = $item->get_title();
138
- $blogentry->content = $item->get_content();
139
- $blogentry->author = $item->get_author()->get_name();
140
- $blogentry->geotags = $item->get_geotags();
141
-
142
- $blogentry->links = $item->get_links(array('replies', 'edit', 'self', 'alternate'));
143
- $blogentry->parselinks();
144
-
145
- $blogentry->categories = $item->get_categories();
146
-
147
- // Checks for duplicates
148
- $post_id = $blogentry->post_exists();
149
-
150
- if ($post_id != 0)
151
- {
152
- $this->posts_skipped++;
153
- } else
154
- {
155
- //Unique new post so import it
156
- $post_id = $blogentry->import();
157
- $this->posts_done++;
158
- $this->save_vars();
159
- }
160
-
161
- //Ref: Not importing properly http://core.trac.wordpress.org/ticket/19096
162
- //Simplified this section to count what is loaded rather than parsing the results again
163
- $start_index++;
164
- }
165
-
166
- $this->posts_start_index = $start_index;
167
-
168
- $this->save_vars();
169
-
170
- } while ($this->total_posts > $start_index && $this->have_time());
171
- }
172
- return ($this->total_posts <= $start_index);
173
- }
174
-
175
- function import_comments($connector)
176
- {
177
- if (isset($this->comments_start_index))
178
- $start_index = (int)$this->comments_start_index;
179
- else
180
- $start_index = 1;
181
-
182
- if ($start_index > 0 && $this->total_comments > 0)
183
- {
184
-
185
- $this->mode = 'comments';
186
- do
187
- {
188
- $index = $struct = $entries = array();
189
-
190
- //So we can link up the comments as we go we need to load them in reverse order
191
- //Reverse the start index as the GData Blogger feed can't be sorted
192
- $batch = ((floor(($this->total_comments - $start_index) / Blogger_Import::MAX_RESULTS) * Blogger_Import::MAX_RESULTS) + 1);
193
-
194
- $response = $connector->oauth_get($this->comments_url,array('max-results' => Blogger_Import::MAX_RESULTS, 'start-index' => $batch));
195
- // parse the feed
196
- $feed = new SimplePie();
197
- //3/1/2012 Updated syntax for registering the item
198
- $reg = $feed->get_registry();
199
- $reg->register('Item', 'WP_SimplePie_Blog_Item');
200
- // Use the standard "stricter" sanitize class for comments
201
- $feed->set_raw_data($response);
202
- $feed->init();
203
-
204
- //Reverse the batch so we load the oldest comments first and hence can link up nested comments
205
- $comments = array_reverse($feed->get_items());
206
-
207
- if (!is_null($comments))
208
- {
209
- foreach ($comments as $item)
210
- {
211
- $commententry = new CommentEntry();
212
-
213
- $commententry->id = $item->get_id();
214
- $commententry->updated = $item->get_updated();
215
- $commententry->content = $item->get_content();
216
- $commententry->author = $item->get_author()->get_name();
217
- $commententry->authoruri = $item->get_author()->get_link();
218
- $commententry->authoremail = $item->get_author()->get_email();
219
-
220
- $commententry->source = $item->get_source();
221
- $parts = parse_url($commententry->source);
222
- $commententry->old_post_permalink = $parts['path']; //Will be something like this '/feeds/417730729915399755/posts/default/8397846992898424746'
223
-
224
- $commententry->post_ID = BloggerEntry::get_post_by_oldID($commententry->old_post_permalink);
225
-
226
- //Get the links
227
- $commententry->links = $item->get_links(array('edit', 'self', 'alternate', 'related'));
228
- $commententry->parselinks();
229
-
230
- // Nested comment?
231
- if (isset($commententry->related))
232
- {
233
- $commententry->parentcommentid = CommentEntry::get_comment_by_oldID($commententry->related);
234
- }
235
-
236
- //Perhaps could log errors here?
237
- if ($commententry->post_ID != 0)
238
- {
239
- // Checks for duplicates
240
- if ($comment_id = $commententry->exists())
241
- {
242
- $this->comments_skipped++;
243
- } else
244
- {
245
- $comment_id = $commententry->import();
246
- $this->comments_done++;
247
- }
248
- } else
249
- {
250
- $this->comments_skipped++;
251
- }
252
- $this->save_vars();
253
- $start_index++;
254
- }
255
- }
256
-
257
- $this->comments_start_index = $start_index;
258
- $this->save_vars();
259
- } while ($this->total_comments > $start_index && $this->have_time());
260
- }
261
- return ($this->total_comments <= $start_index);
262
- }
263
-
264
- function save_authors()
265
- {
266
- global $wpdb;
267
-
268
- //Change to take authors as a parameter
269
- $authors = (array )$_POST['authors'];
270
-
271
- //Todo: Handle the case where there are no more authors to remap
272
-
273
- // Get an array of posts => authors
274
- $post_ids = (array )$wpdb->get_col($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'blogger_blog' AND meta_value = %s", $this->host));
275
- $post_ids = join(',', $post_ids);
276
- $results = (array )$wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = 'blogger_author' AND post_id IN ($post_ids)");
277
- foreach ($results as $row)
278
- $authors_posts[$row->post_id] = $row->meta_value;
279
-
280
- foreach ($authors as $author => $user_id)
281
- {
282
- $user_id = (int)$user_id;
283
-
284
- // Skip authors that haven't been changed
285
- if ($user_id == $this->authors[$author][1])
286
- continue;
287
-
288
- // Get a list of the selected author's posts
289
- $post_ids = (array )array_keys($authors_posts, $this->authors[$author][0]);
290
- $post_ids = join(',', $post_ids);
291
-
292
- $wpdb->query($wpdb->prepare("UPDATE $wpdb->posts SET post_author = %d WHERE id IN ($post_ids)", $user_id));
293
- $this->authors[$author][1] = $user_id;
294
-
295
- //Should we be tidying up the post meta data here, rather than in restart?
296
- //$wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key = 'blogger_author'");
297
- }
298
- return '';
299
- }
300
-
301
-
302
- /**
303
- * Return count of imported posts from WordPress database
304
- *
305
- * @return int
306
- */
307
- function count_imported_posts()
308
- {
309
- global $wpdb;
310
- $count = 0;
311
- $meta_key = 'blogger_blog';
312
- $sql = $wpdb->prepare("SELECT count(post_id) as cnt FROM $wpdb->postmeta m
313
- inner join $wpdb->posts p on p.id = m.post_id and post_type = 'post'
314
- where meta_key = '%s' and meta_value = '%s'", $meta_key, $this->host);
315
-
316
- $result = $wpdb->get_results($sql);
317
-
318
- if (!empty($result))
319
- $count = intval($result[0]->cnt);
320
-
321
- // unset to save memory
322
- unset($results);
323
-
324
- return $count;
325
- }
326
-
327
- /**
328
- * Return count of imported images from WordPress database
329
- *
330
- * @param string $bloghost url
331
- * @return int
332
- */
333
- function count_imported_images()
334
- {
335
- global $wpdb;
336
- $count = 0;
337
- $meta_key = 'blogger_blog';
338
- $sql = $wpdb->prepare("SELECT count(post_id) as cnt FROM $wpdb->postmeta m
339
- inner join $wpdb->posts p on p.id = m.post_id and post_type = 'attachment'
340
- where meta_key = '%s' and meta_value = '%s'", $meta_key, $this->host);
341
-
342
- $result = $wpdb->get_results($sql);
343
-
344
- if (!empty($result))
345
- $count = intval($result[0]->cnt);
346
-
347
- // unset to save memory
348
- unset($results);
349
-
350
- return $count;
351
- }
352
-
353
- /**
354
- * Return count of imported comments from WordPress database
355
- *
356
- * @param string $bloghost url
357
- * @return int
358
- */
359
- function count_imported_comments()
360
- {
361
- global $wpdb;
362
- $count = 0;
363
- $meta_key = 'blogger_blog';
364
- $sql = $wpdb->prepare("SELECT count(post_id) as cnt FROM $wpdb->postmeta m
365
- inner join $wpdb->posts p on p.id = m.post_id and post_type = 'post'
366
- inner join $wpdb->comments c on p.id = c.comment_post_ID
367
- where meta_key = '%s' and meta_value = '%s'
368
- and c.comment_type <> 'pingback'", $meta_key, $this->host);
369
-
370
- $result = $wpdb->get_results($sql);
371
-
372
- if (!empty($result))
373
- $count = intval($result[0]->cnt);
374
-
375
- // unset to save memory
376
- unset($results);
377
-
378
- return $count;
379
- }
380
-
381
- function process_links()
382
- {
383
- //Update all of the links in the blog
384
- global $wpdb;
385
-
386
- $postsprocessed = $this->links_progress;
387
- if ($postsprocessed == 0)
388
- {
389
- $linksprocessed = 0;
390
- } else
391
- {
392
- $linksprocessed = $this->links_done;
393
- }
394
- $batchsize = 20;
395
-
396
- $oldurlsearch = $this->host;
397
-
398
- if (substr($oldurlsearch, 0, 3) == 'www.')
399
- {
400
- $oldurlsearch = substr($oldurlsearch, 3, strlen($oldurlsearch - 3));
401
- }
402
-
403
- $oldurlsearch = str_replace('.', '\.', $oldurlsearch);
404
-
405
- $blogspot = stripos($oldurlsearch, '\.blogspot\.');
406
- if ($blogspot)
407
- { //Blogspot addresses can be international e.g. myblog.blogspot.com, myblog.blogspot.com.au or myblog.blogspot.co.uk or myblog.blogspot.de both resolve to the same blog.
408
- //See http://www.searchenginejournal.com/google-blogger-url-censorship/39724/
409
- $oldurlsearch = substr($oldurlsearch, 0, $blogspot + 12) . '[\w\.]{2,6}';
410
- }
411
-
412
- $loadedposts = get_posts(array('meta_key' => 'blogger_blog', 'meta_value' => $this->host, 'posts_per_page' => $batchsize, 'offset' => $postsprocessed, 'post_status' => array('draft', 'publish','future')));
413
-
414
- //Stop if nothing left
415
- if (count($loadedposts) == 0){
416
- return true;
417
- }
418
-
419
- foreach ($loadedposts as $importedpost) {
420
- $importedcontent = $importedpost->post_content;
421
-
422
- $regexp = '<a\s[^>]*href=([\"\'`])(https?:\/\/(?:www\.)*' . $oldurlsearch . '\/)([^\" >]*?)\1[^>]*>(.*)<\/a>';
423
- if (preg_match_all("/$regexp/siU", $importedcontent, $matches, PREG_SET_ORDER))
424
- {
425
- foreach ($matches as $match)
426
- {
427
- $HostURL = substr($match[2], 0, strlen($match[2]) - 1); //e.g. http://minitemp.blogspot.co.uk
428
- $PageURL = '/' . $match[3]; //e.g. '/2011/04/what-happens-if-blog-title-is-really.html'
429
- $sql = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta m
430
- inner join $wpdb->posts p on p.id = m.post_id and post_type = 'post'
431
- where meta_key = '%s' and meta_value = '%s'", 'blogger_permalink', $PageURL);
432
-
433
- $linkpostid = $wpdb->get_var($sql);
434
-
435
- if ($linkpostid != 0) {
436
- $NewURL = get_permalink($linkpostid);
437
- } else { // Page not found, update content with just the new domain
438
- $NewURL = site_url($PageURL);
439
- }
440
-
441
- $importedcontent = str_replace($HostURL . $PageURL, $NewURL, $importedcontent);
442
- $linksprocessed++;
443
- }
444
-
445
- if ($importedcontent == '')
446
- {
447
- return new WP_Error('Empty Content', __("Attempting to write back empty content"));
448
- }
449
-
450
- $importedpost->post_content = $importedcontent;
451
- wp_update_post($importedpost);
452
-
453
- }
454
- $postsprocessed++;
455
-
456
- //For some reason the intermediate values are not getting written, is it that the options are cached hence not read back?
457
- $this->links_done = $linksprocessed;
458
- $this->links_progress = $postsprocessed;
459
- $saved = $this->save_vars();
460
- }
461
- unset($loadedposts);
462
- return ($postsprocessed >= $this->total_posts);;
463
- }
464
-
465
- function isurlimage($srcurl)
466
- {
467
- //Process picasaweb links and files that are images
468
- if (substr($srcurl, 0, 27) == 'http://picasaweb.google.com')
469
- return true;
470
- return preg_match('/(?i)\.(jpe?g|png|gif|bmp)$/i', $srcurl);
471
- }
472
-
473
- //Get the current status for this blog
474
- function get_js_status()
475
- {
476
- //Trap for division by zero errors
477
- if ($this->total_posts == 0) {
478
- $p1 = 100;
479
- $i2 = 100;
480
- $l2 = 100;
481
- } else {
482
- $p1 = ($this->posts_done / $this->total_posts) * 100;
483
- $i2 = ($this->images_progress / $this->total_posts) * 100;
484
- $l2 = ($this->links_progress / $this->total_posts) * 100;
485
- }
486
-
487
- $p2 = sprintf(__('%d of %d', 'blogger-importer'), $this->posts_done, $this->total_posts);
488
- $p3 = sprintf(_n('%d post skipped', '%d posts skipped', $this->posts_skipped, 'blogger-importer'), $this->posts_skipped);
489
- $c1 = $this->total_comments == 0 ? 100 : ($this->comments_done / $this->total_comments) * 100;
490
- $c2 = sprintf(__('%d of %d', 'blogger-importer'), $this->comments_done, $this->total_comments);
491
- $c3 = sprintf(_n('%d comment skipped', '%d comments skipped', $this->comments_skipped, 'blogger-importer'), $this->comments_skipped);
492
- $i1 = isset($this->images_done) ? (int)$this->images_done : 0;
493
- $i3 = sprintf(_n('%d image skipped', '%d images skipped', $this->images_skipped, 'blogger-importer'), $this->images_skipped);
494
-
495
- $l1 = isset($this->links_done) ? (int)$this->links_done : 0;
496
-
497
- return "{p1:$p1,p2:\"$p2\",p3:\"$p3\",c1:$c1,c2:\"$c2\",c3:\"$c3\",i1:$i1,i2:$i2,i3:\"$i3\",l1:$l1,l2:$l2}";
498
- }
499
-
500
- function get_authors()
501
- {
502
- //Get a list of blogger authors who created the posts
503
- //Use a subquery rather than 2 statements to avoid issue with prepare not being able to sanitise an array of integers, also protects us if the post_id type changes
504
- global $wpdb;
505
- global $current_user;
506
-
507
- $authors = (array )$wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = 'blogger_author' AND post_id IN (SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'blogger_blog' AND meta_value = %s)",$this->host));
508
-
509
- $this->authors = array_map(null, $authors, array_fill(0, count($authors), $current_user->ID));
510
- $this->save_vars();
511
- }
512
-
513
- /*
514
- * Search for either a linked image or a non linked image within the supplied html
515
- * <a href="xxx" yyyy><img src="zzz" ></a> or <img src="zzz" >
516
- * Ref: http://www.the-art-of-web.com/php/parse-links/
517
- * "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>"
518
- * http://wordpress.org/extend/plugins/blogger-image-import/
519
- * "<a[^>]+href\=([\"'`])(.*)\\1[^<]*?<img[^>]*src\=([\"'`])(.*)\\3[^>]*>"
520
- */
521
- function get_images($content)
522
- {
523
- $highrez = array();
524
- $lowrez = array();
525
-
526
- //First images with links
527
- //Might be nice to expand this top try and get Alt and/or Title attributes for use as description
528
- $regexp = "<a\s[^>]*href\=([\"'`])([^> ]*?)\\1[^<]*?<img[^>]*src\=([\"'`])([^\> ]*?)\\3[^>]*>";
529
-
530
- if (preg_match_all("/$regexp/siU", $content, $matches1, PREG_SET_ORDER))
531
- {
532
- //http://www.techrepublic.com/article/17-useful-functions-for-manipulating-arrays-in-php/5792851
533
- foreach ($matches1 as $match)
534
- {
535
- if ($this->isurlimage($match[2]))
536
- {
537
- $highrez[$match[4]] = $match[2];
538
- } else
539
- {
540
- $lowrez[$match[4]] = '';
541
- }
542
- }
543
- }
544
-
545
- //Now any image (n.b. this overlaps the previous set)
546
- $regexp = "<img[^>]*src\=([\"'`])([^\> ]*?)\\1[^>]*>";
547
-
548
- if (preg_match_all("/$regexp/siU", $content, $matches2, PREG_SET_ORDER))
549
- {
550
- foreach ($matches2 as $match)
551
- {
552
- $lowrez[$match[2]] = '';
553
- }
554
- }
555
-
556
- //Remove any rows from this second set that are already in the first set and merge two sets of results
557
- $images = array_merge($lowrez, $highrez);
558
- return $images;
559
- }
560
-
561
- /**
562
- * Update all of the images in the posts that have already been imported
563
- */
564
- function process_images()
565
- {
566
- $postsprocessed = $this->images_progress;
567
- if ($postsprocessed == 0)
568
- {
569
- $imagesprocessed = 0;
570
- $imagesskipped = 0;
571
- } else
572
- {
573
- $imagesprocessed = $this->images_done;
574
- $imagesskipped = $this->images_skipped;
575
- }
576
-
577
- $batchsize = 20;
578
-
579
- $loadedposts = get_posts(array('meta_key' => 'blogger_blog', 'meta_value' => $this->host, 'posts_per_page' => $batchsize, 'offset' => $postsprocessed, 'post_status' => array('draft', 'publish','future')));
580
-
581
- //Stop if nothing left
582
- if (count($loadedposts) == 0){
583
- return true;
584
- }
585
-
586
- foreach ($loadedposts as $importedpost)
587
- {
588
-
589
- $importedcontent = $importedpost->post_content;
590
- $author = get_post_meta($importedpost->ID, 'blogger_author', true);
591
-
592
- $img_count = 0; //Count of images for this post
593
- foreach ($this->get_images($importedcontent) as $lowrez => $highrez)
594
- {
595
- if (!$this->image_filter($lowrez))
596
- {
597
- //Pass null for description so that the default (filename) is used, might be good to use Alt tag instead?
598
- $newcontent = $this->import_image($importedpost->ID, $lowrez, $highrez, null, $img_count, $importedcontent, $this->host, $author);
599
- if (!is_wp_error($newcontent)) {
600
- $importedcontent = $newcontent;
601
- $img_count++;
602
- } else {
603
- Blogger_Import::_log($newcontent);
604
- $imagesskipped++;
605
- }
606
- }
607
- }
608
- $imagesprocessed += $img_count;
609
-
610
- $importedpost->post_content = $importedcontent;
611
- wp_update_post($importedpost);
612
- $postsprocessed++;
613
-
614
- //For some reason the intermediate values are not getting written
615
- $this->images_done = $imagesprocessed;
616
- $this->images_progress = $postsprocessed;
617
- $this->images_skipped = $imagesskipped;
618
- $saved = $this->save_vars();
619
- }
620
- unset($loadedposts);
621
- return ($postsprocessed >= $this->total_posts);
622
- }
623
-
624
- function image_urlremap($url,$large)
625
- { /* Fix problem urls
626
- e.g. change https://lh4.googleusercontent.com/-nt66qhxzDyY/TZOD-RhTYMI/AAAAAAAACd4/Elzm1smRFb4/s800-h/Ski%2520Trip.jpg to
627
- to https://lh4.googleusercontent.com/-nt66qhxzDyY/TZOD-RhTYMI/AAAAAAAACd4/Elzm1smRFb4/s800/Ski%2520Trip.jpg
628
- Could use a apply_filter here to allow users to add their own tweeks
629
- */
630
- $pattern = '/(\/)(s\d*)-h(\/)/i';
631
- $replacement = '$1$2$3';
632
- $img = preg_replace($pattern, $replacement, $url);
633
-
634
- /* Strip out ? and # on the end of files */
635
- $pattern = '/(.*)[#\?].*/i';
636
- $replacement = '$1';
637
- $img = preg_replace($pattern, $replacement, $img);
638
-
639
- if ($large) {
640
- // For images on blogger we can swap /sXXX/ with for example /s1600/ to get a larger file.
641
- // Use a standardised large size so we can control quality vs filesize.
642
- $pattern = '/(\/)(s\d*)(\/)/i';
643
- $replacement = '$1s'.Blogger_Import::LARGE_IMAGE_SIZE.'$3';
644
- $img = preg_replace($pattern, $replacement, $img);
645
- }
646
- return $img;
647
- }
648
-
649
- function image_filter($url)
650
- {
651
- // Do we exclude this particular image?
652
- // Don't include images that are already loaded onto this site
653
- // Could use a apply_filter here to allow users to add their own tweeks
654
- return (substr($url, 0, strlen(site_url())) == site_url());
655
- }
656
-
657
- function import_image($post_id, $lowrez, $highrez, $description, $imgcount, $postcontent, $blogname, $author)
658
- {
659
- /* Import a new image unless we specifically filter it out or if it has already been downloaded on another page.
660
- Based on http://wordpress.stackexchange.com/questions//media-sideload-image-file-name and the tumblr-importer
661
- Simple filename cleaning as characters such as +, % cause issues ref: http://wordpress.org/extend/plugins/uploadplus/
662
-
663
- It's processing links of a form similar to these as provided by the "get_images" function
664
- <a href="myhighrezimage.jpg"><img src="mylowrezimage.jpg"></a>
665
- or
666
- <img src="mylowrezimage.jpg">
667
-
668
- If the high resolution (linked) file is not an image then the low resolution version is downloaded.
669
- */
670
- $lowrez_old = $lowrez;
671
- $highrez_old = $highrez;
672
- $highrezispage = false;
673
-
674
- $lowrez = $this->image_urlremap($lowrez,false);
675
- if ($lowrez == '')
676
- return new WP_Error('Not an image',$message = __('Lowrez not an image','blogger-importer'), $data = array($lowrez_old, $highrez_old));
677
-
678
- if ($highrez != '')
679
- {
680
- $highrez = $this->image_urlremap($highrez,true);
681
- } else
682
- {
683
- $highrez = $this->image_urlremap($lowrez,true);
684
- }
685
-
686
- if (!$att_id = $this->image_exists($lowrez))
687
- {
688
- //Option to add a timeout to download_url, but don't use the wp_remote_get timeout as that's much shorter than the default here of 300s
689
- $tmp = download_url($highrez);
690
-
691
- if (is_wp_error($tmp))
692
- {
693
- @unlink($tmp); // clean up, copied this from other examples but how is this supposed to work if $tmp is an error??
694
- //Don't exit as can still try the small image
695
- }
696
-
697
- // If the highrez was not an image then try the lowrex
698
- if (!$this->is_image($tmp, $highrez))
699
- {
700
- $highrezispage = true; //That image was not valid
701
- $tmp = download_url($lowrez); // Option to add a timeout here
702
-
703
- if (is_wp_error($tmp))
704
- {
705
- @unlink($tmp); // clean up
706
- return $tmp; // output wp_error
707
- }
708
-
709
- if (!$this->is_image($tmp, $lowrez))
710
- {
711
- @unlink($tmp); // clean up None of items are actually images, for example might be a single pixel, deliberately filtered out or a 404 error?
712
- return new WP_Error('No Images',__('None of the images are valid','blogger-importer'), $data = array($lowrez_old, $highrez_old));
713
- }
714
- }
715
-
716
- $new_name = preg_replace('/[^A-Za-z0-9._ ]/i', '-', basename($lowrez));
717
-
718
- $file_array = array('name' => $new_name, 'tmp_name' => $tmp);
719
-
720
- $att_id = media_handle_sideload($file_array, $post_id, $description, array('post_excerpt' => $description));
721
- if (is_wp_error($att_id))
722
- {
723
- @unlink($file_array['tmp_name']);
724
- return $att_id;
725
- }
726
-
727
- // Link attachment upto old url, store the author so we can replace it later
728
- add_post_meta($att_id, 'blogger_permalink', $lowrez);
729
- add_post_meta($att_id, 'blogger_blog', $blogname, true);
730
- add_post_meta($att_id, 'blogger_author', $author, true);
731
-
732
- if ($highrezispage) //Not an image so store so we can link later
733
- add_post_meta($att_id, 'blogger_largeimgispage', true);
734
-
735
- } else
736
- {
737
- //Image already exists, check if the high rez one was valid last time
738
- $tmp = get_post_meta($att_id, 'blogger_largeimgispage', true);
739
- if ($tmp == true)
740
- $highrezispage = true;
741
- }
742
-
743
- //Always treat picassa webs as image so they get replaced with the new High rez link
744
- if (substr($highrez, 0, 27) == 'http://picasaweb.google.com')
745
- $highrezispage = false;
746
-
747
- //Replace the image strings
748
- if (!$highrezispage && $highrez_old != '')
749
- {
750
- $highrez_new = reset(wp_get_attachment_image_src($att_id, 'full'));
751
- $postcontent = str_replace($highrez_old, $highrez_new, $postcontent);
752
- }
753
- $lowrez_new = reset(wp_get_attachment_image_src($att_id, 'medium'));
754
- $postcontent = str_replace($lowrez_old, $lowrez_new, $postcontent);
755
-
756
- //Set the first image to be the post thumbnail (zero index)
757
- if ($imgcount == 0)
758
- {
759
- set_post_thumbnail($post_id, $att_id);
760
- }
761
-
762
- //media handle sideload moves the file so there should be no temp file left but cleanup just incase.
763
- @unlink($tmp);
764
-
765
- // incase something goes wrong
766
- if ($postcontent == '')
767
- {
768
- return new WP_Error('Empty Content', __("Attempting to write back empty content",'blogger-importer'), $data = array($lowrez_old, $highrez_old));
769
- }
770
- return $postcontent;
771
- }
772
-
773
- function is_image($file, $filename)
774
- {
775
- //Is the downloaded file really an image
776
- //e.g. it looked like an image from the URL but when downloaded it was something else perhaps a html page
777
- //Also filter out tracking images of 1 pixel square
778
- //Found that wp_check_filetype_and_ext and wp_match_mime_types was giving false positives
779
- $imgstats = @getimagesize($file);
780
- if (!$imgstats)
781
- {
782
- return false;
783
- }
784
-
785
- return (($imgstats[0] > 1) && ($imgstats[1] > 1));
786
- }
787
-
788
- function image_exists($lowrez)
789
- {
790
- global $wpdb;
791
- return $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts p INNER JOIN $wpdb->postmeta m ON p.ID = m.post_id AND meta_key = 'blogger_permalink' WHERE post_type = 'attachment' AND meta_value = %s LIMIT 0 , 1",
792
- $lowrez));
793
- }
794
-
795
- function have_time()
796
- {
797
- return (time() - $this->importer_started < Blogger_Import::MAX_EXECUTION_TIME);
798
- }
799
-
800
- function save_vars()
801
- {
802
- $vars = get_object_vars($this);
803
- //Store each blog it it's own setting so that we retrieve and save less data each time it updates the stats
804
- //11/3/2014 Simplified function to avoid logging unneccesary errors
805
- update_option('blogger_importer_blog_'.$this->ID, $vars);
806
- return !empty($vars);
807
- }
808
-
809
-
810
- }
811
-
812
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
blogger-importer-connector.php DELETED
@@ -1,195 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * @author Andy Clark
5
- * @copyright 2013
6
- * Connector for Google Blogger
7
- *
8
- */
9
-
10
- class Blogger_Importer_Connector
11
- {
12
- var $token;
13
- var $secret;
14
- var $endpoint;
15
- var $oauth_token;
16
- var $callback_url;
17
-
18
- /*
19
- Make the initial connection to blogger, authorise tokens etc.
20
- */
21
- function connect($url)
22
- {
23
- // Establish an Blogger_OAuth consumer
24
- $base_url = admin_url();
25
- $request_token_endpoint = 'https://www.google.com/accounts/OAuthGetRequestToken';
26
- $authorize_endpoint = 'https://www.google.com/accounts/OAuthAuthorizeToken';
27
-
28
- $test_consumer = new Blogger_OAuthConsumer('anonymous', 'anonymous', null); // anonymous is a google thing to allow non-registered apps to work
29
-
30
- if (!Blogger_OAuthUtil::sslinstalled())
31
- {
32
- return new WP_Error('OpenSSL', __('OpenSSL is not installed check your PHP.INI or ask your server provider to enable the OpenSSL module.','blogger-importer'));
33
- }
34
-
35
- //prepare to get request token
36
- //https://developers.google.com/accounts/docs/OAuth_ref#RequestToken
37
- $sig_method = new Blogger_OAuthSignatureMethod_HMAC_SHA1();
38
- $parsed = parse_url($request_token_endpoint);
39
- $params = array('callback' => $base_url, 'scope' => 'http://www.blogger.com/feeds/', 'xoauth_displayname' => 'WordPress');
40
-
41
- $req_req = Blogger_OAuthRequest::from_consumer_and_token($test_consumer, null, "GET", $request_token_endpoint, $params);
42
- $req_req->sign_request($sig_method, $test_consumer, null);
43
-
44
- // go get the request tokens from Google
45
- $req_response = wp_remote_get($req_req->to_url(), array('sslverify' => false, 'timeout' => Blogger_Import::REMOTE_TIMEOUT));
46
- if (is_wp_error($req_response))
47
- {
48
- return $req_response;
49
- }
50
- $req_token = wp_remote_retrieve_body($req_response);
51
- if (is_wp_error($req_token))
52
- {
53
- return $req_token;
54
- }
55
-
56
- // parse the tokens
57
- parse_str($req_token, $tokens);
58
-
59
- $oauth_token = $tokens['oauth_token'];
60
- $oauth_token_secret = $tokens['oauth_token_secret'];
61
-
62
- //AGC:10/10/2012 Added error handling here based on http://wordpress.org/support/topic/plugin-blogger-importer-invalid-token/page/2?replies=31#post-3243710
63
- if ($oauth_token == '')
64
- {
65
- return new WP_Error('Invalid Token', __('Invalid Token: Check server date, firewall settings and transports (curl, streams and fsockopen)','blogger-importer'));
66
- } else
67
- {
68
- $this->callback_url = add_query_arg(array( 'token' => $oauth_token, 'secret' => $oauth_token_secret ),$url);
69
- $this->endpoint = $authorize_endpoint;
70
- $this->oauth_token = $oauth_token;
71
- return true;
72
- }
73
- }
74
-
75
- /*
76
- *
77
- */
78
- function auth_form(){
79
- //$next_url = admin_url('index.php?import=blogger&amp;noheader=true');
80
- $auth = esc_attr__('Authorize', 'blogger-importer');
81
-
82
- return(sprintf ("<form action='%s' method='get'>
83
- <p class='submit' style='text-align:left;'>
84
- <input type='submit' class='button' value='%s' />
85
- <input type='hidden' name='oauth_token' value='%s' />
86
- <input type='hidden' name='oauth_callback' value='%s' />
87
- </p>
88
- </form>
89
- </div>\n",$this->endpoint,$auth,$this->oauth_token,$this->callback_url));
90
- }
91
-
92
- /**
93
- * We have a authorized request token now, so upgrade it to an access token
94
- *
95
- * @link https://developers.google.com/gdata/articles/oauth#UsingAccessToken
96
- */
97
- function auth($token,$secret)
98
- {
99
- $oauth_access_token_endpoint = 'https://www.google.com/accounts/OAuthGetAccessToken';
100
-
101
- // auth the token
102
- $test_consumer = new Blogger_OAuthConsumer('anonymous', 'anonymous', null);
103
- $auth_token = new Blogger_OAuthConsumer($token, $secret);
104
- $access_token_req = new Blogger_OAuthRequest("GET", $oauth_access_token_endpoint);
105
- $access_token_req = $access_token_req->from_consumer_and_token($test_consumer, $auth_token, "GET", $oauth_access_token_endpoint);
106
-
107
- $access_token_req->sign_request(new Blogger_OAuthSignatureMethod_HMAC_SHA1(), $test_consumer, $auth_token);
108
-
109
- // Should be doing validation here, what if wp_remote calls failed?
110
- $after_access_request = wp_remote_retrieve_body(wp_remote_get($access_token_req->to_url(), array('sslverify' => false, 'timeout' => Blogger_Import::REMOTE_TIMEOUT)));
111
-
112
- parse_str($after_access_request, $access_tokens);
113
-
114
- $this->token = $access_tokens['oauth_token'];
115
- $this->secret = $access_tokens['oauth_token_secret'];
116
-
117
- $this->save_vars();
118
- }
119
-
120
-
121
- /**
122
- * Get a URL using the oauth token for authentication (returns false on failure)
123
- */
124
- function oauth_get($url,$params = null)
125
- {
126
- $test_consumer = new Blogger_OAuthConsumer('anonymous', 'anonymous', null);
127
- $goog = new Blogger_OAuthConsumer($this->token, $this->secret, null);
128
- $request = new Blogger_OAuthRequest("GET", $url, $params);
129
-
130
- //Ref: Not importing properly http://core.trac.wordpress.org/ticket/19096
131
- $blog_req = $request->from_consumer_and_token($test_consumer, $goog, 'GET', $url, $params);
132
-
133
- $blog_req->sign_request(new Blogger_OAuthSignatureMethod_HMAC_SHA1(), $test_consumer, $goog);
134
-
135
- $data = wp_remote_get($blog_req->to_url(), array('sslverify' => false, 'timeout' => Blogger_Import::REMOTE_TIMEOUT));
136
-
137
- if (wp_remote_retrieve_response_code($data) == 200)
138
- {
139
- $response = wp_remote_retrieve_body($data);
140
- } else
141
- {
142
- $response = false;
143
- }
144
-
145
- return $response;
146
- }
147
-
148
-
149
- //Need to check, why start index 2? Surely 1 would be better
150
- function get_total_results($url)
151
- {
152
- $response = $this->oauth_get($url,array('max-results' => 1, 'start-index' => 2));
153
-
154
- $feed = new SimplePie();
155
- $feed->set_raw_data($response);
156
- $feed->init();
157
- $results = $feed->get_channel_tags('http://a9.com/-/spec/opensearchrss/1.0/', 'totalResults');
158
-
159
- $total_results = $results[0]['data'];
160
- unset($feed);
161
- return (int)$total_results;
162
- }
163
-
164
- //Have we authorised the connection
165
- function isconnected()
166
- {
167
- return (isset($this->secret));
168
- }
169
-
170
- function reset()
171
- {
172
- unset($this->secret);
173
- unset($this->token);
174
- delete_option('blogger_importer_connector');
175
- }
176
-
177
- function save_vars()
178
- {
179
- if (!update_option('blogger_importer_connector', $this)) {
180
- Blogger_Import::_log('Error saving connection');
181
- Blogger_Import::_log(var_export(get_object_vars($this),true));
182
- };
183
- return !empty($vars);
184
- }
185
-
186
- //Return the connection
187
- static function read_option()
188
- {
189
- $connection = get_option('blogger_importer_connector',new Blogger_Importer_Connector());
190
- return $connection;
191
- }
192
-
193
- }
194
-
195
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
blogger-importer-table.php DELETED
@@ -1,118 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * @author Andy Clark
5
- * @copyright 2013
6
- * Ref:http://wpengineer.com/2426/wp_list_table-a-step-by-step-guide/
7
- * Class to render the blog table
8
- */
9
-
10
- if( ! class_exists( 'WP_List_Table' ) ) {
11
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
12
- }
13
-
14
- class Blogger_Import_List_Table extends WP_List_Table {
15
-
16
- //Use unique names here so that WP does not style our comments as pers some other tables.
17
- function get_columns(){
18
- $columns = array(
19
- 'BL_name' => __('Blog Name','blogger-importer'),
20
- 'BL_url' => __('Blog URL','blogger-importer'),
21
- 'BL_posts' => __('Posts','blogger-importer'),
22
- 'BL_comments' => __('Comments','blogger-importer'),
23
- 'BL_images' => __('Images','blogger-importer'),
24
- 'BL_links' => __('Links','blogger-importer'),
25
- 'BL_action' => __('Action Button','blogger-importer')
26
- );
27
-
28
- return $columns;
29
- }
30
-
31
- function prepare_items($blogs,$JSInit) {
32
-
33
- $columns = $this->get_columns();
34
- $hidden = array();
35
- $sortable = array();
36
- $this->_column_headers = array($columns, $hidden, $sortable);
37
- $this->JSInit = $JSInit;
38
-
39
- foreach ($blogs as $i => $blog) {
40
- $row = array();
41
- $row['ID'] = $i;
42
- $row['BL_name'] = esc_js($blog->title);
43
- $row['BL_url'] = $blog->host;
44
- $row['BL_posts'] = array('posts_done'=> ($blog->posts_done) ? (int)$blog->posts_done : 0,'total_posts' => $blog->total_posts);
45
- $row['BL_comments'] = array('comments_done'=> ($blog->comments_done) ? (int)$blog->comments_done : 0,'total_comments' => $blog->total_comments);
46
- $row['BL_images'] = $blog->images_done ? (int)$blog->images_done : 0;
47
- $row['BL_links'] = $blog->links_done ? (int)$blog->links_done : 0;
48
- $row['BL_action'] = $blog->mode;
49
- $this->items[] = $row;
50
- }
51
- }
52
-
53
- //Column Rendering
54
- function column_BL_posts( $item ) {
55
- return sprintf('<div ID="Posts%s"><div ID="PostsLabel%s" class="ui-progressbar-caption">'.__('%d of %d', 'blogger-importer').'</div></div>',$item['ID'],$item['ID'],$item['BL_posts']['posts_done'],$item['BL_posts']['total_posts']);
56
- }
57
-
58
- function column_BL_comments( $item ) {
59
- return sprintf('<div ID="Comments%s"><div ID="CommentsLabel%s" class="ui-progressbar-caption">'.__('%d of %d', 'blogger-importer').'</div></div>',$item['ID'],$item['ID'],$item['BL_comments']['comments_done'],$item['BL_comments']['total_comments']);
60
- }
61
-
62
- function column_BL_images( $item ) {
63
- return sprintf('<div ID="Images%s"><div ID="ImagesLabel%s" class="ui-progressbar-caption">%d</div></div>',$item['ID'],$item['ID'],$item['BL_images']);
64
- }
65
-
66
- function column_BL_links( $item ) {
67
- return sprintf('<div ID="Links%s"><div ID="LinksLabel%s" class="ui-progressbar-caption">%d</div></div>',$item['ID'],$item['ID'],$item['BL_links']);
68
- }
69
-
70
- function column_BL_action( $item ) {
71
- $start = esc_js(__('Import', 'blogger-importer'));
72
- $continue = esc_js(__('Continue', 'blogger-importer'));
73
- $stop = esc_js(__('Importing...', 'blogger-importer'));
74
- $authors = esc_js(__('Set Authors', 'blogger-importer'));
75
-
76
- if ($item['BL_action'] == 'init')
77
- $value = $start;
78
- elseif ($item['BL_action'] == 'posts' || $item['BL_action'] == 'comments')
79
- $value = $continue;
80
- else
81
- $value = $authors;
82
- $value = esc_attr($value);
83
-
84
- return sprintf("<input type='submit' class='button' id='submit%s' value='%s' /><input type='hidden' name='blog' value='%s' />",$item['ID'],$value,$item['ID']);
85
- }
86
-
87
- function column_default( $item, $column_name ) {
88
- switch( $column_name ) {
89
- case 'BL_name':
90
- case 'BL_url':
91
- case 'BL_comments':
92
- case 'BL_images':
93
- case 'BL_links':
94
- case 'BL_action':
95
- return $item[ $column_name ];
96
- default:
97
- return print_r( $item, true ) ; //Show the whole array for troubleshooting purposes
98
- }
99
- }
100
-
101
- //Run Javascript at the bottom of the page to pass table data through to JQuery
102
- function _js_vars() {
103
- printf( "<!--blogger-importer-table _js_vars -->
104
- <script type='text/javascript'>
105
- /* <![CDATA[ */
106
- var blogs = {};
107
- jQuery(function() {
108
- %s
109
- jQuery.each(blogs, function(i, me){me.init();});
110
- jQuery('#Refresh').bind('click', function(){return jQuery.each(blogs, function(i, me){me.stop();})});
111
- });
112
- /* ]]> */
113
- </script>\n",$this->JSInit );
114
- }
115
-
116
-
117
- }
118
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
blogger-importer.css DELETED
@@ -1,62 +0,0 @@
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
- /* Todo: Review some of these since moving to WP_Tables */
17
- .stat {
18
- z-index: 10;
19
- position: relative;
20
- text-align: center;
21
- }
22
- td.submit {
23
- margin:0;
24
- padding:0;
25
- }
26
-
27
- td {
28
- padding-left:10px;
29
- padding-right:10px;
30
- }
31
-
32
- /* Fix for MP6 plugin aka future styling for Admin UI */
33
- table.wp-list-table td { line-height: 2em;}
34
-
35
- .column-BL_name { text-align: left;}
36
- .column-BL_url { text-align: left;}
37
- .column-BL_posts { text-align: left; width:12%; }
38
- .column-BL_comments { text-align: left; width:12%;}
39
- .column-BL_images { text-align: left; width:12%;}
40
- .column-BL_links { text-align: left; width:12%;}
41
- .column-BL_action { text-align: left; width:8%;}
42
-
43
- td.column-BL_posts div { width: 100%; }
44
-
45
- /* JQuery Progress Bars */
46
- .ui-progressbar-value {background-color: #83B4D8;
47
- position:relative;
48
- height:2em;
49
- margin-top:-2em;
50
- z-index: 9;
51
- display: block;}
52
- .ui-progressbar {border: thin solid;
53
- height:2em;
54
- }
55
-
56
- .ui-progressbar-caption {
57
- z-index:10;
58
- display: block;
59
- position: relative;
60
- text-align: center;
61
-
62
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
blogger-importer.js DELETED
@@ -1,146 +0,0 @@
1
- /* Javascript for refreshing the blog table. */
2
- /* Localised strings passed to this via wp_localize_script and BL_strings object */
3
- /* Stop on error or stop if Ajax Admin can't find a suitable handler */
4
- function blog(i, title, mode, status){
5
- this.blog = i;
6
- this.mode = mode;
7
- this.title = title;
8
- eval('this.status='+status);
9
- this.button = '#submit'+this.blog;
10
- };
11
- blog.prototype = {
12
- start: function() {
13
- this.cont = true;
14
- this.kick();
15
- this.check();
16
- },
17
- kick: function() {
18
- ++this.kicks;
19
- with ({currentblog: this.blog}) {
20
- jQuery.post(BL_strings.ajaxURL,{
21
- action: 'BL_import',
22
- blogID:this.blog
23
- },
24
- function(text,result){blogs[currentblog].kickd(text,result)});
25
- }
26
- },
27
- check: function() {
28
- ++this.checks;
29
- with ({currentblog: this.blog}) {
30
- jQuery.post(BL_strings.ajaxURL,{
31
- action: 'BL_status',
32
- blogID:this.blog
33
- },
34
- function(text,result){blogs[currentblog].checkd(text,result)});
35
- }
36
- },
37
- kickd: function(text, result) {
38
- --this.kicks;
39
- if ( result == 'error' || text == '0' ) {
40
- // TODO: exception handling
41
- this.stop();
42
- } else {
43
- if ( text == 'done' ) {
44
- this.stop();
45
- this.done();
46
- this.check();
47
- } else if ( text == 'nothing' ) {
48
- this.stop();
49
- this.nothing();
50
- this.done();
51
- } else if ( text == 'continue' ) {
52
- this.kick();
53
- } else if ( this.mode == 'stopped' )
54
- jQuery(this.button).attr('value', BL_strings.cont);
55
-
56
- }
57
- },
58
- checkd: function(text, result) {
59
- --this.checks;
60
- if ( result == 'error' || text == '0' ) {
61
- // TODO: exception handling
62
- this.stop();
63
- } else {
64
- eval('this.status='+text);
65
- this.update();
66
- if ( this.cont || this.kicks > 0 ) {
67
- with ({currentblog: this.blog}) {
68
- setTimeout(function() {
69
- blogs[currentblog].check();
70
- },parseInt(BL_strings.interval));
71
- }
72
- }
73
- }
74
- },
75
- update: function() {
76
- try
77
- {
78
- jQuery('#Posts'+this.blog).progressbar({ value: this.status.p1});
79
- jQuery('#PostsLabel'+this.blog).text(this.status.p2);
80
- jQuery('#Posts'+this.blog).attr('title', this.status.p3);
81
- jQuery('#Comments'+this.blog).progressbar({ value: this.status.c1 });
82
- jQuery('#CommentsLabel'+this.blog).text(this.status.c2);
83
- jQuery('#Comments'+this.blog).attr('title',this.status.c3);
84
- jQuery('#Images'+this.blog).progressbar({ value: this.status.i2});
85
- jQuery('#ImagesLabel'+this.blog).text(this.status.i1);
86
- jQuery('#Images'+this.blog).attr('title',this.status.i3);
87
- jQuery('#Links'+this.blog).progressbar({ value: this.status.l2 });
88
- jQuery('#LinksLabel'+this.blog).text(this.status.l1);
89
- }
90
- catch(err)
91
- {
92
- txt="Error displaying updates for "+this.title+", importer cannot continue\n\n";
93
- txt+="Error description: " + err.message + "\n\n";
94
- txt+="Click OK to continue.\n\n";
95
- alert(txt);
96
- }
97
- },
98
- stop: function() {
99
- this.cont = false;
100
- },
101
- done: function() {
102
- this.mode = 'authors';
103
- jQuery(this.button).attr('value', BL_strings.authors);
104
- },
105
- nothing: function() {
106
- this.mode = 'nothing';
107
- jQuery(this.button).remove();
108
- alert(BL_strings.nothing);
109
- },
110
- getauthors: function() {
111
- if ( jQuery('div.wrap').length > 1 )
112
- jQuery('div.wrap').gt(0).remove();
113
- jQuery('div.wrap').empty().append('<h2>'+BL_strings.authhead+'</h2><h3>' + this.title + '</h3>');
114
- jQuery('div.wrap').append('<p id=\"auth\">'+BL_strings.loadauth+'</p>');
115
- jQuery('p#auth').load('index.php?import=blogger&noheader=true&authors=1',{blog:this.blog});
116
- },
117
- init: function() {
118
- this.update();
119
- var i = this.blog;
120
- jQuery(this.button).bind('click', function(){return blogs[i].click();});
121
- this.kicks = 0;
122
- this.checks = 0;
123
- },
124
- click: function() {
125
- if ( this.mode == 'init' || this.mode == 'stopped' || this.mode == 'posts' || this.mode == 'comments' ) {
126
- this.mode = 'started';
127
- this.start();
128
- jQuery(this.button).attr('value', BL_strings.stop);
129
- } else if ( this.mode == 'started' ) {
130
- //return false; // let it run...
131
- this.mode = 'stopped';
132
- this.stop();
133
- if ( this.checks > 0 || this.kicks > 0 ) {
134
- this.mode = 'stopping';
135
- jQuery(this.button).attr('value', BL_strings.stopping);
136
- } else {
137
- jQuery(this.button).attr('value', BL_strings.cont);
138
- }
139
- } else if ( this.mode == 'authors' ) {
140
- document.location = 'index.php?import=blogger&authors=1&blog='+this.blog;
141
- //this.mode = 'authors2';
142
- //this.getauthors();
143
- }
144
- return false;
145
- }
146
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
blogger-importer.php CHANGED
@@ -1,490 +1,917 @@
1
- <?php
2
-
3
- /*
4
- Plugin Name: Blogger Importer
5
- Plugin URI: http://wordpress.org/extend/plugins/blogger-importer/
6
- Description: Imports posts, comments, images and tags from a Blogger blog then migrates authors to WordPress users.
7
- Author: wordpressdotorg
8
- Author URI: http://wordpress.org/
9
- Version: 0.8
10
- License: GPLv2
11
- License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
12
- */
13
-
14
- // Wordpress Classes needed by importer
15
- require_once ABSPATH . 'wp-admin/includes/import.php';
16
- if (!class_exists('WP_Importer'))
17
- {
18
- $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
19
- if (file_exists($class_wp_importer))
20
- require_once $class_wp_importer;
21
- }
22
- if (!class_exists('WP_Error'))
23
- {
24
- $class_wp_error = ABSPATH . 'wp-includes/class-wp-error.php';
25
- if (file_exists($class_wp_error))
26
- require_once $class_wp_error;
27
- }
28
-
29
-
30
- require_once ABSPATH . WPINC . '/class-feed.php';
31
-
32
- // Custom classes used by importer
33
- require_once dirname( __FILE__ ) . '/blogger-importer-sanitize.php';
34
- require_once dirname( __FILE__ ) . '/blogger-importer-blogitem.php';
35
- require_once dirname( __FILE__ ) . '/blogger-importer-blog.php';
36
- require_once dirname( __FILE__ ) . '/blogger-importer-connector.php';
37
- require_once dirname( __FILE__ ) . '/blogger-entry.php';
38
- require_once dirname( __FILE__ ) . '/comment-entry.php';
39
- require_once dirname( __FILE__ ) . '/oauth.php';
40
- require_once dirname( __FILE__ ) . '/blogger-importer-table.php';
41
-
42
- /**
43
- * Blogger Importer
44
- *
45
- * @package WordPress
46
- * @subpackage Importer
47
- */
48
- if (class_exists('WP_Importer'))
49
- {
50
- class Blogger_Import extends WP_Importer
51
- {
52
- // 14/2/2013 switched from global defines to class constants
53
- // These are used to change the behaviour of the importer from the default.
54
- const MAX_RESULTS = 25; // How many records per GData query (int)
55
- const MAX_EXECUTION_TIME = 20; // How many seconds to let the script run (int)
56
- const STATUS_INTERVAL = 3; // How many seconds between status bar updates (int)
57
- const IMPORT_IMG = true; // Should we import the images (boolean)
58
- const REMOTE_TIMEOUT = 5; // How many seconds to wait until google responds (int)
59
- const LARGE_IMAGE_SIZE = '1024'; // The size of large images downloaded (string)
60
- const POST_PINGBACK = 0; // Turn off the post pingback, set to 1 to re-enabled(bool)
61
- //N.B. Not all images will be this large and not all will be able to be remapped.
62
-
63
- var $blogs = array();
64
- var $connector;
65
-
66
- function Blogger_Import()
67
- {
68
- if (isset($_GET['import']) && $_GET['import'] == 'blogger')
69
- {
70
- add_action('admin_print_scripts', array(&$this, 'queue_scripts'));
71
- add_action('admin_print_styles', array(&$this, 'queue_style'));
72
- add_filter('blogger_importer_congrats', array(&$this, 'congrats_options'), 10, 2);
73
- //Looking at the Wordpress importer there appear to be quite a few "filters" there that perhaps should be standardised across all importers.
74
- }
75
- //Get Data
76
- $this->read_options();
77
- }
78
-
79
- static function register_importer()
80
- {
81
- if (!defined('WP_LOAD_IMPORTERS'))
82
- return;
83
- //Moved in from blogger_importer_init
84
- load_plugin_textdomain('blogger-importer', false, dirname(plugin_basename(__file__)) . '/languages');
85
-
86
- $blogger_import = new Blogger_Import();
87
- register_importer('blogger', __('Blogger', 'blogger-importer'), __('Import categories, posts, images and comments then maps users from a Blogger blog.', 'blogger-importer'), array($blogger_import,'start'));
88
- }
89
-
90
- function queue_scripts($hook)
91
- {
92
- $interval = self::STATUS_INTERVAL * 1000;
93
- wp_enqueue_script('BloggerImporter', plugins_url('/blogger-importer.js', __file__), array('jquery','jquery-ui-progressbar'), '', true);
94
- wp_localize_script('BloggerImporter', 'BL_strings', array('ajaxURL' => admin_url('admin-ajax.php'), 'cont' => esc_js(__('Continue', 'blogger-importer')), 'stop' => esc_js(__('Importing...', 'blogger-importer')), 'stopping' => '', 'authors' =>
95
- esc_js(__('Set Authors', 'blogger-importer')), 'nothing' => esc_js(__('Nothing was imported. Had you already imported this blog?', 'blogger-importer')), 'loadauth' => esc_js(__('Preparing author mapping form...',
96
- 'blogger-importer')), 'authhead' => esc_js(__('Final Step: Author Mapping', 'blogger-importer')), 'interval' => $interval));
97
- }
98
-
99
- function queue_style()
100
- {
101
- wp_enqueue_style('BloggerImporter', plugins_url('/blogger-importer.css', __file__));
102
- }
103
-
104
- // Shows the welcome screen and the magic auth link.
105
- function greet()
106
- {
107
- $title = __('Import Blogger', 'blogger-importer');
108
- $welcome = __('Howdy! This importer allows you to import posts and comments from your Blogger account into your WordPress site.', 'blogger-importer');
109
- $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');
110
- $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');
111
- $errormsg = __('Error occurred getting OAuth tokens from Google', 'blogger-importer');
112
-
113
- echo "
114
-
115
- <div class='wrap'>
116
- " . screen_icon() . "
117
- <h2>$title</h2>
118
- <p>$welcome</p><p>$prereqs</p><p>$stepone</p>";
119
-
120
- $isconnected = $this->connector->connect(admin_url('admin-ajax.php?action=BL_auth'));
121
- if (!is_wp_error($isconnected))
122
- {
123
- echo($this->connector->auth_form());
124
- } else
125
- {
126
-
127
- echo '<p>' . $errormsg . '</p>';
128
- echo '<p><pre>
129
- ' . $isconnected->get_error_message() . '
130
- </pre></p>';
131
- }
132
- }
133
-
134
-
135
- function uh_oh($title, $message, $info)
136
- {
137
- echo "<div class='wrap'>";
138
- screen_icon();
139
- echo "<h2>$title</h2><p>$message</p><pre>$info</pre></div>";
140
- }
141
-
142
- /**
143
- * Gets the list of blogs from blogger into an array $this->blogs[]
144
- */
145
- function get_blogs($iter = 0)
146
- {
147
- $xml = $this->connector->oauth_get('https://www.blogger.com/feeds/default/blogs');
148
-
149
- // Give it a few retries... apparently this step often flakes out the first time.
150
- if (empty($xml))
151
- {
152
- if ($iter < 3)
153
- {
154
- return $this->get_blogs($iter + 1);
155
- } else
156
- {
157
- return false;
158
- }
159
- }
160
-
161
- $feed = new SimplePie();
162
- $feed->set_raw_data($xml);
163
- $feed->init();
164
-
165
- $i = 0;
166
- foreach ($feed->get_items() as $item)
167
- {
168
- $blog = new Blogger_Importer_Blog();
169
- $blog->ID = $i++;
170
- //Perhaps these could be passed as parameters to the new blog object or the init defaults call?
171
- $blog->title = $item->get_title();
172
- $blog->summary = $item->get_description();
173
-
174
- //id is of the form tag:blogger.com,1999:blog-417730729915399755
175
- //We need that number from the end
176
- $rawid = explode('-', $item->get_id());
177
- $blog->id = $rawid[count($rawid) - 1];
178
-
179
- $parts = parse_url($item->get_link(0, 'alternate'));
180
- $blog->host = $parts['host'];
181
- $blog->gateway = $item->get_link(0, 'edit');
182
- $blog->posts_url = $item->get_link(0, 'http://schemas.google.com/g/2005#post');
183
- //AGC:20/4/2012 Developers guide suggests that the correct feed is located as follows
184
- //See https://developers.google.com/blogger/docs/1.0/developers_guide_php
185
- $blog->comments_url = "http://www.blogger.com/feeds/{$blog->id}/comments/default";
186
-
187
- $blog->init_defaults($this->connector->get_total_results($blog->posts_url),$this->connector->get_total_results($blog->comments_url));
188
-
189
- $this->blogs[] = $blog;
190
- }
191
-
192
- return true;
193
- }
194
-
195
- /**
196
- * Shows the list of your bloger blogs as a table
197
- * 25/1/2013 AGC: Moved the table rendering to be a wp_list_table
198
- *
199
- * @See Blogger_Import_List_Table
200
- * @Link http://wpengineer.com/2426/wp_list_table-a-step-by-step-guide/
201
- */
202
- function show_blogs()
203
- {
204
- global $wp_importers;
205
- $noscript = esc_html__('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.',
206
- 'blogger-importer');
207
- $title = esc_html__('Import Blogger', 'blogger-importer');
208
- $refreshbutton = esc_attr__('Refresh blog list', 'blogger-importer');
209
-
210
- $intro = $wp_importers['blogger'][1];
211
-
212
- $init = '';
213
- foreach ($this->blogs as $i => $blog)
214
- {
215
- $blogtitle = esc_js($blog->title);
216
- $init .= "blogs[$i]=new blog($i,'$blogtitle','{$blog->mode}','" . $blog->get_js_status() . '\');';
217
- }
218
-
219
- echo screen_icon() . "<h2>" . $title . "</h2><noscript>" . $noscript . "</noscript>";
220
-
221
- echo '<p>' . $intro . '</p>';
222
-
223
- $myListTable = new Blogger_Import_List_Table(array('ajax' => true));
224
- $myListTable->prepare_items($this->blogs, $init);
225
- echo '<div id="BlogList" class="wrap">';
226
- $myListTable->display();
227
- echo '</div>';
228
-
229
- //Refresh button
230
- echo ("<form method='post' action='?import=blogger'>
231
- <p class='submit' style='text-align:left;'>");
232
- wp_nonce_field( 'blogger-importer-refresh', 'blogger-importer-refresh-nonce' );
233
- printf("<input type='submit' class='button' value='%s' name='refresh' /></p></form>",$refreshbutton);
234
- }
235
-
236
- /**
237
- * A clean return function for Ajax calls,
238
- * http://www.dagondesign.com/articles/wordpress-hook-for-entire-page-using-output-buffering/
239
- * 11/3/2014 Simplified this as the output buffer cleaning rarely seemed to work
240
- */
241
-
242
- function ajax_die($data)
243
- {
244
- header( 'Content-Type: text/plain' );
245
- echo $data;
246
- exit;
247
- }
248
-
249
- //AJAX functions
250
- static function ajax_getstatus()
251
- {
252
- $blogID = $_POST['blogID'];
253
- $blog = Blogger_Importer_Blog::read_option($blogID);
254
- Blogger_Import::ajax_die($blog->get_js_status());
255
- }
256
-
257
- static function ajax_doimport()
258
- {
259
- $blogID = $_POST['blogID'];
260
- $blog = Blogger_Importer_Blog::read_option($blogID);
261
- $connector = Blogger_Importer_Connector::read_option();
262
- Blogger_Import::ajax_die($blog->import_blog($connector));
263
- }
264
-
265
- static function ajax_doauth()
266
- {
267
- $connector = Blogger_Importer_Connector::read_option();
268
- $connector->auth($_GET['token'],$_GET['secret']);
269
- wp_redirect(admin_url('admin.php?import=blogger'));
270
- }
271
-
272
- function get_author_form($blog)
273
- {
274
- //Present a form to the users so they can re-map the imported authors to Wordpress users.
275
- $blog->get_authors();
276
-
277
- $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.',
278
- 'blogger-importer'), 'users.php');
279
- $heading = __('Author mapping', 'blogger-importer');
280
- $blogtitle = "{$blog->title} ({$blog->host})";
281
- $mapthis = __('Blogger username', 'blogger-importer');
282
- $tothis = __('WordPress login', 'blogger-importer');
283
- $submit = esc_js(__('Save Changes', 'blogger-importer'));
284
- $rows = '';
285
-
286
- foreach ($blog->authors as $i => $author)
287
- $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>";
288
-
289
- 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='" .
290
- esc_attr($blog->ID) . "' />".wp_nonce_field( 'blogger-importer-saveauthors', 'blogger-importer-saveauthors-nonce',true,false )."<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>";
291
- }
292
-
293
- function get_user_options($current)
294
- {
295
- //AGC: 21/10/2013 Simplified function, caching using a global variable not needed as this is not a function that is called frequently.
296
- $importer_users = (array )get_users(); //Function: get_users_of_blog() Deprecated in version 3.1. Use get_users() instead.
297
-
298
- $options = '';
299
-
300
- foreach ($importer_users as $user)
301
- {
302
- $sel = ($user->ID == $current) ? " selected='selected'" : '';
303
- $options .= "<option value='$user->ID'$sel>$user->display_name</option>";
304
- }
305
-
306
- return $options;
307
- }
308
-
309
- function restart()
310
- {
311
- $this->connector->reset();
312
- $options = get_option('blogger_importer');
313
-
314
- delete_option('blogger_importer');
315
- foreach ($this->blogs as $i => $blog)
316
- {
317
- delete_option('blogger_importer_blog_'.$blog->ID);
318
- }
319
- }
320
-
321
- // Step 9: Congratulate the user
322
- function congrats()
323
- {
324
- echo "<div class='wrap'>";
325
- screen_icon();
326
-
327
- echo '<h2>' . __('Congratulations!', 'blogger-importer') . '</h2><p>' . __('Now that you have imported your Blogger blog into WordPress, what are you going to do? Here are some suggestions:',
328
- 'blogger-importer') . '</p><ul>';
329
-
330
- $congrats = apply_filters('blogger_importer_congrats', '', count($this->blogs));
331
- $congrats = $congrats . '<li>' . __('For security, click the link below to reset this importer.', 'blogger-importer') . '</li>';
332
- echo $congrats;
333
- echo '</ul>';
334
- echo '</div>';
335
- }
336
-
337
- function congrats_options($optionlist, $blogcount)
338
- {
339
- //Plugable list of options called by filter 'blogger_importer_congrats'
340
- $optionlist = $optionlist . '<li><a href="' . admin_url('edit.php') . '">' . __('Review posts', 'blogger-importer') . '</a></li>';
341
- $optionlist = $optionlist . '<li><a href="' . admin_url('edit-tags.php?taxonomy=category') . '">' . __('Review categories', 'blogger-importer') . '</a></li>';
342
- $optionlist = $optionlist . '<li><a href="' . admin_url('import.php') . '">' . __('Convert categories to tags', 'blogger-importer') . '</a></li>';
343
- $optionlist = $optionlist . '<li><a href="' . admin_url('edit-comments.php') . '">' . __('Review comments', 'blogger-importer') . '</a></li>';
344
- $optionlist = $optionlist . '<li><a href="' . admin_url('upload.php') . '">' . __('Review media', 'blogger-importer') . '</a></li>';
345
-
346
- if ($blogcount > 1)
347
- {
348
- $optionlist = $optionlist . '<li>' . __('In case you haven&#8217;t done it already, you can import the posts from your other blogs:', 'blogger-importer');
349
- $optionlist = $optionlist . ' <a href="' . admin_url('?import=blogger') . '">' . __('Show blogs', 'blogger-importer') . '</a></li>';
350
- }
351
- return $optionlist;
352
- }
353
-
354
- function read_options()
355
- {
356
- $options = get_option('blogger_importer');
357
- if (is_array($options))
358
- foreach ($options as $key => $value)
359
- $this->$key = $value;
360
-
361
- $this->connector = Blogger_Importer_Connector::read_option();
362
-
363
- if (count($this->blogs) == 0) {
364
- $blog = true;
365
- for ($i = 0; $blog ; $i++) {
366
- $blog = Blogger_Importer_Blog::read_option($i);
367
- if ($blog) {
368
- $this->blogs[] = $blog;
369
- }
370
- }
371
- }
372
- }
373
-
374
- function save_vars()
375
- {
376
- //Todo: return false if errors occur
377
- $vars = get_object_vars($this);
378
-
379
- if (array_key_exists('blogs',$vars)){
380
- unset($vars['blogs']);
381
- }
382
- if (array_key_exists('connector',$vars)){
383
- unset($vars['connector']);
384
- }
385
-
386
- //http://core.trac.wordpress.org/ticket/13480
387
- //Calling update options multiple times in a page (or ajax call) means that the cache kicks in and does not save to DB
388
- update_option('blogger_importer', $vars);
389
-
390
- //How to check for errors here?
391
- if (isset($connector)) {
392
- $connector->save_vars();
393
- }
394
- foreach ($this->blogs as $i => $blog) {
395
- $blog->save_vars();
396
- }
397
- return true;
398
- }
399
-
400
-
401
- /**
402
- * The start function is what is called when the importer runs
403
- * it is used to parse the parameters and select the appropriate
404
- * action such as importing a blog
405
- * Moved status and import out to separate ajax calls
406
- */
407
- function start()
408
- {
409
- if (isset($_POST['restart'])) {
410
- if ( check_admin_referer( 'blogger-importer-clear', 'blogger-importer-clear-nonce' ) ) {
411
- $this->restart();
412
- wp_redirect('?import=blogger');
413
- } else {
414
- wp_die('Error');
415
- }
416
- }
417
- if (isset($_POST['refresh'])) {
418
- if ( check_admin_referer( 'blogger-importer-refresh', 'blogger-importer-refresh-nonce' ) ) {
419
- $this->blogs = array();
420
- } else {
421
- wp_die('Error');
422
- }
423
- }
424
- if (isset($_REQUEST['blog'])) {
425
- $importing_blog = (int)(is_array($_REQUEST['blog']) ? array_shift($keys = array_keys($_REQUEST['blog'])) : $_REQUEST['blog']);
426
- $blog = $this->blogs[$importing_blog];
427
-
428
- if (isset($_GET['authors'])) {
429
- print ($this->get_author_form($blog));
430
- return;
431
- }
432
- if (isset($_GET['saveauthors'])) {
433
- if ( check_admin_referer( 'blogger-importer-saveauthors', 'blogger-importer-saveauthors-nonce' )) {
434
- $blog->save_authors();
435
- wp_redirect('?import=blogger&congrats=1');
436
- }
437
- }
438
- } elseif (isset($_GET['congrats'])) {
439
- $this->congrats();
440
- } elseif (isset($this->connector) && $this->connector->isconnected()) {
441
- if (empty($this->blogs)) {
442
- if (!$this->get_blogs()) {
443
- $this->uh_oh(__('Trouble signing in', 'blogger-importer'), __('We were not able to gain access to your account. Try starting over.', 'blogger-importer'), '');
444
- }
445
- if (empty($this->blogs)) {
446
- $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'), '');
447
- }
448
- }
449
- if (!empty($this->blogs)) {
450
- $this->show_blogs();
451
- }
452
- } else {
453
- $this->connector = new Blogger_Importer_Connector();
454
- $this->greet();
455
- }
456
-
457
- if (isset($this->connector) && $this->connector->isconnected())
458
- {
459
- $restart = __('Restart', 'blogger-importer');
460
- $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.',
461
- 'blogger-importer');
462
- $submit = esc_attr__('Clear account information', 'blogger-importer');
463
- echo "<div class='wrap'><h2>$restart</h2><p>$message</p>";
464
- echo "<form method='post' action='?import=blogger&amp;noheader=true'>";
465
- wp_nonce_field( 'blogger-importer-clear', 'blogger-importer-clear-nonce' );
466
- printf("<p class='submit' style='text-align:left;'><input type='submit' class='button' value='%s' name='restart' /></p></form>",$submit);
467
- }
468
- $this->save_vars();
469
- }
470
-
471
- function _log( $message ) {
472
- //Log to file only, we can't log to display as this is a background(ajax) call and there is no display
473
- if( WP_DEBUG === true && WP_DEBUG_DISPLAY === false ){
474
- if( is_array( $message ) || is_object( $message ) ){
475
- error_log( print_r( $message, true ) );
476
- } else {
477
- error_log( $message );
478
- }
479
- }
480
- }
481
- }
482
- } // class_exists( 'WP_Importer' )
483
-
484
- add_action('admin_init', array('Blogger_Import','register_importer'));
485
- //Ajax calls
486
- add_action('wp_ajax_BL_import', array('Blogger_Import','ajax_doimport'));
487
- add_action('wp_ajax_BL_status', array('Blogger_Import','ajax_getstatus'));
488
- add_action('wp_ajax_BL_auth', array('Blogger_Import','ajax_doauth'));
489
-
490
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Blogger Importer
4
+ Plugin URI: http://wordpress.org/extend/plugins/blogger-importer/
5
+ Description: Import posts, comments, and categories from a Blogger blog and migrate authors to WordPress users.
6
+ Author: wordpressdotorg
7
+ Author URI: http://wordpress.org/
8
+ Version: 0.9
9
+ License: GPLv2
10
+ License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11
+ Text Domain: blogger-importer
12
+ Domain Path: /languages
13
+ */
14
+
15
+ if ( ! defined( 'WP_LOAD_IMPORTERS' ) )
16
+ return;
17
+
18
+ /** Display verbose errors */
19
+ define( 'IMPORT_DEBUG', false );
20
+
21
+ // Load Importer API
22
+ require_once ABSPATH . 'wp-admin/includes/import.php';
23
+
24
+ require_once ABSPATH . WPINC . '/class-feed.php';
25
+
26
+ // Custom classes used by importer
27
+ require_once dirname( __FILE__ ) . '/blogger-importer-sanitize.php';
28
+ require_once dirname( __FILE__ ) . '/blogger-importer-blogitem.php';
29
+ require_once dirname( __FILE__ ) . '/blogger-entry.php';
30
+ require_once dirname( __FILE__ ) . '/comment-entry.php';
31
+
32
+
33
+ if ( ! class_exists( 'WP_Importer' ) ) {
34
+ $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
35
+ if ( file_exists( $class_wp_importer ) )
36
+ require $class_wp_importer;
37
+ }
38
+
39
+ /**
40
+ * Blogger Importer class for managing the import process of a XML file
41
+ *
42
+ */
43
+ if ( !class_exists( 'Blogger_Importer' ) ) {
44
+ class Blogger_Importer extends WP_Importer {
45
+ const IMPORT_IMG = true; // Should we import the images (boolean)
46
+ const LARGE_IMAGE_SIZE = '1024'; // The size of large images downloaded (string)
47
+ const POST_PINGBACK = 0; // Turn off the post pingback, set to 1 to re-enabled(bool)
48
+
49
+ var $id; // XML attachment ID
50
+
51
+ var $authors = array();
52
+
53
+ // mappings from old information to new
54
+ var $processed_authors = array();
55
+ var $author_mapping = array();
56
+
57
+ function Blogger_Importer() { /* nothing */ }
58
+
59
+ /**
60
+ * Registered callback function for the Blogger Importer
61
+ *
62
+ * Manages the three separate stages of the XML import process
63
+ */
64
+ function dispatch() {
65
+ $this->header();
66
+
67
+ $step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
68
+ switch ( $step ) {
69
+ case 0:
70
+ $this->greet();
71
+ break;
72
+ case 1:
73
+ check_admin_referer( 'import-upload' );
74
+ if ( $this->handle_upload() )
75
+ $this->import_options();
76
+ break;
77
+ case 2:
78
+ check_admin_referer( 'import-blogger' );
79
+ $this->id = (int) $_POST['import_id'];
80
+ $file = get_attached_file( $this->id );
81
+ set_time_limit(0);
82
+ $this->import( $file );
83
+ break;
84
+ }
85
+
86
+ $this->footer();
87
+ }
88
+
89
+ /**
90
+ * The main controller for the actual import stage.
91
+ *
92
+ * @param string $file Path to the XML file for importing
93
+ */
94
+ function import( $file ) {
95
+ add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) );
96
+
97
+ $this->import_start( $file );
98
+
99
+ $this->get_author_mapping();
100
+
101
+ wp_suspend_cache_invalidation( true );
102
+ $this->process_posts();
103
+ $this->process_comments();
104
+
105
+ if (Blogger_Importer::IMPORT_IMG)
106
+ {
107
+ $this->process_images();
108
+ }
109
+
110
+ $this->process_links();
111
+
112
+ wp_suspend_cache_invalidation( false );
113
+
114
+ // update incorrect/missing information in the DB
115
+ //$this->backfill_parents();
116
+ //$this->backfill_attachment_urls();
117
+ //$this->remap_featured_images();
118
+
119
+ $this->import_end();
120
+ }
121
+
122
+ /**
123
+ * Parses the XML file and prepares us for the task of processing parsed data
124
+ *
125
+ * @param string $file Path to the XML file for importing
126
+ */
127
+ function import_start( $file ) {
128
+ if ( ! is_file($file) ) {
129
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'blogger-importer' ) . '</strong><br />';
130
+ echo __( 'The file does not exist, please try again.', 'blogger-importer' ) . '</p>';
131
+ $this->footer();
132
+ die();
133
+ }
134
+
135
+ $import_data = $this->parse( $file );
136
+
137
+ if ( is_wp_error( $import_data ) ) {
138
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'blogger-importer' ) . '</strong><br />';
139
+ echo esc_html( $import_data->get_error_message() ) . '</p>';
140
+ $this->footer();
141
+ die();
142
+ }
143
+
144
+ $this->import_data = $import_data;
145
+
146
+ // <link rel='alternate' type='text/html' href='http://example.blogspot.com/'/>
147
+ $links = $import_data->get_links('alternate');
148
+ $this->host = parse_url($links[0], PHP_URL_HOST);
149
+
150
+ $this->images_progress = 0;
151
+ $this->images_skipped = 0;
152
+ $this->links_done = 0;
153
+ $this->links_progress = 0;
154
+
155
+ wp_defer_term_counting( true );
156
+ wp_defer_comment_counting( true );
157
+
158
+ do_action( 'import_start' );
159
+ }
160
+
161
+ /**
162
+ * Performs post-import cleanup of files and the cache
163
+ */
164
+ function import_end() {
165
+ wp_import_cleanup( $this->id );
166
+
167
+ wp_cache_flush();
168
+ foreach ( get_taxonomies() as $tax ) {
169
+ delete_option( "{$tax}_children" );
170
+ _get_term_hierarchy( $tax );
171
+ }
172
+
173
+ wp_defer_term_counting( false );
174
+ wp_defer_comment_counting( false );
175
+
176
+ echo '<p>' . __( 'All done.', 'blogger-importer' ) . ' <a href="' . admin_url() . '">' . __( 'Have fun!', 'blogger-importer' ) . '</a>' . '</p>';
177
+ echo '<p>' . __( 'Remember to update the passwords and roles of imported users.', 'blogger-importer' ) . '</p>';
178
+
179
+ do_action( 'import_end' );
180
+ }
181
+
182
+ /**
183
+ * Handles the WXR upload and initial parsing of the file to prepare for
184
+ * displaying author import options
185
+ *
186
+ * @return bool False if error uploading or invalid file, true otherwise
187
+ */
188
+ function handle_upload() {
189
+ $file = wp_import_handle_upload();
190
+
191
+ if ( isset( $file['error'] ) ) {
192
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'blogger-importer' ) . '</strong><br />';
193
+ echo esc_html( $file['error'] ) . '</p>';
194
+ return false;
195
+ } else if ( ! file_exists( $file['file'] ) ) {
196
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'blogger-importer' ) . '</strong><br />';
197
+ printf( __( 'The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'blogger-importer' ), esc_html( $file['file'] ) );
198
+ echo '</p>';
199
+ return false;
200
+ }
201
+
202
+ $this->id = (int) $file['id'];
203
+ $import_data = $file['file'];
204
+
205
+ if ( is_wp_error( $import_data ) ) {
206
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'blogger-importer' ) . '</strong><br />';
207
+ echo esc_html( $import_data->get_error_message() ) . '</p>';
208
+ return false;
209
+ }
210
+
211
+ $this->get_authors_from_import( $import_data );
212
+
213
+ return true;
214
+ }
215
+
216
+ /**
217
+ * Retrieve authors from parsed data
218
+ *
219
+ * @param array $import_data Data returned by a WXR parser
220
+ */
221
+ function get_authors_from_import( $import_data ) {
222
+
223
+ $feed = $this->parse($import_data);
224
+
225
+ $authors = $feed->get_authors();
226
+
227
+ foreach ($authors as $author) {
228
+ $login = sanitize_user( $author->get_name(), true );
229
+ $this->authors[$login] = array(
230
+ 'author_login' => $author->get_name(),
231
+ 'author_display_name' => $author->get_name(),
232
+ 'author_email' => $author->get_email(),
233
+ );
234
+ }
235
+ }
236
+
237
+ /**
238
+ * Display pre-import options, author importing/mapping and option to
239
+ * fetch attachments
240
+ */
241
+ function import_options() {
242
+ $j = 0;
243
+ ?>
244
+ <form action="<?php echo admin_url( 'admin.php?import=blogger&amp;step=2' ); ?>" method="post">
245
+ <?php wp_nonce_field( 'import-blogger' ); ?>
246
+ <input type="hidden" name="import_id" value="<?php echo $this->id; ?>" />
247
+
248
+ <?php if ( ! empty( $this->authors ) ) : ?>
249
+ <h3><?php _e( 'Assign Authors', 'blogger-importer' ); ?></h3>
250
+ <p><?php _e( 'To make it easier for you to edit and save the imported content, you may want to reassign the author of the imported item to an existing user of this site. For example, you may want to import all the entries as <code>admin</code>s entries.', 'blogger-importer' ); ?></p>
251
+ <?php if ( $this->allow_create_users() ) : ?>
252
+ <p><?php printf( __( 'If a new user is created by WordPress, a new password will be randomly generated and the new user&#8217;s role will be set as %s. Manually changing the new user&#8217;s details will be necessary.', 'blogger-importer' ), esc_html( get_option('default_role') ) ); ?></p>
253
+ <?php endif; ?>
254
+ <ol id="authors">
255
+ <?php foreach ( $this->authors as $author ) : ?>
256
+ <li><?php $this->author_select( $j++, $author ); ?></li>
257
+ <?php endforeach; ?>
258
+ </ol>
259
+ <?php endif; ?>
260
+
261
+ <p class="submit"><input type="submit" class="button" value="<?php esc_attr_e( 'Submit', 'blogger-importer' ); ?>" /></p>
262
+ </form>
263
+ <?php
264
+ }
265
+
266
+ /**
267
+ * Display import options for an individual author. That is, either create
268
+ * a new user based on import info or map to an existing user
269
+ *
270
+ * @param int $n Index for each author in the form
271
+ * @param array $author Author information, e.g. login, display name, email
272
+ */
273
+ function author_select( $n, $author ) {
274
+ _e( 'Import author:', 'blogger-importer' );
275
+ echo ' <strong>' . esc_html( $author['author_display_name'] );
276
+ echo '</strong><br />';
277
+
278
+ $create_users = $this->allow_create_users();
279
+ if ( $create_users ) {
280
+ _e( 'as a new user:', 'blogger-importer' );
281
+ $value = esc_attr( sanitize_user( $author['author_login'], true ) );
282
+
283
+ echo ' <input type="text" name="user_new['.$n.']" value="'. $value .'" /><br />';
284
+ }
285
+
286
+ _e( 'or assign posts to an existing user:', 'blogger-importer' );
287
+ wp_dropdown_users( array( 'name' => "user_map[$n]", 'multi' => true, 'show_option_all' => __( '- Select -', 'blogger-importer' ) ) );
288
+ echo '<input type="hidden" name="imported_authors['.$n.']" value="' . esc_attr( $author['author_login'] ) . '" />';
289
+ }
290
+
291
+ /**
292
+ * Map old author logins to local user IDs based on decisions made
293
+ * in import options form. Can map to an existing user, create a new user
294
+ * or falls back to the current user in case of error with either of the previous
295
+ */
296
+ function get_author_mapping() {
297
+ if ( ! isset( $_POST['imported_authors'] ) )
298
+ return;
299
+
300
+ $create_users = $this->allow_create_users();
301
+
302
+ foreach ( (array) $_POST['imported_authors'] as $i => $old_login ) {
303
+ // Multisite adds strtolower to sanitize_user. Need to sanitize here to stop breakage in process_posts.
304
+ $santized_old_login = sanitize_user( $old_login, true );
305
+ $old_id = isset( $this->authors[$old_login]['author_id'] ) ? intval($this->authors[$old_login]['author_id']) : false;
306
+
307
+ if ( ! empty( $_POST['user_map'][$i] ) ) {
308
+ $user = get_userdata( intval($_POST['user_map'][$i]) );
309
+ if ( isset( $user->ID ) ) {
310
+ if ( $old_id )
311
+ $this->processed_authors[$old_id] = $user->ID;
312
+ $this->author_mapping[$santized_old_login] = $user->ID;
313
+ }
314
+ } else if ( $create_users ) {
315
+ if ( ! empty($_POST['user_new'][$i]) ) {
316
+ $user_id = wp_create_user( $_POST['user_new'][$i], wp_generate_password() );
317
+ } else if ( $this->version != '1.0' ) {
318
+ $user_data = array(
319
+ 'user_login' => $old_login,
320
+ 'user_pass' => wp_generate_password(),
321
+ 'user_email' => isset( $this->authors[$old_login]['author_email'] ) ? $this->authors[$old_login]['author_email'] : '',
322
+ 'display_name' => $this->authors[$old_login]['author_display_name'],
323
+ 'first_name' => isset( $this->authors[$old_login]['author_first_name'] ) ? $this->authors[$old_login]['author_first_name'] : '',
324
+ 'last_name' => isset( $this->authors[$old_login]['author_last_name'] ) ? $this->authors[$old_login]['author_last_name'] : '',
325
+ );
326
+ $user_id = wp_insert_user( $user_data );
327
+ }
328
+
329
+ if ( ! is_wp_error( $user_id ) ) {
330
+ if ( $old_id )
331
+ $this->processed_authors[$old_id] = $user_id;
332
+ $this->author_mapping[$santized_old_login] = $user_id;
333
+ } else {
334
+ printf( __( 'Failed to create new user for %s. Their posts will be attributed to the current user.', 'blogger-importer' ), esc_html($this->authors[$old_login]['author_display_name']) );
335
+ if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
336
+ echo ' ' . $user_id->get_error_message();
337
+ echo '<br />';
338
+ }
339
+ }
340
+
341
+ // failsafe: if the user_id was invalid, default to the current user
342
+ if ( ! isset( $this->author_mapping[$santized_old_login] ) ) {
343
+ if ( $old_id )
344
+ $this->processed_authors[$old_id] = (int) get_current_user_id();
345
+ $this->author_mapping[$santized_old_login] = (int) get_current_user_id();
346
+ }
347
+ }
348
+ }
349
+
350
+ /**
351
+ * Create new posts based on import information
352
+ */
353
+ function process_posts() {
354
+ $feed = $this->import_data;
355
+
356
+ foreach ( $feed->get_items() as $item ) {
357
+ // check that it is actually a post first
358
+ // <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/blogger/2008/kind#post'/>
359
+ $is_post = false;
360
+ $cats = $item->get_categories();
361
+ foreach ( $cats as $cat ) {
362
+ if ( $cat == 'http://schemas.google.com/blogger/2008/kind#post' ) {
363
+ $is_post = true;
364
+ break;
365
+ }
366
+ }
367
+
368
+ // only import posts for now
369
+ if ( ! $is_post ) {
370
+ continue;
371
+ }
372
+
373
+ $blogentry = new BloggerEntry();
374
+
375
+ $blogentry->blogurl = $this->host;
376
+ $blogentry->id = $item->get_id();
377
+ $blogentry->published = $item->get_published();
378
+ $blogentry->updated = $item->get_updated();
379
+ $blogentry->isDraft = $item->get_draft_status();
380
+ $blogentry->title = $item->get_title();
381
+ $blogentry->content = $item->get_content();
382
+ $blogentry->geotags = $item->get_geotags();
383
+
384
+ // map the post author
385
+ $blogentry->bloggerauthor = sanitize_user( $item->get_author()->get_name(), true );
386
+ if ( isset( $this->author_mapping[$blogentry->bloggerauthor] ) )
387
+ $blogentry->author = $this->author_mapping[$blogentry->bloggerauthor];
388
+ else
389
+ $blogentry->author = (int) get_current_user_id();
390
+
391
+ $blogentry->links = $item->get_links(array('replies', 'edit', 'self', 'alternate'));
392
+ $blogentry->parselinks();
393
+
394
+ foreach ( $cats as $cat ) {
395
+ if ( false === strpos( $cat, 'http://schemas.google.com') ) {
396
+ $blogentry->categories[] = $cat;
397
+ }
398
+ }
399
+
400
+ // Checks for duplicates
401
+ $post_id = $blogentry->post_exists();
402
+
403
+ if ( $post_id != 0 ) {
404
+ $this->posts_skipped++;
405
+ } else {
406
+ //Unique new post so import it
407
+ $post_id = $blogentry->import();
408
+ $this->posts_done++;
409
+ }
410
+ }
411
+ }
412
+
413
+ /**
414
+ * Create new comments based on import information
415
+ */
416
+ function process_comments() {
417
+ $feed = $this->import_data;
418
+
419
+ foreach ( $feed->get_items() as $item ) {
420
+ // check that it is actually a comment first
421
+ // <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/blogger/2008/kind#comment'/>
422
+ $is_comment = false;
423
+ $cats = $item->get_categories();
424
+ foreach ( $cats as $cat ) {
425
+ if ( $cat == 'http://schemas.google.com/blogger/2008/kind#comment' ) {
426
+ $is_comment = true;
427
+ break;
428
+ }
429
+ }
430
+
431
+ // we only import comments here
432
+ if ( ! $is_comment ) {
433
+ continue;
434
+ }
435
+
436
+ $commententry = new CommentEntry();
437
+
438
+ $commententry->id = $item->get_id();
439
+ $commententry->updated = $item->get_updated();
440
+ $commententry->content = $item->get_content();
441
+ $commententry->author = $item->get_author()->get_name();
442
+ $commententry->authoruri = $item->get_author()->get_link();
443
+ $commententry->authoremail = $item->get_author()->get_email();
444
+
445
+ $replyto = $item->get_item_tags('http://purl.org/syndication/thread/1.0','in-reply-to');
446
+ $commententry->source = $replyto[0]['attribs']['']['source'];
447
+
448
+ $commententry->source = $item->get_source();
449
+ $parts = parse_url($commententry->source);
450
+ $commententry->old_post_permalink = $parts['path']; //Will be something like this '/feeds/417730729915399755/posts/default/8397846992898424746'
451
+
452
+ $bloggerentry = new BloggerEntry();
453
+ $commententry->post_ID = $bloggerentry->get_post_by_oldID($commententry->old_post_permalink);
454
+
455
+ //Get the links
456
+ $commententry->links = $item->get_links(array('edit', 'self', 'alternate', 'related'));
457
+ $commententry->parselinks();
458
+
459
+ // Nested comment?
460
+ if ( isset($commententry->related) ) {
461
+ $commententry->parentcommentid = $commententry->get_comment_by_oldID($commententry->related);
462
+ }
463
+
464
+ //Perhaps could log errors here?
465
+ if ($commententry->post_ID != 0) {
466
+ // Checks for duplicates
467
+ if ($comment_id = $commententry->exists()) {
468
+ $this->comments_skipped++;
469
+ } else {
470
+ $comment_id = $commententry->import();
471
+ $this->comments_done++;
472
+ }
473
+ } else {
474
+ $this->comments_skipped++;
475
+ }
476
+ }
477
+ }
478
+
479
+ /*
480
+ * Search for either a linked image or a non linked image within the supplied html
481
+ * <a href="xxx" yyyy><img src="zzz" ></a> or <img src="zzz" >
482
+ * Ref: http://www.the-art-of-web.com/php/parse-links/
483
+ * "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>"
484
+ * http://wordpress.org/extend/plugins/blogger-image-import/
485
+ * "<a[^>]+href\=([\"'`])(.*)\\1[^<]*?<img[^>]*src\=([\"'`])(.*)\\3[^>]*>"
486
+ */
487
+ function get_images($content) {
488
+ $highrez = array();
489
+ $lowrez = array();
490
+
491
+ //First images with links
492
+ //Might be nice to expand this top try and get Alt and/or Title attributes for use as description
493
+ $regexp = "<a\s[^>]*href\=([\"'`])([^> ]*?)\\1[^<]*?<img[^>]*src\=([\"'`])([^\> ]*?)\\3[^>]*>";
494
+
495
+ if (preg_match_all("/$regexp/siU", $content, $matches1, PREG_SET_ORDER)) {
496
+ //http://www.techrepublic.com/article/17-useful-functions-for-manipulating-arrays-in-php/5792851
497
+ foreach ($matches1 as $match) {
498
+ if ($this->isurlimage($match[2])) {
499
+ $highrez[$match[4]] = $match[2];
500
+ } else {
501
+ $lowrez[$match[4]] = '';
502
+ }
503
+ }
504
+ }
505
+
506
+ //Now any image (n.b. this overlaps the previous set)
507
+ $regexp = "<img[^>]*src\=([\"'`])([^\> ]*?)\\1[^>]*>";
508
+
509
+ if (preg_match_all("/$regexp/siU", $content, $matches2, PREG_SET_ORDER)) {
510
+ foreach ($matches2 as $match) {
511
+ $lowrez[$match[2]] = '';
512
+ }
513
+ }
514
+
515
+ //Remove any rows from this second set that are already in the first set and merge two sets of results
516
+ $images = array_merge($lowrez, $highrez);
517
+ return $images;
518
+ }
519
+
520
+ /**
521
+ * Update all of the images in the posts that have already been imported
522
+ */
523
+ function process_images() {
524
+ $postsprocessed = $this->images_progress;
525
+ if ($postsprocessed == 0) {
526
+ $imagesprocessed = 0;
527
+ $imagesskipped = 0;
528
+ } else {
529
+ $imagesprocessed = $this->images_done;
530
+ $imagesskipped = $this->images_skipped;
531
+ }
532
+
533
+ $batchsize = 20;
534
+
535
+ $loadedposts = get_posts( array(
536
+ 'meta_key' => 'blogger_blog',
537
+ 'meta_value' => $this->host,
538
+ 'posts_per_page' => $batchsize,
539
+ 'offset' => $postsprocessed,
540
+ 'post_status' => array('draft', 'publish', 'future')
541
+ ));
542
+
543
+ //Stop if nothing left
544
+ if (count($loadedposts) == 0) {
545
+ return true;
546
+ }
547
+
548
+ foreach($loadedposts as $importedpost) {
549
+
550
+ $importedcontent = $importedpost->post_content;
551
+ $author = get_post_meta($importedpost->ID, 'blogger_author', true);
552
+
553
+ $img_count = 0; //Count of images for this post
554
+ foreach($this->get_images($importedcontent) as $lowrez => $highrez) {
555
+ if (!$this->image_filter($lowrez)) {
556
+ //Pass null for description so that the default (filename) is used, might be good to use Alt tag instead?
557
+ $newcontent = $this->import_image($importedpost->ID, $lowrez, $highrez, null, $img_count, $importedcontent, $this->host, $author);
558
+ if (!is_wp_error($newcontent)) {
559
+ $importedcontent = $newcontent;
560
+ $img_count++;
561
+ } else {
562
+ $imagesskipped++;
563
+ }
564
+ }
565
+ }
566
+ $imagesprocessed += $img_count;
567
+
568
+ $importedpost->post_content = $importedcontent;
569
+ wp_update_post($importedpost);
570
+ $postsprocessed++;
571
+
572
+ $this->images_done = $imagesprocessed;
573
+ $this->images_progress = $postsprocessed;
574
+ $this->images_skipped = $imagesskipped;
575
+ }
576
+ unset($loadedposts);
577
+ return;
578
+ }
579
+
580
+ function image_urlremap($url, $large) {
581
+ /* Fix problem urls
582
+ e.g. change https://lh4.googleusercontent.com/-nt66qhxzDyY/TZOD-RhTYMI/AAAAAAAACd4/Elzm1smRFb4/s800-h/Ski%2520Trip.jpg to
583
+ to https://lh4.googleusercontent.com/-nt66qhxzDyY/TZOD-RhTYMI/AAAAAAAACd4/Elzm1smRFb4/s800/Ski%2520Trip.jpg
584
+ Could use a apply_filter here to allow users to add their own tweeks
585
+ */
586
+ $pattern = '/(\/)(s\d*)-h(\/)/i';
587
+ $replacement = '$1$2$3';
588
+ $img = preg_replace($pattern, $replacement, $url);
589
+
590
+ /* Strip out ? and # on the end of files */
591
+ $pattern = '/(.*)[#\?].*/i';
592
+ $replacement = '$1';
593
+ $img = preg_replace($pattern, $replacement, $img);
594
+
595
+ if ($large) {
596
+ // For images on blogger we can swap /sXXX/ with for example /s1600/ to get a larger file.
597
+ // Use a standardised large size so we can control quality vs filesize.
598
+ $pattern = '/(\/)(s\d*)(\/)/i';
599
+ $replacement = '$1s'.Blogger_Importer::LARGE_IMAGE_SIZE.
600
+ '$3';
601
+ $img = preg_replace($pattern, $replacement, $img);
602
+ }
603
+ return $img;
604
+ }
605
+
606
+ function image_filter($url) {
607
+ // Do we exclude this particular image?
608
+ // Don't include images that are already loaded onto this site
609
+ // Could use a apply_filter here to allow users to add their own tweeks
610
+ return (substr($url, 0, strlen(site_url())) == site_url());
611
+ }
612
+
613
+ function import_image($post_id, $lowrez, $highrez, $description, $imgcount, $postcontent, $blogname, $author) {
614
+ /* Import a new image unless we specifically filter it out or if it has already been downloaded on another page.
615
+ Based on http://wordpress.stackexchange.com/questions//media-sideload-image-file-name and the tumblr-importer
616
+ Simple filename cleaning as characters such as +, % cause issues ref: http://wordpress.org/extend/plugins/uploadplus/
617
+
618
+ It's processing links of a form similar to these as provided by the "get_images" function
619
+ <a href="myhighrezimage.jpg"><img src="mylowrezimage.jpg"></a>
620
+ or
621
+ <img src="mylowrezimage.jpg">
622
+
623
+ If the high resolution (linked) file is not an image then the low resolution version is downloaded.
624
+ */
625
+ $lowrez_old = $lowrez;
626
+ $highrez_old = $highrez;
627
+ $highrezispage = false;
628
+
629
+ $lowrez = $this->image_urlremap($lowrez, false);
630
+ if ($lowrez == '')
631
+ return new WP_Error('Not an image', $message = __('Lowrez not an image', 'blogger-importer'), $data = array($lowrez_old, $highrez_old));
632
+
633
+ if ($highrez != '') {
634
+ $highrez = $this->image_urlremap($highrez, true);
635
+ } else {
636
+ $highrez = $this->image_urlremap($lowrez, true);
637
+ }
638
+
639
+ if (!$att_id = $this->image_exists($lowrez)) {
640
+ //Option to add a timeout to download_url, but don't use the wp_remote_get timeout as that's much shorter than the default here of 300s
641
+ $tmp = @download_url($highrez);
642
+
643
+ if (is_wp_error($tmp)) {
644
+ @unlink($tmp); // clean up, copied this from other examples but how is this supposed to work if $tmp is an error??
645
+ //Don't exit as can still try the small image
646
+ }
647
+
648
+ // If the highrez was not an image then try the lowrex
649
+ if (!$this->is_image($tmp, $highrez)) {
650
+ $highrezispage = true; //That image was not valid
651
+ $tmp = @download_url($lowrez); // Option to add a timeout here
652
+
653
+ if (is_wp_error($tmp)) {
654
+ @unlink($tmp); // clean up
655
+ return $tmp; // output wp_error
656
+ }
657
+
658
+ if (!$this->is_image($tmp, $lowrez)) {
659
+ @unlink($tmp); // clean up None of items are actually images, for example might be a single pixel, deliberately filtered out or a 404 error?
660
+ return new WP_Error('No Images', __('None of the images are valid', 'blogger-importer'), $data = array($lowrez_old, $highrez_old));
661
+ }
662
+ }
663
+
664
+ $new_name = preg_replace('/[^A-Za-z0-9._ ]/i', '-', basename($lowrez));
665
+
666
+ $file_array = array('name' => $new_name, 'tmp_name' => $tmp);
667
+
668
+ if ( empty( $description ) ) {
669
+ $description = $new_name;
670
+ }
671
+
672
+ $att_id = media_handle_sideload($file_array, $post_id, $description);
673
+ if (is_wp_error($att_id)) {
674
+ @unlink($file_array['tmp_name']);
675
+ return $att_id;
676
+ }
677
+
678
+ // Link attachment upto old url, store the author so we can replace it later
679
+ add_post_meta($att_id, 'blogger_permalink', $lowrez);
680
+ add_post_meta($att_id, 'blogger_blog', $blogname, true);
681
+ add_post_meta($att_id, 'blogger_author', $author, true);
682
+
683
+ if ($highrezispage) //Not an image so store so we can link later
684
+ add_post_meta($att_id, 'blogger_largeimgispage', true);
685
+
686
+ } else {
687
+ //Image already exists, check if the high rez one was valid last time
688
+ $tmp = get_post_meta($att_id, 'blogger_largeimgispage', true);
689
+ if ($tmp == true)
690
+ $highrezispage = true;
691
+ }
692
+
693
+ //Always treat picassa webs as image so they get replaced with the new High rez link
694
+ if (substr($highrez, 0, 27) == 'http://picasaweb.google.com')
695
+ $highrezispage = false;
696
+
697
+ //Replace the image strings
698
+ if (!$highrezispage && $highrez_old != '') {
699
+ $imagesrc = wp_get_attachment_image_src($att_id, 'full');
700
+ $highrez_new = reset($imagesrc);
701
+ $postcontent = str_replace($highrez_old, $highrez_new, $postcontent);
702
+ }
703
+ $imagesrc = wp_get_attachment_image_src($att_id, 'medium');
704
+ $lowrez_new = reset($imagesrc);
705
+ $postcontent = str_replace($lowrez_old, $lowrez_new, $postcontent);
706
+
707
+ //Set the first image to be the post thumbnail (zero index)
708
+ if ($imgcount == 0) {
709
+ set_post_thumbnail($post_id, $att_id);
710
+ }
711
+
712
+ //media handle sideload moves the file so there should be no temp file left but cleanup just incase.
713
+ @unlink($tmp);
714
+
715
+ // incase something goes wrong
716
+ if ($postcontent == '') {
717
+ return new WP_Error('Empty Content', __("Attempting to write back empty content", 'blogger-importer'), $data = array($lowrez_old, $highrez_old));
718
+ }
719
+ return $postcontent;
720
+ }
721
+
722
+ function is_image($file, $filename) {
723
+ //Is the downloaded file really an image
724
+ //e.g. it looked like an image from the URL but when downloaded it was something else perhaps a html page
725
+ //Also filter out tracking images of 1 pixel square
726
+ //Found that wp_check_filetype_and_ext and wp_match_mime_types was giving false positives
727
+ $imgstats = @getimagesize($file);
728
+ if (!$imgstats) {
729
+ return false;
730
+ }
731
+
732
+ return (($imgstats[0] > 1) && ($imgstats[1] > 1));
733
+ }
734
+
735
+ function image_exists($lowrez) {
736
+ global $wpdb;
737
+ return $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts p INNER JOIN $wpdb->postmeta m ON p.ID = m.post_id AND meta_key = 'blogger_permalink' WHERE post_type = 'attachment' AND meta_value = %s LIMIT 0 , 1",
738
+ $lowrez));
739
+ }
740
+
741
+ function process_links() {
742
+ //Update all of the links in the blog
743
+ global $wpdb;
744
+
745
+ $postsprocessed = $this->links_progress;
746
+ if ($postsprocessed == 0) {
747
+ $linksprocessed = 0;
748
+ } else {
749
+ $linksprocessed = $this->links_done;
750
+ }
751
+ $batchsize = 20;
752
+
753
+ $oldurlsearch = $this->host;
754
+
755
+ if (substr($oldurlsearch, 0, 3) == 'www.') {
756
+ $oldurlsearch = substr($oldurlsearch, 3, strlen($oldurlsearch - 3));
757
+ }
758
+
759
+ $oldurlsearch = str_replace('.', '\.', $oldurlsearch);
760
+
761
+ $blogspot = stripos($oldurlsearch, '\.blogspot\.');
762
+ if ($blogspot) { //Blogspot addresses can be international e.g. myblog.blogspot.com, myblog.blogspot.com.au or myblog.blogspot.co.uk or myblog.blogspot.de both resolve to the same blog.
763
+ //See http://www.searchenginejournal.com/google-blogger-url-censorship/39724/
764
+ $oldurlsearch = substr($oldurlsearch, 0, $blogspot + 12).
765
+ '[\w\.]{2,6}';
766
+ }
767
+
768
+ $loadedposts = get_posts(array('meta_key' => 'blogger_blog', 'meta_value' => $this->host, 'posts_per_page' => $batchsize, 'offset' => $postsprocessed, 'post_status' => array('draft', 'publish', 'future')));
769
+
770
+ //Stop if nothing left
771
+ if (count($loadedposts) == 0) {
772
+ return true;
773
+ }
774
+
775
+ foreach($loadedposts as $importedpost) {
776
+ $importedcontent = $importedpost->post_content;
777
+
778
+ $regexp = '<a\s[^>]*href=([\"\'`])(https?:\/\/(?:www\.)*'.$oldurlsearch.'\/)([^\" >]*?)\1[^>]*>(.*)<\/a>';
779
+ if (preg_match_all("/$regexp/siU", $importedcontent, $matches, PREG_SET_ORDER)) {
780
+ foreach($matches as $match) {
781
+ $HostURL = substr($match[2], 0, strlen($match[2]) - 1); //e.g. http://minitemp.blogspot.co.uk
782
+ $PageURL = '/'.$match[3]; //e.g. '/2011/04/what-happens-if-blog-title-is-really.html'
783
+ $sql = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta m
784
+ inner join $wpdb->posts p on p.id = m.post_id and post_type = 'post'
785
+ where meta_key = '%s'
786
+ and meta_value = '%s'
787
+ ", 'blogger_permalink', $PageURL);
788
+
789
+ $linkpostid = $wpdb->get_var($sql);
790
+
791
+ if ($linkpostid != 0) {
792
+ $NewURL = get_permalink($linkpostid);
793
+ } else { // Page not found, update content with just the new domain
794
+ $NewURL = site_url($PageURL);
795
+ }
796
+
797
+ $importedcontent = str_replace($HostURL.$PageURL, $NewURL, $importedcontent); $linksprocessed++;
798
+ }
799
+
800
+ if ($importedcontent == '') {
801
+ return new WP_Error('Empty Content', __("Attempting to write back empty content"));
802
+ }
803
+
804
+ $importedpost->post_content = $importedcontent;
805
+ wp_update_post($importedpost);
806
+
807
+ }
808
+ $postsprocessed++;
809
+
810
+ //For some reason the intermediate values are not getting written, is it that the options are cached hence not read back?
811
+ $this->links_done = $linksprocessed;
812
+ $this->links_progress = $postsprocessed;
813
+ }
814
+ unset($loadedposts);
815
+ return;
816
+ }
817
+
818
+ function isurlimage($srcurl) {
819
+ //Process picasaweb links and files that are images
820
+ if (substr($srcurl, 0, 27) == 'http://picasaweb.google.com')
821
+ return true;
822
+ return preg_match('/(?i)\.(jpe?g|png|gif|bmp)$/i', $srcurl);
823
+ }
824
+ /**
825
+ * Parse the atom file
826
+ *
827
+ * @param string $file Path to XML file for parsing
828
+ * @return SimplePie object of the feed
829
+ */
830
+ function parse( $file ) {
831
+ $data = file_get_contents( $file );
832
+ // parse the feed
833
+ $feed = new SimplePie();
834
+ //set_xxxx methods depreciated (and not working?) replaced with get_registry as per docs
835
+ $reg = $feed->get_registry();
836
+ $reg->register('Sanitize', 'Blogger_Importer_Sanitize');
837
+ $feed->sanitize = $reg->create('Sanitize'); //Should not really need to do this but there seems to be an issue with the SimplePie class?
838
+ $reg->register('Item', 'WP_SimplePie_Blog_Item');
839
+ $feed->set_raw_data( $data );
840
+ $feed->init();
841
+ return $feed;
842
+ }
843
+
844
+ // Display import page title
845
+ function header() {
846
+ echo '<div class="wrap">';
847
+ screen_icon();
848
+ echo '<h2>' . __( 'Import Blogger', 'blogger-importer' ) . '</h2>';
849
+ }
850
+
851
+ // Close div.wrap
852
+ function footer() {
853
+ echo '</div>';
854
+ }
855
+
856
+ /**
857
+ * Display introductory text and file upload form
858
+ */
859
+ function greet() {
860
+ echo '<div class="narrow">';
861
+ echo '<p>'.__( 'Howdy! Upload your Blogger Exported XML file and we&#8217;ll import the contents from it into this site.', 'blogger-importer' ).'</p>';
862
+ echo '<p>'.__( 'Choose an XML file to upload, then click Upload file and import.', 'blogger-importer' ).'</p>';
863
+ wp_import_upload_form( 'admin.php?import=blogger&amp;step=1' );
864
+ echo '</div>';
865
+ }
866
+
867
+ /**
868
+ * Decide if the given meta key maps to information we will want to import
869
+ *
870
+ * @param string $key The meta key to check
871
+ * @return string|bool The key if we do want to import, false if not
872
+ */
873
+ function is_valid_meta_key( $key ) {
874
+ // skip attachment metadata since we'll regenerate it from scratch
875
+ // skip _edit_lock as not relevant for import
876
+ if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock' ) ) )
877
+ return false;
878
+ return $key;
879
+ }
880
+
881
+ /**
882
+ * Decide whether or not the importer is allowed to create users.
883
+ * Default is true, can be filtered via import_allow_create_users
884
+ *
885
+ * @return bool True if creating users is allowed
886
+ */
887
+ function allow_create_users() {
888
+ return apply_filters( 'import_allow_create_users', true );
889
+ }
890
+
891
+ /**
892
+ * Added to http_request_timeout filter to force timeout at 60 seconds during import
893
+ * @return int 60
894
+ */
895
+ function bump_request_timeout( $val ) {
896
+ return 60;
897
+ }
898
+
899
+ // return the difference in length between two strings
900
+ function cmpr_strlen( $a, $b ) {
901
+ return strlen($b) - strlen($a);
902
+ }
903
+ }
904
+
905
+ } // class_exists( 'Blogger_Importer' )
906
+
907
+ function blogger_importer_init() {
908
+ load_plugin_textdomain( 'blogger-importer', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
909
+
910
+ /**
911
+ * WordPress Importer object for registering the import callback
912
+ * @global WP_Import $wp_import
913
+ */
914
+ $GLOBALS['wp_import'] = new Blogger_Importer();
915
+ register_importer('blogger', __('Blogger', 'blogger-importer'), __('Import posts, comments, and categories from a Blogger blog and migrate authors to WordPress users.', 'blogger-importer'), array( $GLOBALS['wp_import'], 'dispatch' ) );
916
+ }
917
+ add_action( 'admin_init', 'blogger_importer_init' );
comment-entry.php CHANGED
@@ -1,9 +1,6 @@
1
  <?php
2
-
3
  /**
4
- * @author Andy Clark
5
- * @copyright 2013
6
- * A data object representing the data to be added into Wordpress
7
  * 10/3/2014 Added errorhandling to cope with comments that don't link to a post
8
  */
9
 
1
  <?php
 
2
  /**
3
+ * A data object representing the data to be added into WordPress
 
 
4
  * 10/3/2014 Added errorhandling to cope with comments that don't link to a post
5
  */
6
 
languages/blogger-importer-el.mo DELETED
Binary file
languages/blogger-importer-el.po DELETED
@@ -1,371 +0,0 @@
1
- # Translation of the WordPress plugin Blogger Importer 0.2 by wordpressdotorg.
2
- # Copyright (C) 2010 wordpressdotorg
3
- # This file is distributed under the same license as the Blogger Importer package.
4
- # FIRST AUTHOR <EMAIL@ADDRESS>, 2010.
5
- #
6
- msgid ""
7
- msgstr ""
8
- "Project-Id-Version: Blogger Importer 0.2\n"
9
- "Report-Msgid-Bugs-To: \n"
10
- "POT-Creation-Date: 2013-10-29 12:10-0000\n"
11
- "PO-Revision-Date: 2013-10-29 15:45+0200\n"
12
- "Last-Translator: Stergatu Lena <stergatu@cti.gr>\n"
13
- "Language-Team: \n"
14
- "Language: el_GR\n"
15
- "MIME-Version: 1.0\n"
16
- "Content-Type: text/plain; charset=UTF-8\n"
17
- "Content-Transfer-Encoding: 8bit\n"
18
- "X-Poedit-SourceCharset: utf-8\n"
19
- "X-Generator: Poedit 1.5.7\n"
20
-
21
- #: ../blogger-importer-blog.php:462 ../blogger-importer-blog.php:787
22
- msgid "Attempting to write back empty content"
23
- msgstr "Προσπάθειας εγγραφής κενού περιεχομένου"
24
-
25
- #: ../blogger-importer-blog.php:502 ../blogger-importer-blog.php:505
26
- #: ../blogger-importer-table.php:55 ../blogger-importer-table.php:59
27
- #, php-format
28
- msgid "%d of %d"
29
- msgstr "%d από %d"
30
-
31
- #: ../blogger-importer-blog.php:503
32
- #, php-format
33
- msgid "%d posts skipped"
34
- msgstr "%d άρθρα αγνοήθηκαν"
35
-
36
- #: ../blogger-importer-blog.php:506
37
- #, php-format
38
- msgid "%d comments skipped"
39
- msgstr "%d σχόλια αγνοήθηκαν"
40
-
41
- #: ../blogger-importer-blog.php:508
42
- #, php-format
43
- msgid "%d images skipped"
44
- msgstr "%d εικόνες αγνοήθηκαν"
45
-
46
- #: ../blogger-importer-blog.php:695
47
- msgid "Lowrez not an image"
48
- msgstr "Lowrez δεν είναι εικόνα"
49
-
50
- #: ../blogger-importer-blog.php:731
51
- msgid "None of the images are valid"
52
- msgstr "Καμία από τις εικόνες δεν είναι έγκυρη"
53
-
54
- #: ../blogger-importer-table.php:19
55
- msgid "Blog Name"
56
- msgstr "Όνομα Ιστολογίου"
57
-
58
- #: ../blogger-importer-table.php:20
59
- msgid "Blog URL"
60
- msgstr "URL Ιστολογίου"
61
-
62
- #: ../blogger-importer-table.php:21
63
- msgid "Posts"
64
- msgstr "Άρθρα"
65
-
66
- #: ../blogger-importer-table.php:22
67
- msgid "Comments"
68
- msgstr "Σχόλια"
69
-
70
- #: ../blogger-importer-table.php:23
71
- msgid "Images"
72
- msgstr "Εικόνες"
73
-
74
- #: ../blogger-importer-table.php:24
75
- msgid "Links"
76
- msgstr "Σύνδεσμοι"
77
-
78
- #: ../blogger-importer-table.php:25
79
- msgid "Action Button"
80
- msgstr "Κουμπί ενέργειας"
81
-
82
- #: ../blogger-importer-table.php:71
83
- msgid "Import"
84
- msgstr "Εισαγωγή"
85
-
86
- #: ../blogger-importer-table.php:72 ../blogger-importer.php:84
87
- msgid "Continue"
88
- msgstr "Συνέχεια"
89
-
90
- #: ../blogger-importer-table.php:73 ../blogger-importer.php:84
91
- msgid "Importing..."
92
- msgstr "Εισαγωγή…"
93
-
94
- #: ../blogger-importer-table.php:74 ../blogger-importer.php:85
95
- msgid "Set Authors"
96
- msgstr "Ορισμός συντακτών"
97
-
98
- #: ../blogger-importer.php:77
99
- msgid "Blogger"
100
- msgstr "Blogger"
101
-
102
- #: ../blogger-importer.php:77
103
- msgid ""
104
- "Import categories, posts, images and comments then maps users from a Blogger "
105
- "blog."
106
- msgstr ""
107
- "Εισαγωγή κατηγοριών, άρθρων, εικόνων και σχολίων και στην συνέχεια "
108
- "αντιστοίχιση μελών από ιστολόγιο Blogger."
109
-
110
- #: ../blogger-importer.php:85
111
- msgid "Nothing was imported. Had you already imported this blog?"
112
- msgstr "Δεν εισήχθη τίποτα. Μήπως είχατε εισάγει ήδη το ιστολόγιο;"
113
-
114
- #: ../blogger-importer.php:85
115
- msgid "Preparing author mapping form..."
116
- msgstr "Προετοιμασία χάρτη συντακτών…"
117
-
118
- #: ../blogger-importer.php:86
119
- msgid "Final Step: Author Mapping"
120
- msgstr "Τελευταίο βήμα: Χάρτης συντακτών"
121
-
122
- #: ../blogger-importer.php:99
123
- msgid "Import Blogger"
124
- msgstr "Εισαγωγή Blogger"
125
-
126
- #: ../blogger-importer.php:100
127
- msgid ""
128
- "Howdy! This importer allows you to import posts and comments from your "
129
- "Blogger account into your WordPress site."
130
- msgstr ""
131
- "Καλώς ήρθατε! Ο εισαγωγέας αυτός είναι για να εισάγετε άρθρα και σχόλια από "
132
- "λογαριασμό Blogger σε ένα ιστολόγιο WordPress."
133
-
134
- #: ../blogger-importer.php:101
135
- msgid ""
136
- "To use this importer, you must have a Google account and an upgraded (New, "
137
- "was Beta) blog hosted on blogspot.com or a custom domain (not FTP)."
138
- msgstr ""
139
- "Για να χρησιμοποιήσετε τον εισαγωγέα, πρέπει να έχετε λογαριασμό Google και "
140
- "αναβαθμισμένο ιστολόγιο στο blogspot.com ή σε δικό σας όνομα (όχι FTP)."
141
-
142
- #: ../blogger-importer.php:102
143
- msgid ""
144
- "The first thing you need to do is tell Blogger to let WordPress access your "
145
- "account. You will be sent back here after providing authorization."
146
- msgstr ""
147
- "Καταρχάς, πρέπει να πείτε στο Blogger να δώσει πρόσβαση στον λογαριασμό του "
148
- "WordPress. Αφού δώσετε την έγκριση, θα επιστρέψετε αυτόματα εδώ."
149
-
150
- #: ../blogger-importer.php:104
151
- msgid "Error occurred getting OAuth tokens from Google"
152
- msgstr "Σφάλμα ανάκτησης OAuth tokens από την Google"
153
-
154
- #: ../blogger-importer.php:142
155
- msgid ""
156
- "OpenSSL is not installed check your PHP.INI or ask your server provider to "
157
- "enable the OpenSSL module."
158
- msgstr ""
159
- "Το OpenSSL δεν είναι εγκατεστημένο. Ελέξτε το PHP.INI ή ζητήστε από τον "
160
- "server provider να ενεργοποιήσει το OpenSSL module."
161
-
162
- #: ../blogger-importer.php:175
163
- msgid ""
164
- "Invalid Token: Check server date, firewall settings and transports (curl, "
165
- "streams and fsockopen)"
166
- msgstr ""
167
- "Μη έγκυρο Token: Ελέξτε την ημερομηνία του server, τις ρυθμίσεις firewall "
168
- "και μεταφοράς δεδομένων (curl, streams and fsockopen)"
169
-
170
- #: ../blogger-importer.php:394
171
- #, php-format
172
- msgid ""
173
- "All posts were imported with the current user as author. Use this form to "
174
- "move each Blogger user&#8217;s posts to a different WordPress user. You may "
175
- "<a href=\"%s\">add users</a> and then return to this page and complete the "
176
- "user mapping. This form may be used as many times as you like until you "
177
- "activate the &#8220;Restart&#8221; function below."
178
- msgstr ""
179
- "Όλα τα άρθρα εισήχθησαν με συντάκτη τον τρέχοντα χρήστη. Χρησιμοποιήστε τη "
180
- "φόρμα για να μεταφέρετε τα άρθρα κάθε συντάκτη του Blogger σε διαφορετικό "
181
- "συντάκτη του WordPress. Μπορείτε να <a href=\"%s\">προσθέσετε μέλη</a> και "
182
- "να επιστρέψετε για να ολοκληρώσετε την αναχαρτογράφηση. Μέχρι να "
183
- "ενεργοποιήσετε την «Επανεκκίνηση», γίνεται να χρησιμοποιήσετε τη φόρμα όσες "
184
- "φορές θέλετε."
185
-
186
- #: ../blogger-importer.php:396
187
- msgid "Author mapping"
188
- msgstr "Χάρτης συντακτών"
189
-
190
- #: ../blogger-importer.php:398
191
- msgid "Blogger username"
192
- msgstr "Όνομα χρήστη Blogger"
193
-
194
- #: ../blogger-importer.php:399
195
- msgid "WordPress login"
196
- msgstr "Σύνδεση WordPress"
197
-
198
- #: ../blogger-importer.php:400
199
- msgid "Save Changes"
200
- msgstr "Αποθήκευση αλλαγών"
201
-
202
- #: ../blogger-importer.php:447
203
- msgid "Congratulations!"
204
- msgstr "Συγχαρητήρια!"
205
-
206
- #: ../blogger-importer.php:447
207
- msgid ""
208
- "Now that you have imported your Blogger blog into WordPress, what are you "
209
- "going to do? Here are some suggestions:"
210
- msgstr ""
211
- "Η εισαγωγή του ιστολογίου Blogger στο WordPress τελείωσε. Τι θα κάνετε τώρα; "
212
- "Να μερικές ιδέες:"
213
-
214
- #: ../blogger-importer.php:451
215
- msgid "For security, click the link below to reset this importer."
216
- msgstr "Για λόγους ασφαλείας, κάντε κλικ πιο κάτω να μηδενίσετε τον εισαγωγέα."
217
-
218
- #: ../blogger-importer.php:460
219
- msgid "Review posts"
220
- msgstr "Ανασκόπηση άρθρων"
221
-
222
- #: ../blogger-importer.php:461
223
- msgid "Review categories"
224
- msgstr "Ανασκόπηση ετικετών"
225
-
226
- #: ../blogger-importer.php:462
227
- msgid "Convert categories to tags"
228
- msgstr "Μετατροπή κατηγοριών σε ετικέτες"
229
-
230
- #: ../blogger-importer.php:463
231
- msgid "Review comments"
232
- msgstr "Ανασκόπηση σχολίων"
233
-
234
- #: ../blogger-importer.php:464
235
- msgid "Review media"
236
- msgstr "Ανασκόπηση πολυμέσων"
237
-
238
- #: ../blogger-importer.php:468
239
- msgid ""
240
- "In case you haven&#8217;t done it already, you can import the posts from "
241
- "your other blogs:"
242
- msgstr ""
243
- "Αν δεν το έχετε κάνει ήδη, μπορείτε να εισάγετε άρθρα από άλλα ιστολόγια σας:"
244
-
245
- #: ../blogger-importer.php:469
246
- msgid "Show blogs"
247
- msgstr "Προβολή ιστολογίων"
248
-
249
- #: ../blogger-importer.php:554
250
- msgid "Trouble signing in"
251
- msgstr "Πρόβλημα στη σύνδεση"
252
-
253
- #: ../blogger-importer.php:554
254
- msgid "We were not able to gain access to your account. Try starting over."
255
- msgstr ""
256
- "Δεν ήταν δυνατή η πρόσβαση στον λογαριασμό σας. Δοκιμάστε άλλη μία φορά."
257
-
258
- #: ../blogger-importer.php:557
259
- msgid "No blogs found"
260
- msgstr "Δεν βρέθηκαν ιστολόγια"
261
-
262
- #: ../blogger-importer.php:557
263
- msgid ""
264
- "We were able to log in but there were no blogs. Try a different account next "
265
- "time."
266
- msgstr ""
267
- "Η είσοδος έγινε κανονικά αλλά δεν βρέθηκε ιστολόγιο. Δοκιμάστε έναν άλλο "
268
- "λογαριασμό."
269
-
270
- #: ../blogger-importer.php:568
271
- msgid "Restart"
272
- msgstr "Επανεκκίνηση"
273
-
274
- #: ../blogger-importer.php:569
275
- msgid ""
276
- "We have saved some information about your Blogger account in your WordPress "
277
- "database. Clearing this information will allow you to start over. Restarting "
278
- "will not affect any posts you have already imported. If you attempt to re-"
279
- "import a blog, duplicate posts and comments will be skipped."
280
- msgstr ""
281
- "Αποθηκεύσαμε στη βάση δεδομένων του WordPress κάποια στοιχεία από τον "
282
- "λογαριασμό σας στο Blogger. Η αφαίρεση αυτών των στοιχείων σας επιτρέπει να "
283
- "ξεκινήσετε από την αρχή. Άρθρα που έχουν ήδη εισαχθεί δεν επηρεάζονται. Αν "
284
- "επιχειρήσετε να επανεισάγετε ένα ιστολόγιο, τα ήδη εισηγμένα άρθρα και "
285
- "σχόλια δεν επανεισάγονται."
286
-
287
- #~ msgid "Authorize"
288
- #~ msgstr "Εξουσιοδότηση"
289
-
290
- #~ msgid "Blogger Blogs"
291
- #~ msgstr "Ιστολόγια Blogger"
292
-
293
- #~ msgid "The Magic Button"
294
- #~ msgstr "Το Μαγικό Κουμπί"
295
-
296
- #~ msgid ""
297
- #~ "This feature requires Javascript but it seems to be disabled. Please "
298
- #~ "enable Javascript and then reload this page. Don&#8217;t worry, you can "
299
- #~ "turn it back off when you&#8217;re done."
300
- #~ msgstr ""
301
- #~ "Η λειτουργία αυτή απαιτεί JavaScript, που φαίνεται ότι είναι "
302
- #~ "απενεργοποιημένη. Παρακαλούμε ενεργοποιήστε την JavaScript και ανανεώστε "
303
- #~ "τη σελίδα. (Μόλις τελειώσετε, μπορείτε να απενεργοποιήσετε πάλι την "
304
- #~ "JavaScript.)"
305
-
306
- #~ msgid "That was hard work! Take a break."
307
- #~ msgstr "Ήταν κουραστική εργασία! Κάντε ένα διάλειμμα!"
308
-
309
- #~ msgid ""
310
- #~ "Go to <a href=\"%s\" target=\"%s\">Authors &amp; Users</a>, where you can "
311
- #~ "modify the new user(s) or delete them. If you want to make all of the "
312
- #~ "imported posts yours, you will be given that option when you delete the "
313
- #~ "new authors."
314
- #~ msgstr ""
315
- #~ "Στο <a href=\"%s\" target=\"%s\">Συντάκτες &amp; Μέλη</a> μπορείτε να "
316
- #~ "επεξεργαστείτε νέα μέλη ή να τα διαγράψετε. Αν θέλετε να μεταφέρετε στον "
317
- #~ "δικό σας λογαριασμό όλα τα εισηγμένα άρθρα, σας δίνεται η επιλογή όταν "
318
- #~ "διαγράφετε τους νέους συντάκτες."
319
-
320
- #~ msgid "Clear account information"
321
- #~ msgstr "Καθαρισμός πληροφοριών λογαριασμού"
322
-
323
- #~ msgid "Blogger Importer"
324
- #~ msgstr "Εισαγωγέας Blogger"
325
-
326
- #~ msgid "http://wordpress.org/extend/plugins/blogger-importer/"
327
- #~ msgstr "http://wordpress.org/extend/plugins/blogger-importer/"
328
-
329
- #~ msgid ""
330
- #~ "Import posts, comments and tags from a Blogger blog and migrate authors "
331
- #~ "to WordPress users."
332
- #~ msgstr ""
333
- #~ "Εισαγωγή άρθρων, σχολίων και ετικετών από ιστολόγιο Blogger και στην "
334
- #~ "συνέχεια αντιστοίχιση συντακτών με μέλη του ιστολογίου σας."
335
-
336
- #~ msgid "wordpressdotorg"
337
- #~ msgstr "wordpressdotorg"
338
-
339
- #~ msgid "http://wordpress.org/"
340
- #~ msgstr "http://wordpress.org/"
341
-
342
- #~ msgid "Authorization failed"
343
- #~ msgstr "Εξουσιοδότηση απέτυχε"
344
-
345
- #~ msgid ""
346
- #~ "Something went wrong. If the problem persists, send this info to support:"
347
- #~ msgstr ""
348
- #~ "Κάτι δεν πήγε καλά. Αν επιμείνει το πρόβλημα, στείλτε αυτά τα στοιχεία "
349
- #~ "στην υποστήριξη:"
350
-
351
- #~ msgid "Could not connect to https://www.google.com"
352
- #~ msgstr "Αδύνατη η σύνδεση με https://www.google.com"
353
-
354
- #~ msgid ""
355
- #~ "There was a problem opening a secure connection to Google. This is what "
356
- #~ "went wrong:"
357
- #~ msgstr ""
358
- #~ "Δεν ήταν δυνατή η ασφαλής σύνδεση με το Google. Να τι δεν πήγε καλά:"
359
-
360
- #~ msgid "Could not connect to %s"
361
- #~ msgstr "Αδύνατη η σύνδεση με %s"
362
-
363
- #~ msgid ""
364
- #~ "There was a problem opening a connection to Blogger. This is what went "
365
- #~ "wrong:"
366
- #~ msgstr "Δεν ήταν δυνατή η σύνδεση με το Blogger. Να τι δεν πήγε καλά:"
367
-
368
- #~ msgid "Import posts, comments, tags, and attachments from a Blogger blog."
369
- #~ msgstr ""
370
- #~ "Εγκαταστήστε τον εισαγωγέα Blogger για να εισάγετε άρθρα, σχόλια και μέλη "
371
- #~ "ιστολόγιο Blogger."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
languages/blogger-importer.pot DELETED
@@ -1,292 +0,0 @@
1
- # Copyright (C) 2014 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.8\n"
6
- "Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/blogger-importer\n"
7
- "POT-Creation-Date: 2014-12-20 19:44:23+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: 2014-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-blog.php:447 blogger-importer-blog.php:768
16
- msgid "Attempting to write back empty content"
17
- msgstr ""
18
-
19
- #: blogger-importer-blog.php:487 blogger-importer-blog.php:490
20
- #: blogger-importer-table.php:55 blogger-importer-table.php:59
21
- msgid "%d of %d"
22
- msgstr ""
23
-
24
- #: blogger-importer-blog.php:488
25
- msgid "%d post skipped"
26
- msgid_plural "%d posts skipped"
27
- msgstr[0] ""
28
- msgstr[1] ""
29
-
30
- #: blogger-importer-blog.php:491
31
- msgid "%d comment skipped"
32
- msgid_plural "%d comments skipped"
33
- msgstr[0] ""
34
- msgstr[1] ""
35
-
36
- #: blogger-importer-blog.php:493
37
- msgid "%d image skipped"
38
- msgid_plural "%d images skipped"
39
- msgstr[0] ""
40
- msgstr[1] ""
41
-
42
- #: blogger-importer-blog.php:676
43
- msgid "Lowrez not an image"
44
- msgstr ""
45
-
46
- #: blogger-importer-blog.php:712
47
- msgid "None of the images are valid"
48
- msgstr ""
49
-
50
- #: blogger-importer-connector.php:32
51
- msgid ""
52
- "OpenSSL is not installed check your PHP.INI or ask your server provider to "
53
- "enable the OpenSSL module."
54
- msgstr ""
55
-
56
- #: blogger-importer-connector.php:65
57
- msgid ""
58
- "Invalid Token: Check server date, firewall settings and transports (curl, "
59
- "streams and fsockopen)"
60
- msgstr ""
61
-
62
- #: blogger-importer-connector.php:80
63
- msgid "Authorize"
64
- msgstr ""
65
-
66
- #: blogger-importer-table.php:19
67
- msgid "Blog Name"
68
- msgstr ""
69
-
70
- #: blogger-importer-table.php:20
71
- msgid "Blog URL"
72
- msgstr ""
73
-
74
- #: blogger-importer-table.php:21
75
- msgid "Posts"
76
- msgstr ""
77
-
78
- #: blogger-importer-table.php:22
79
- msgid "Comments"
80
- msgstr ""
81
-
82
- #: blogger-importer-table.php:23
83
- msgid "Images"
84
- msgstr ""
85
-
86
- #: blogger-importer-table.php:24
87
- msgid "Links"
88
- msgstr ""
89
-
90
- #: blogger-importer-table.php:25
91
- msgid "Action Button"
92
- msgstr ""
93
-
94
- #: blogger-importer-table.php:71
95
- msgid "Import"
96
- msgstr ""
97
-
98
- #: blogger-importer-table.php:72 blogger-importer.php:94
99
- msgid "Continue"
100
- msgstr ""
101
-
102
- #: blogger-importer-table.php:73 blogger-importer.php:94
103
- msgid "Importing..."
104
- msgstr ""
105
-
106
- #: blogger-importer-table.php:74 blogger-importer.php:95
107
- msgid "Set Authors"
108
- msgstr ""
109
-
110
- #: blogger-importer.php:87
111
- msgid "Blogger"
112
- msgstr ""
113
-
114
- #: blogger-importer.php:87
115
- msgid ""
116
- "Import categories, posts, images and comments then maps users from a Blogger "
117
- "blog."
118
- msgstr ""
119
-
120
- #: blogger-importer.php:95
121
- msgid "Nothing was imported. Had you already imported this blog?"
122
- msgstr ""
123
-
124
- #: blogger-importer.php:95
125
- msgid "Preparing author mapping form..."
126
- msgstr ""
127
-
128
- #: blogger-importer.php:96
129
- msgid "Final Step: Author Mapping"
130
- msgstr ""
131
-
132
- #: blogger-importer.php:107 blogger-importer.php:207
133
- msgid "Import Blogger"
134
- msgstr ""
135
-
136
- #: blogger-importer.php:108
137
- msgid ""
138
- "Howdy! This importer allows you to import posts and comments from your "
139
- "Blogger account into your WordPress site."
140
- msgstr ""
141
-
142
- #: blogger-importer.php:109
143
- msgid ""
144
- "To use this importer, you must have a Google account and an upgraded (New, "
145
- "was Beta) blog hosted on blogspot.com or a custom domain (not FTP)."
146
- msgstr ""
147
-
148
- #: blogger-importer.php:110
149
- msgid ""
150
- "The first thing you need to do is tell Blogger to let WordPress access your "
151
- "account. You will be sent back here after providing authorization."
152
- msgstr ""
153
-
154
- #: blogger-importer.php:111
155
- msgid "Error occurred getting OAuth tokens from Google"
156
- msgstr ""
157
-
158
- #: blogger-importer.php:205
159
- msgid ""
160
- "This feature requires Javascript but it seems to be disabled. Please enable "
161
- "Javascript and then reload this page. Don&#8217;t worry, you can turn it "
162
- "back off when you&#8217;re done."
163
- msgstr ""
164
-
165
- #: blogger-importer.php:208
166
- msgid "Refresh blog list"
167
- msgstr ""
168
-
169
- #: blogger-importer.php:277
170
- msgid ""
171
- "All posts were imported with the current user as author. Use this form to "
172
- "move each Blogger user&#8217;s posts to a different WordPress user. You may "
173
- "<a href=\"%s\">add users</a> and then return to this page and complete the "
174
- "user mapping. This form may be used as many times as you like until you "
175
- "activate the &#8220;Restart&#8221; function below."
176
- msgstr ""
177
-
178
- #: blogger-importer.php:279
179
- msgid "Author mapping"
180
- msgstr ""
181
-
182
- #: blogger-importer.php:281
183
- msgid "Blogger username"
184
- msgstr ""
185
-
186
- #: blogger-importer.php:282
187
- msgid "WordPress login"
188
- msgstr ""
189
-
190
- #: blogger-importer.php:283
191
- msgid "Save Changes"
192
- msgstr ""
193
-
194
- #: blogger-importer.php:327
195
- msgid "Congratulations!"
196
- msgstr ""
197
-
198
- #: blogger-importer.php:327
199
- msgid ""
200
- "Now that you have imported your Blogger blog into WordPress, what are you "
201
- "going to do? Here are some suggestions:"
202
- msgstr ""
203
-
204
- #: blogger-importer.php:331
205
- msgid "For security, click the link below to reset this importer."
206
- msgstr ""
207
-
208
- #: blogger-importer.php:340
209
- msgid "Review posts"
210
- msgstr ""
211
-
212
- #: blogger-importer.php:341
213
- msgid "Review categories"
214
- msgstr ""
215
-
216
- #: blogger-importer.php:342
217
- msgid "Convert categories to tags"
218
- msgstr ""
219
-
220
- #: blogger-importer.php:343
221
- msgid "Review comments"
222
- msgstr ""
223
-
224
- #: blogger-importer.php:344
225
- msgid "Review media"
226
- msgstr ""
227
-
228
- #: blogger-importer.php:348
229
- msgid ""
230
- "In case you haven&#8217;t done it already, you can import the posts from "
231
- "your other blogs:"
232
- msgstr ""
233
-
234
- #: blogger-importer.php:349
235
- msgid "Show blogs"
236
- msgstr ""
237
-
238
- #: blogger-importer.php:443
239
- msgid "Trouble signing in"
240
- msgstr ""
241
-
242
- #: blogger-importer.php:443
243
- msgid "We were not able to gain access to your account. Try starting over."
244
- msgstr ""
245
-
246
- #: blogger-importer.php:446
247
- msgid "No blogs found"
248
- msgstr ""
249
-
250
- #: blogger-importer.php:446
251
- msgid ""
252
- "We were able to log in but there were no blogs. Try a different account next "
253
- "time."
254
- msgstr ""
255
-
256
- #: blogger-importer.php:459
257
- msgid "Restart"
258
- msgstr ""
259
-
260
- #: blogger-importer.php:460
261
- msgid ""
262
- "We have saved some information about your Blogger account in your WordPress "
263
- "database. Clearing this information will allow you to start over. Restarting "
264
- "will not affect any posts you have already imported. If you attempt to re-"
265
- "import a blog, duplicate posts and comments will be skipped."
266
- msgstr ""
267
-
268
- #: blogger-importer.php:462
269
- msgid "Clear account information"
270
- msgstr ""
271
-
272
- #. Plugin Name of the plugin/theme
273
- msgid "Blogger Importer"
274
- msgstr ""
275
-
276
- #. Plugin URI of the plugin/theme
277
- msgid "http://wordpress.org/extend/plugins/blogger-importer/"
278
- msgstr ""
279
-
280
- #. Description of the plugin/theme
281
- msgid ""
282
- "Imports posts, comments, images and tags from a Blogger blog then migrates "
283
- "authors to WordPress users."
284
- msgstr ""
285
-
286
- #. Author of the plugin/theme
287
- msgid "wordpressdotorg"
288
- msgstr ""
289
-
290
- #. Author URI of the plugin/theme
291
- msgid "http://wordpress.org/"
292
- msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
oauth.php DELETED
@@ -1,930 +0,0 @@
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 sslinstalled() {
778
- return function_exists('openssl_sign');
779
- }
780
-
781
- public static function urlencode_rfc3986($input) {
782
- if (is_array($input)) {
783
- return array_map(array('Blogger_OAuthUtil', 'urlencode_rfc3986'), $input);
784
- } else if (is_scalar($input)) {
785
- return str_replace(
786
- '+',
787
- ' ',
788
- str_replace('%7E', '~', rawurlencode($input))
789
- );
790
- } else {
791
- return '';
792
- }
793
- }
794
-
795
-
796
- // This decode function isn't taking into consideration the above
797
- // modifications to the encoding process. However, this method doesn't
798
- // seem to be used anywhere so leaving it as is.
799
- public static function urldecode_rfc3986($string) {
800
- return urldecode($string);
801
- }
802
-
803
- // Utility function for turning the Authorization: header into
804
- // parameters, has to do some unescaping
805
- // Can filter out any non-oauth parameters if needed (default behaviour)
806
- // May 28th, 2010 - method updated to tjerk.meesters for a speed improvement.
807
- // see http://code.google.com/p/oauth/issues/detail?id=163
808
- public static function split_header($header, $only_allow_oauth_parameters = true) {
809
- $params = array();
810
- if (preg_match_all('/('.($only_allow_oauth_parameters ? 'oauth_' : '').'[a-z_-]*)=(:?"([^"]*)"|([^,]*))/', $header, $matches)) {
811
- foreach ($matches[1] as $i => $h) {
812
- $params[$h] = Blogger_OAuthUtil::urldecode_rfc3986(empty($matches[3][$i]) ? $matches[4][$i] : $matches[3][$i]);
813
- }
814
- if (isset($params['realm'])) {
815
- unset($params['realm']);
816
- }
817
- }
818
- return $params;
819
- }
820
-
821
- // helper to try to sort out headers for people who aren't running apache
822
- public static function get_headers() {
823
- if (function_exists('apache_request_headers')) {
824
- // we need this to get the actual Authorization: header
825
- // because apache tends to tell us it doesn't exist
826
- $headers = apache_request_headers();
827
-
828
- // sanitize the output of apache_request_headers because
829
- // we always want the keys to be Cased-Like-This and arh()
830
- // returns the headers in the same case as they are in the
831
- // request
832
- $out = array();
833
- foreach ($headers AS $key => $value) {
834
- $key = str_replace(
835
- " ",
836
- "-",
837
- ucwords(strtolower(str_replace("-", " ", $key)))
838
- );
839
- $out[$key] = $value;
840
- }
841
- } else {
842
- // otherwise we don't have apache and are just going to have to hope
843
- // that $_SERVER actually contains what we need
844
- $out = array();
845
- if( isset($_SERVER['CONTENT_TYPE']) )
846
- $out['Content-Type'] = $_SERVER['CONTENT_TYPE'];
847
- if( isset($_ENV['CONTENT_TYPE']) )
848
- $out['Content-Type'] = $_ENV['CONTENT_TYPE'];
849
-
850
- foreach ($_SERVER as $key => $value) {
851
- if (substr($key, 0, 5) == "HTTP_") {
852
- // this is chaos, basically it is just there to capitalize the first
853
- // letter of every word that is not an initial HTTP and strip HTTP
854
- // code from przemek
855
- $key = str_replace(
856
- " ",
857
- "-",
858
- ucwords(strtolower(str_replace("_", " ", substr($key, 5))))
859
- );
860
- $out[$key] = $value;
861
- }
862
- }
863
- }
864
- return $out;
865
- }
866
-
867
- // This function takes a input like a=b&a=c&d=e and returns the parsed
868
- // parameters like this
869
- // array('a' => array('b','c'), 'd' => 'e')
870
- public static function parse_parameters( $input ) {
871
- if (!isset($input) || !$input) return array();
872
-
873
- $pairs = explode('&', $input);
874
-
875
- $parsed_parameters = array();
876
- foreach ($pairs as $pair) {
877
- $split = explode('=', $pair, 2);
878
- $parameter = Blogger_OAuthUtil::urldecode_rfc3986($split[0]);
879
- $value = isset($split[1]) ? Blogger_OAuthUtil::urldecode_rfc3986($split[1]) : '';
880
-
881
- if (isset($parsed_parameters[$parameter])) {
882
- // We have already recieved parameter(s) with this name, so add to the list
883
- // of parameters with this name
884
-
885
- if (is_scalar($parsed_parameters[$parameter])) {
886
- // This is the first duplicate, so transform scalar (string) into an array
887
- // so we can add the duplicates
888
- $parsed_parameters[$parameter] = array($parsed_parameters[$parameter]);
889
- }
890
-
891
- $parsed_parameters[$parameter][] = $value;
892
- } else {
893
- $parsed_parameters[$parameter] = $value;
894
- }
895
- }
896
- return $parsed_parameters;
897
- }
898
-
899
- public static function build_http_query($params) {
900
- if (!$params) return '';
901
-
902
- // Urlencode both keys and values
903
- $keys = Blogger_OAuthUtil::urlencode_rfc3986(array_keys($params));
904
- $values = Blogger_OAuthUtil::urlencode_rfc3986(array_values($params));
905
- $params = array_combine($keys, $values);
906
-
907
- // Parameters are sorted by name, using lexicographical byte value ordering.
908
- // Ref: Spec: 9.1.1 (1)
909
- uksort($params, 'strcmp');
910
-
911
- $pairs = array();
912
- foreach ($params as $parameter => $value) {
913
- if (is_array($value)) {
914
- // If two or more parameters share the same name, they are sorted by their value
915
- // Ref: Spec: 9.1.1 (1)
916
- // June 12th, 2010 - changed to sort because of issue 164 by hidetaka
917
- sort($value, SORT_STRING);
918
- foreach ($value as $duplicate_value) {
919
- $pairs[] = $parameter . '=' . $duplicate_value;
920
- }
921
- } else {
922
- $pairs[] = $parameter . '=' . $value;
923
- }
924
- }
925
- // For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
926
- // Each name-value pair is separated by an '&' character (ASCII code 38)
927
- return implode('&', $pairs);
928
- }
929
- }
930
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: wordpressdotorg, Otto42, Workshopshed, SergeyBiryukov, rmccue
3
  Donate link:
4
  Tags: importer, blogger
5
  Requires at least: 3.0
6
- Tested up to: 4.1
7
- Stable tag: 0.7
8
  License: GPLv2 or later
9
 
10
  Imports posts, images, comments, and categories (blogger tags) from a Blogger blog then migrates authors to WordPress users.
@@ -45,24 +45,18 @@ This will ensure that the information transfers across as smoothly as possible a
45
 
46
  = How to use =
47
 
48
- 1. Blogger Importer is available from the WordPress Tools->Import screen.
49
- 1. Press Authorise
50
- 1. If you are not already logged into Google you will be asked to login
51
- 1. You will be asked to grant WordPress access to your Blogger information, to continue press Grant Access
52
- 1. You will be presented with a list of all your blogs
53
- 1. Select the appropriate blog and press the import button
54
- 1. Wait whilst the posts, comments and images are imported
55
- 1. Press the Set Authors button
56
- 1. Select the appropriate mapping for the authors
57
- 1. Review categories, posts and comments
58
-
59
- You can now remove the importer plugin if you no longer need to use it.
60
 
61
  == Frequently Asked Questions ==
62
 
63
  = How do I re-import? =
64
 
65
- From the list of blogs, press refresh blog list, this should update the counts and re-enable the import button. 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.
66
 
67
  = Once I've imported the posts do I need to keep the plugin? =
68
 
@@ -90,11 +84,11 @@ This version of the importer imports these too, but you can disable this via a s
90
 
91
  = What size are the images? =
92
 
93
- The importer will attempt to download the a large version of the file if one is available. This is controlled by the setting "LARGE_IMAGE_SIZE" and defaults to a width of 1024. The display size of the images is the "medium" size of images as defined on Wordpress. You can change this in advance if you want to show a different size.
94
 
95
  = How do I know what images are skipped? =
96
 
97
- If you hover over the progress bar for images it will tell you how many images are skipped. To see the filenames of these images you will need to enable Wordpress debugging to log to file. See http://codex.wordpress.org/Debugging_in_WordPress
98
 
99
  = What about future posts? =
100
 
@@ -108,29 +102,13 @@ No, WordPress and Blogger handle the permalinks differently. However, it is poss
108
 
109
  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. If the php-xml module is not installed then this may result in your entire comment text being stripped out and the error "PHP Warning: DOMDocument not found, unable to use sanitizer" to appear in your logs.
110
 
111
- = The dashboard is reporting that there are 0 comments in blogger =
112
-
113
- This can occur if your blogger blog is set to private.
114
-
115
  = The comments don't have avatars =
116
 
117
- This is a know limitation of the data that is provided from Blogger. The Wordpress system uses Gravatar to provide the images for the comment avatars. This relies the email of the person making the comment. Blogger does not provide the email address in the data feed so Wordpress does not display the correct images. You can manually update or script change to the comment email addresses to work around this issue.
118
-
119
- = How do I diagnose communication issues? =
120
-
121
- If you've got issues with the blogger importer talking to Google then you can use the Core Control plugin to first check that your communication is working with the HTTP Module and if that is all ok then check the HTTP Logging Module to see if any of the remote calls to Google are returning errors. Also the OAuth Playground is a good way to test your access to the blogger data. http://googlecodesamples.com/oauth_playground/
122
-
123
- = I'm getting timeouts connecting to Google =
124
-
125
- Try the core control plugin as mentioned above. Also you try changing the constant REMOTE_TIMEOUT in the blogger-importer.php file to be a larger number of seconds.
126
-
127
- = Why does it keep stopping? =
128
-
129
- The imported is not expect to stop, so this could be to an incompatibility with another plugin, disable any other plugins and see if the problem persists. Also check your error log to see if any error messages have been reported.
130
 
131
  = It does not seem to be processing the images =
132
 
133
- The most common reasons for this are lack of memory and timeouts, these should appear in your error log. Also check you've not run out of disk space on your server. Because Wordpress stores the files in multiple resolutions one image might take up as much as 250kb spread across 5 files of different sizes.
134
 
135
  = How do I make the images bigger or smaller? / My images are fuzzy =
136
 
@@ -148,15 +126,8 @@ If your origional blog has hardcoded width and height values that are larger tha
148
 
149
  The importer is designed to download the high resolution images where they are available. You can either disable the downloading of images or you can change the constant LARGE_IMAGE_SIZE string in the blogger-importer.php file to swap the links with a smaller image.
150
 
151
- == Screenshots ==
152
-
153
- 1. Import in progress
154
- 2. Custom Fields added to Posts, Attachements and Comments
155
-
156
  == Reference ==
157
 
158
- * https://developers.google.com/blogger/docs/1.0/developers_guide_php
159
- * https://developers.google.com/gdata/articles/oauth
160
  * http://www.simplepie.org/
161
 
162
  The following were referenced for implementing the images and links
@@ -175,7 +146,6 @@ The following were referenced for implementing the images and links
175
 
176
  * Some users have reported that their IFrames are stripped out of the post content.
177
  * Requests for better performance of larger transfers and tranfers of images
178
- * Drop the check for OpenSSL and Blogger_OAuthSignatureMethod_RSA_SHA1 is not used by any other code in the plugin and can probably just be removed.
179
  * Review of behavior when it re-imports, partiularly are the counts correct
180
  * Review using get_posts or get_comments with the appropriate parameters to get the counts and exists instead of using SQL
181
  * Incorrect notice, PHP Notice: The data could not be converted to UTF-8. You MUST have either the iconv or mbstring extension installed. This occurs even when Iconv is installed, could be related to Blogger reporting 0 comments
@@ -194,6 +164,9 @@ Filter - blogger_importer_congrats - Passes the list of options shown to the use
194
 
195
  == Changelog ==
196
 
 
 
 
197
  = 0.8 =
198
  * Fixed issue with the authors form not showing a the list of authors for a blog
199
  * Simplified check for duplicate comments
@@ -213,7 +186,7 @@ Filter - blogger_importer_congrats - Passes the list of options shown to the use
213
  * Added setting author on images
214
  * Added error handling in get_oauth_link() as suggested by daniel_henrique ref http://core.trac.wordpress.org/ticket/21163
215
  * Added a check for OpenSSL as suggested by digitalsensus
216
- * Fixed issue with SimplePie santizer not getting set in Wordpress 3.5
217
  * Added filter for the congrats function 'blogger_importer_congrats' so other plugins can add in new options
218
  * Converted manual HTML table to WP_LIST_TABLE
219
  * Moved inline Javascript to separate file to aid debugging and testing
3
  Donate link:
4
  Tags: importer, blogger
5
  Requires at least: 3.0
6
+ Tested up to: 4.3
7
+ Stable tag: 0.9
8
  License: GPLv2 or later
9
 
10
  Imports posts, images, comments, and categories (blogger tags) from a Blogger blog then migrates authors to WordPress users.
45
 
46
  = How to use =
47
 
48
+ 1. On your Blogger account, visit the Settings->Other page, and locate the "Export Blog" option. This will download an XML file containing your posts and comments.
49
+ 2. In WordPress, the Blogger Importer is available from the Tools->Import menu.
50
+ 3. Upload the XML file to WordPress.
51
+ 4. The posts will be read and you will be given the option to map the authors of the posts appropriately.
52
+ 5. Allow the import to finish.
53
+ 6. If the import fails halfway, you can simply retry. Already imported posts will be skipped and not duplicated.
 
 
 
 
 
 
54
 
55
  == Frequently Asked Questions ==
56
 
57
  = How do I re-import? =
58
 
59
+ Simply upload the XML file again. Already imported posts will be skipped and not duplicated.
60
 
61
  = Once I've imported the posts do I need to keep the plugin? =
62
 
84
 
85
  = What size are the images? =
86
 
87
+ The importer will attempt to download the a large version of the file if one is available. This is controlled by the setting "LARGE_IMAGE_SIZE" and defaults to a width of 1024. The display size of the images is the "medium" size of images as defined on WordPress. You can change this in advance if you want to show a different size.
88
 
89
  = How do I know what images are skipped? =
90
 
91
+ If you hover over the progress bar for images it will tell you how many images are skipped. To see the filenames of these images you will need to enable WordPress debugging to log to file. See http://codex.wordpress.org/Debugging_in_WordPress
92
 
93
  = What about future posts? =
94
 
102
 
103
  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. If the php-xml module is not installed then this may result in your entire comment text being stripped out and the error "PHP Warning: DOMDocument not found, unable to use sanitizer" to appear in your logs.
104
 
 
 
 
 
105
  = The comments don't have avatars =
106
 
107
+ This is a known limitation of the data that is provided from Blogger. The WordPress system uses Gravatar to provide the images for the comment avatars. This relies the email of the person making the comment. Blogger does not provide the email address in the data feed so WordPress does not display the correct images. You can manually update or script change to the comment email addresses to work around this issue.
 
 
 
 
 
 
 
 
 
 
 
 
108
 
109
  = It does not seem to be processing the images =
110
 
111
+ The most common reasons for this are lack of memory and timeouts, these should appear in your error log. Also check you've not run out of disk space on your server. Because WordPress stores the files in multiple resolutions one image might take up as much as 250kb spread across 5 files of different sizes.
112
 
113
  = How do I make the images bigger or smaller? / My images are fuzzy =
114
 
126
 
127
  The importer is designed to download the high resolution images where they are available. You can either disable the downloading of images or you can change the constant LARGE_IMAGE_SIZE string in the blogger-importer.php file to swap the links with a smaller image.
128
 
 
 
 
 
 
129
  == Reference ==
130
 
 
 
131
  * http://www.simplepie.org/
132
 
133
  The following were referenced for implementing the images and links
146
 
147
  * Some users have reported that their IFrames are stripped out of the post content.
148
  * Requests for better performance of larger transfers and tranfers of images
 
149
  * Review of behavior when it re-imports, partiularly are the counts correct
150
  * Review using get_posts or get_comments with the appropriate parameters to get the counts and exists instead of using SQL
151
  * Incorrect notice, PHP Notice: The data could not be converted to UTF-8. You MUST have either the iconv or mbstring extension installed. This occurs even when Iconv is installed, could be related to Blogger reporting 0 comments
164
 
165
  == Changelog ==
166
 
167
+ = 0.9 =
168
+ * Complete rewrite to use XML files instead.
169
+
170
  = 0.8 =
171
  * Fixed issue with the authors form not showing a the list of authors for a blog
172
  * Simplified check for duplicate comments
186
  * Added setting author on images
187
  * Added error handling in get_oauth_link() as suggested by daniel_henrique ref http://core.trac.wordpress.org/ticket/21163
188
  * Added a check for OpenSSL as suggested by digitalsensus
189
+ * Fixed issue with SimplePie santizer not getting set in WordPress 3.5
190
  * Added filter for the congrats function 'blogger_importer_congrats' so other plugins can add in new options
191
  * Converted manual HTML table to WP_LIST_TABLE
192
  * Moved inline Javascript to separate file to aid debugging and testing
uninstall.php CHANGED
@@ -1,21 +1,9 @@
1
  <?php
2
-
3
- /**
4
- * @author Andy Clark
5
- * @copyright 2013
6
- *
7
- * Tidy up things left over by the plugin
8
- * Keep this as simple as possible so we don't stall the uninstallation process
9
- */
10
-
11
- delete_option('blogger_importer');
12
- delete_option('blogger_importer_connector');
13
- $blogopt = true;
14
- for ($i = 1; $blogopt ; $i++) {
15
- $blogopt = get_option('blogger_importer_blog_'.$i);
16
- if (is_array($blogopt))
17
- delete_option('blogger_importer_blog_'.$i);
18
- }
19
-
20
-
21
- ?>
1
  <?php
2
+ delete_option('blogger_importer');
3
+ delete_option('blogger_importer_connector');
4
+ $blogopt = true;
5
+ for ($i = 1; $blogopt ; $i++) {
6
+ $blogopt = get_option('blogger_importer_blog_'.$i);
7
+ if (is_array($blogopt))
8
+ delete_option('blogger_importer_blog_'.$i);
9
+ }