Version Description
- Fix callback handling for Tumblr OAuth. They no longer recognize the callback in the authorize URL, and instead expect a non-urlencoded callback parameter in the request-token call. This is not documented anywhere that I can find.
Download this release
Release Info
Developer | Otto42 |
Plugin | Tumblr Importer |
Version | 0.8 |
Comparing to | |
See all releases |
Code changes from version 0.7 to 0.8
- readme.txt +67 -64
- tumblr-importer.php +1033 -1032
readme.txt
CHANGED
@@ -1,64 +1,67 @@
|
|
1 |
-
=== Tumblr Importer ===
|
2 |
-
Contributors: wordpressdotorg, Otto42, dd32, westi, dllh
|
3 |
-
Tags: tumblr, import
|
4 |
-
Requires at least: 3.2
|
5 |
-
Tested up to:
|
6 |
-
Stable tag: 0.
|
7 |
-
License: GPLv2 or later
|
8 |
-
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
-
|
10 |
-
== Description ==
|
11 |
-
|
12 |
-
Imports a Tumblr blog into a WordPress blog.
|
13 |
-
|
14 |
-
* Correctly handles post formats
|
15 |
-
* Background importing: start it up, then come back later to see how far it's gotten
|
16 |
-
* Duplicate checking, will not create duplicate imported posts
|
17 |
-
* Imports posts, drafts, and pages
|
18 |
-
* Media Side loading (for audio, video, and image posts)
|
19 |
-
|
20 |
-
== Installation ==
|
21 |
-
|
22 |
-
1. Upload the files to the `/wp-content/plugins/tumblr-importer/` directory.
|
23 |
-
1. Activate the plugin through the 'Plugins' menu in WordPress.
|
24 |
-
1. Go to Tools->Import and use the new importer.
|
25 |
-
|
26 |
-
== Upgrade Notice ==
|
27 |
-
|
28 |
-
Version 0.
|
29 |
-
|
30 |
-
== Changelog ==
|
31 |
-
|
32 |
-
= 0.
|
33 |
-
*
|
34 |
-
|
35 |
-
= 0.
|
36 |
-
*
|
37 |
-
|
38 |
-
|
39 |
-
*
|
40 |
-
* Improves import
|
41 |
-
*
|
42 |
-
|
43 |
-
|
44 |
-
*
|
45 |
-
|
46 |
-
= 0.
|
47 |
-
*
|
48 |
-
|
49 |
-
|
50 |
-
*
|
51 |
-
|
52 |
-
|
53 |
-
*
|
54 |
-
|
55 |
-
|
56 |
-
*
|
57 |
-
|
58 |
-
|
59 |
-
*
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
*
|
|
|
|
|
|
1 |
+
=== Tumblr Importer ===
|
2 |
+
Contributors: wordpressdotorg, Otto42, dd32, westi, dllh
|
3 |
+
Tags: tumblr, import
|
4 |
+
Requires at least: 3.2
|
5 |
+
Tested up to: 4.1
|
6 |
+
Stable tag: 0.8
|
7 |
+
License: GPLv2 or later
|
8 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
+
|
10 |
+
== Description ==
|
11 |
+
|
12 |
+
Imports a Tumblr blog into a WordPress blog.
|
13 |
+
|
14 |
+
* Correctly handles post formats
|
15 |
+
* Background importing: start it up, then come back later to see how far it's gotten
|
16 |
+
* Duplicate checking, will not create duplicate imported posts
|
17 |
+
* Imports posts, drafts, and pages
|
18 |
+
* Media Side loading (for audio, video, and image posts)
|
19 |
+
|
20 |
+
== Installation ==
|
21 |
+
|
22 |
+
1. Upload the files to the `/wp-content/plugins/tumblr-importer/` directory.
|
23 |
+
1. Activate the plugin through the 'Plugins' menu in WordPress.
|
24 |
+
1. Go to Tools->Import and use the new importer.
|
25 |
+
|
26 |
+
== Upgrade Notice ==
|
27 |
+
|
28 |
+
Version 0.8 fixes a problem with authorization caused by Tumblr's undocumented change to their OAuth handling.
|
29 |
+
|
30 |
+
== Changelog ==
|
31 |
+
|
32 |
+
= 0.8 =
|
33 |
+
* Fix callback handling for Tumblr OAuth. They no longer recognize the callback in the authorize URL, and instead expect a non-urlencoded callback parameter in the request-token call. This is not documented anywhere that I can find.
|
34 |
+
|
35 |
+
= 0.7 =
|
36 |
+
* Update to use new Tumblr API, many fixes and improvements.
|
37 |
+
|
38 |
+
= 0.6 =
|
39 |
+
* Significant improvements in the performance of the importer
|
40 |
+
* Improves import of images from Tumblr - better choice of images sizes for theme display
|
41 |
+
* Improved author selection logic on single author blogs
|
42 |
+
* Auto refreshing to show import progress and give clearer feedback
|
43 |
+
* Improves import videos from Tumble - enable auto-embedding for for content.
|
44 |
+
* Block imports from Tumblr sites with mapped domains enabled because they don't work well - you have to temporarily disable the mapping.
|
45 |
+
|
46 |
+
= 0.5 =
|
47 |
+
* Fix edge cases for tumblr photos where tumblr isn't returning expected headers for filenames
|
48 |
+
|
49 |
+
= 0.4 =
|
50 |
+
* Map multi-image posts to Gallery post format
|
51 |
+
* Import Tags
|
52 |
+
* Import Media to server (Images, Audio, Custom uploaded Video's)
|
53 |
+
* Set the date on Media imports for easier management
|
54 |
+
|
55 |
+
= 0.3 =
|
56 |
+
* Handle multi-image posts
|
57 |
+
* Handle question/answer posts
|
58 |
+
* Handle video posts somewhat better
|
59 |
+
* Speedup (reduce importer delay from 3 minutes to 1 minute)
|
60 |
+
|
61 |
+
= 0.2 =
|
62 |
+
* The audio, video, and image formats no longer use the caption for the titles. Tumblr seems to facilitate putting all sorts of crazy stuff into the caption fields as part of their reblogging system. So instead, these types of posts will have no titles at all. Sorry, but Tumblr simply doesn't have any sort of title fields here to work with, and no data that can be used to "create" a title for them.
|
63 |
+
* Minor debug error cleanup.
|
64 |
+
* Sideloading now done on drafts and pages as well.
|
65 |
+
|
66 |
+
= 0.1 =
|
67 |
+
* First version, not meant to be used except for testing.
|
tumblr-importer.php
CHANGED
@@ -1,1032 +1,1033 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Plugin Name: Tumblr Importer
|
4 |
-
Plugin URI: http://wordpress.org/extend/plugins/tumblr-importer/
|
5 |
-
Description: Import posts from a Tumblr blog.
|
6 |
-
Author: wordpressdotorg
|
7 |
-
Author URI: http://wordpress.org/
|
8 |
-
Version: 0.
|
9 |
-
License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
require_once '
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
*
|
24 |
-
*
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
*
|
41 |
-
*
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
add_filter( '
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
} else if (
|
73 |
-
$this->
|
74 |
-
}
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
$this->
|
82 |
-
}
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
if (
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
<
|
93 |
-
<p
|
94 |
-
<
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
<
|
111 |
-
|
112 |
-
|
113 |
-
<p><?php _e(
|
114 |
-
|
115 |
-
<
|
116 |
-
<
|
117 |
-
<li><?php _e('
|
118 |
-
<li><?php _e('
|
119 |
-
</
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
<
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
<p
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
$this->
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
$
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
"
|
178 |
-
"
|
179 |
-
"
|
180 |
-
"
|
181 |
-
"
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
$
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
<
|
217 |
-
<
|
218 |
-
<p><?php _e('
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
<
|
224 |
-
<
|
225 |
-
<th><?php _e('
|
226 |
-
<th><?php _e('
|
227 |
-
<th><?php _e('
|
228 |
-
|
229 |
-
|
230 |
-
<th><?php _e('
|
231 |
-
<th><?php _e('
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
$
|
237 |
-
|
238 |
-
|
239 |
-
$
|
240 |
-
|
241 |
-
|
242 |
-
$this->blog[$url]['
|
243 |
-
$this->blog[$url]['
|
244 |
-
$this->blog[$url]['
|
245 |
-
$this->blog[$url]['
|
246 |
-
$this->blog[$url]['
|
247 |
-
$this->blog[$url]['
|
248 |
-
$this->blog[$url]['
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
//
|
263 |
-
//
|
264 |
-
|
265 |
-
|
266 |
-
$
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
<
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
<td><?php echo esc_html($blog['
|
286 |
-
<td><?php echo $
|
287 |
-
<td><?php echo $this->blog[$url]['
|
288 |
-
|
289 |
-
|
290 |
-
<td><?php echo $
|
291 |
-
<td><?php echo $
|
292 |
-
|
293 |
-
</
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
</
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
$this->blog[$url]['
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
case '
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
$
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
$this->
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
add_post_meta( $id, 'tumblr_'.$this->blog[$url]['name'].'
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
$this->
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
$
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
$this->
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
$post['
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
add_post_meta( $id, 'tumblr_'.$this->blog[$url]['name'].'
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
$this->
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
$post['
|
524 |
-
$post['
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
$post['
|
530 |
-
$
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
$this->
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
$
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
$
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
$file_array['
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
$post =
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
$
|
611 |
-
$post['post_content']
|
612 |
-
$post['
|
613 |
-
$post =
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
$
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
$post['post_content']
|
651 |
-
$post['
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
$
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
*
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
"
|
686 |
-
"
|
687 |
-
"
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
*
|
700 |
-
*
|
701 |
-
* @param $
|
702 |
-
* @
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
$
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
$blog
|
724 |
-
$blog['
|
725 |
-
$blog['
|
726 |
-
$blog['
|
727 |
-
$blog['
|
728 |
-
$blog['
|
729 |
-
$blog['
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
*
|
744 |
-
*
|
745 |
-
* @param $
|
746 |
-
* @param $
|
747 |
-
* @
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
$
|
752 |
-
$
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
if
|
758 |
-
|
759 |
-
|
760 |
-
'
|
761 |
-
'
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
$
|
779 |
-
|
780 |
-
|
781 |
-
$post
|
782 |
-
$post['
|
783 |
-
$post['
|
784 |
-
$post['
|
785 |
-
$post['
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
$post['
|
798 |
-
$post['media']['
|
799 |
-
$post['media']['
|
800 |
-
$post['media']['
|
801 |
-
$post['
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
'
|
808 |
-
'
|
809 |
-
'
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
$post['
|
817 |
-
$post['post_content']
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
$
|
822 |
-
$
|
823 |
-
$
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
$post['
|
831 |
-
$post['
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
$post['
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
$post['
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
$post['
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
$
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
$
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
$post['
|
881 |
-
|
882 |
-
|
883 |
-
case '
|
884 |
-
|
885 |
-
|
886 |
-
$post['
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
*
|
898 |
-
*
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
$
|
903 |
-
|
904 |
-
'
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
$
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
$page['
|
929 |
-
$page['
|
930 |
-
$
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
*
|
958 |
-
*
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
$
|
978 |
-
|
979 |
-
|
980 |
-
$secret[
|
981 |
-
|
982 |
-
|
983 |
-
$
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
"
|
1011 |
-
"
|
1012 |
-
"
|
1013 |
-
"
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
}
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Tumblr Importer
|
4 |
+
Plugin URI: http://wordpress.org/extend/plugins/tumblr-importer/
|
5 |
+
Description: Import posts from a Tumblr blog.
|
6 |
+
Author: wordpressdotorg
|
7 |
+
Author URI: http://wordpress.org/
|
8 |
+
Version: 0.8
|
9 |
+
License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
10 |
+
Text Domain: tumblr-importer
|
11 |
+
Domain Path: /languages
|
12 |
+
*/
|
13 |
+
|
14 |
+
if ( !defined('WP_LOAD_IMPORTERS') && !defined('DOING_CRON') )
|
15 |
+
return;
|
16 |
+
|
17 |
+
require_once ABSPATH . 'wp-admin/includes/import.php';
|
18 |
+
require_once ABSPATH . 'wp-admin/includes/admin.php';
|
19 |
+
|
20 |
+
require_once 'class-wp-importer-cron.php';
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Tumblr Importer Initialisation routines
|
24 |
+
*
|
25 |
+
* @package WordPress
|
26 |
+
* @subpackage Importer
|
27 |
+
*/
|
28 |
+
function tumblr_importer_init() {
|
29 |
+
global $tumblr_import;
|
30 |
+
load_plugin_textdomain( 'tumblr-importer', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
|
31 |
+
|
32 |
+
$tumblr_import = new Tumblr_Import();
|
33 |
+
register_importer('tumblr', __('Tumblr', 'tumblr-importer'), __('Import posts from a Tumblr blog.', 'tumblr-importer'), array ($tumblr_import, 'start'));
|
34 |
+
if ( !defined('TUMBLR_MAX_IMPORT') )
|
35 |
+
define ('TUMBLR_MAX_IMPORT', 20);
|
36 |
+
}
|
37 |
+
add_action( 'init', 'tumblr_importer_init' );
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Tumblr Importer
|
41 |
+
*
|
42 |
+
* @package WordPress
|
43 |
+
* @subpackage Importer
|
44 |
+
*/
|
45 |
+
if ( class_exists( 'WP_Importer_Cron' ) ) {
|
46 |
+
class Tumblr_Import extends WP_Importer_Cron {
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Constructor
|
50 |
+
*/
|
51 |
+
function __construct() {
|
52 |
+
add_action( 'tumblr_importer_metadata', array( $this, 'tumblr_importer_metadata' ) );
|
53 |
+
add_filter( 'tumblr_importer_format_post', array( $this, 'filter_format_post' ) );
|
54 |
+
add_filter( 'tumblr_importer_get_consumer_key', array( $this, 'get_consumer_key' ) );
|
55 |
+
add_filter( 'wp_insert_post_empty_content', array( $this, 'filter_allow_empty_content' ), 10, 2 );
|
56 |
+
parent::__construct();
|
57 |
+
}
|
58 |
+
|
59 |
+
// Figures out what to do, then does it.
|
60 |
+
function start() {
|
61 |
+
if ( isset($_POST['restart']) )
|
62 |
+
$this->restart();
|
63 |
+
|
64 |
+
if ( !isset($this->error) ) $this->error = null;
|
65 |
+
|
66 |
+
@ $this->consumerkey = defined ('TUMBLR_CONSUMER_KEY') ? TUMBLR_CONSUMER_KEY : ( !empty($_POST['consumerkey']) ? $_POST['consumerkey'] : $this->consumerkey );
|
67 |
+
@ $this->secretkey = defined ('TUMBLR_SECRET_KEY') ? TUMBLR_SECRET_KEY : ( !empty($_POST['secretkey']) ? $_POST['secretkey'] : $this->secretkey );
|
68 |
+
|
69 |
+
// if we have access tokens, verify that they work
|
70 |
+
if ( !empty( $this->access_tokens ) ) {
|
71 |
+
// TODO
|
72 |
+
} else if ( isset( $_GET['oauth_verifier'] ) ) {
|
73 |
+
$this->check_permissions();
|
74 |
+
} else if ( !empty( $this->consumerkey ) && !empty( $this->secretkey ) ) {
|
75 |
+
$this->check_credentials();
|
76 |
+
}
|
77 |
+
if ( isset( $_POST['blogurl'] ) ) {
|
78 |
+
$this->start_blog_import();
|
79 |
+
}
|
80 |
+
if ( isset( $this->blogs ) ) {
|
81 |
+
$this->show_blogs($this->error);
|
82 |
+
} else {
|
83 |
+
$this->greet($this->error);
|
84 |
+
}
|
85 |
+
|
86 |
+
unset ($this->error);
|
87 |
+
|
88 |
+
if ( !isset($_POST['restart']) ) $saved = $this->save_vars();
|
89 |
+
|
90 |
+
if ( $saved && !isset($_GET['noheader']) ) {
|
91 |
+
?>
|
92 |
+
<p><?php _e('We have saved some information about your Tumblr 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 will be skipped.', 'tumblr-importer'); ?></p>
|
93 |
+
<p><?php _e('Note: This will stop any import currently in progress.', 'tumblr-importer'); ?></p>
|
94 |
+
<form method='post' action='?import=tumblr&noheader=true'>
|
95 |
+
<p class='submit' style='text-align:left;'>
|
96 |
+
<input type='submit' class='button' value='<?php esc_attr_e('Clear account information', 'tumblr-importer'); ?>' name='restart' />
|
97 |
+
</p>
|
98 |
+
</form>
|
99 |
+
<?php
|
100 |
+
}
|
101 |
+
}
|
102 |
+
|
103 |
+
function greet($error=null) {
|
104 |
+
|
105 |
+
if ( !empty( $error ) )
|
106 |
+
echo "<div class='error'><p>{$error}</p></div>";
|
107 |
+
?>
|
108 |
+
|
109 |
+
<div class='wrap'><?php echo screen_icon(); ?>
|
110 |
+
<h2><?php _e('Import Tumblr', 'tumblr-importer'); ?></h2>
|
111 |
+
<?php if ( empty($this->request_tokens) ) { ?>
|
112 |
+
<p><?php _e('Howdy! This importer allows you to import posts from your Tumblr account into your WordPress site.', 'tumblr-importer'); ?></p>
|
113 |
+
<p><?php _e("First, you will need to create an 'app' on Tumblr. The app provides a connection point between your blog and Tumblr's servers.", 'tumblr-importer'); ?></p>
|
114 |
+
|
115 |
+
<p><?php _e('To create an app, visit this page:', 'tumblr-importer'); ?><a href="https://www.tumblr.com/oauth/apps">https://www.tumblr.com/oauth/apps</a></p>
|
116 |
+
<ol>
|
117 |
+
<li><?php _e('Click the large green "Register Application" button.','tumblr-importer'); ?></li>
|
118 |
+
<li><?php _e('You need to fill in the "Application Name", "Application Website", and "Default Callback URL" fields. All the rest can be left blank.','tumblr-importer'); ?></li>
|
119 |
+
<li><?php _e('For the "Application Website" and "Default Callback URL" fields, please put in this URL: ','tumblr-importer'); echo '<strong>'.home_url().'</strong>'; ?></li>
|
120 |
+
<li><?php _e('Note: It is important that you put in that URL <em>exactly as given</em>.','tumblr-importer'); ?></li>
|
121 |
+
</ol>
|
122 |
+
|
123 |
+
<p><?php _e('After creating the application, copy and paste the "OAuth Consumer Key" and "Secret Key" into the given fields below.', 'tumblr-importer'); ?></p>
|
124 |
+
|
125 |
+
<form action='?import=tumblr' method='post'>
|
126 |
+
<table class="form-table">
|
127 |
+
<tr>
|
128 |
+
<th scope="row"><label for='consumerkey'><?php _e('OAuth Consumer Key:','tumblr-importer'); ?></label></label></th>
|
129 |
+
<td><input type='text' class="regular-text" name='consumerkey' value='<?php if (isset($this->consumerkey)) echo esc_attr($this->consumerkey); ?>' /></td>
|
130 |
+
</tr>
|
131 |
+
<tr>
|
132 |
+
<th scope="row"><label for='secretkey'><?php _e('Secret Key:','tumblr-importer'); ?></label></label></th>
|
133 |
+
<td><input type='text' class="regular-text" name='secretkey' value='<?php if (isset($this->secretkey)) echo esc_attr($this->secretkey); ?>' /></td>
|
134 |
+
</tr>
|
135 |
+
</table>
|
136 |
+
<p class='submit'>
|
137 |
+
<input type='submit' class='button' value="<?php _e('Connect to Tumblr','tumblr-importer'); ?>" />
|
138 |
+
</p>
|
139 |
+
</form>
|
140 |
+
</div>
|
141 |
+
<?php } else {
|
142 |
+
?>
|
143 |
+
<p><?php _e("Everything seems to be in order, so now you need to tell Tumblr to allow the plugin to access your account.", 'tumblr-importer'); ?></p>
|
144 |
+
<p><?php _e("To do this, click the Authorize link below. You will be redirected back to this page when you've granted the permission.", 'tumblr-importer'); ?></p>
|
145 |
+
|
146 |
+
<p><a href="<?php echo $this->authorize_url; ?>"><?php _e('Authorize the Application','tumblr-importer'); ?></a></p>
|
147 |
+
<?php
|
148 |
+
}
|
149 |
+
}
|
150 |
+
|
151 |
+
function check_credentials() {
|
152 |
+
if ( !( $response = $this->oauth_get_request_token() ) )
|
153 |
+
return;
|
154 |
+
|
155 |
+
if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
|
156 |
+
$this->error = __('Tumblr returned an error: ', 'tumblr-importer') . wp_remote_retrieve_response_code( $response ) .' '. wp_remote_retrieve_body( $response );
|
157 |
+
return;
|
158 |
+
}
|
159 |
+
// parse the body
|
160 |
+
$this->request_tokens = array();
|
161 |
+
wp_parse_str( wp_remote_retrieve_body( $response ), $this->request_tokens);
|
162 |
+
$this->authorize_url = add_query_arg(array(
|
163 |
+
'oauth_token' => $this->request_tokens ['oauth_token'],
|
164 |
+
), 'https://www.tumblr.com/oauth/authorize');
|
165 |
+
|
166 |
+
return;
|
167 |
+
}
|
168 |
+
|
169 |
+
function check_permissions() {
|
170 |
+
$verifier = $_GET['oauth_verifier'];
|
171 |
+
$token = $_GET['oauth_token'];
|
172 |
+
|
173 |
+
// get the access_tokens
|
174 |
+
$url = 'https://www.tumblr.com/oauth/access_token';
|
175 |
+
|
176 |
+
$params = array('oauth_consumer_key' => $this->consumerkey,
|
177 |
+
"oauth_nonce" => time().rand(),
|
178 |
+
"oauth_timestamp" => time(),
|
179 |
+
"oauth_token" => $this->request_tokens['oauth_token'],
|
180 |
+
"oauth_signature_method" => "HMAC-SHA1",
|
181 |
+
"oauth_verifier" => $verifier,
|
182 |
+
"oauth_version" => "1.0",
|
183 |
+
);
|
184 |
+
|
185 |
+
$params['oauth_signature'] = $this->oauth_signature(array($this->secretkey,$this->request_tokens['oauth_token_secret']), 'GET', $url, $params);
|
186 |
+
|
187 |
+
$url = add_query_arg( array_map('urlencode', $params), $url);
|
188 |
+
$response = wp_remote_get( $url );
|
189 |
+
unset($this->request_tokens);
|
190 |
+
if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
|
191 |
+
$this->error = __('Tumblr returned an error: ', 'tumblr-importer') . wp_remote_retrieve_response_code( $response ) .' '. wp_remote_retrieve_body( $response );
|
192 |
+
return;
|
193 |
+
} else {
|
194 |
+
$this->access_tokens = array();
|
195 |
+
wp_parse_str( wp_remote_retrieve_body( $response ), $this->access_tokens);
|
196 |
+
}
|
197 |
+
|
198 |
+
// try to get the list of blogs on the account
|
199 |
+
|
200 |
+
$blogs = $this->get_blogs();
|
201 |
+
if ( is_wp_error ($blogs) ) {
|
202 |
+
$this->error = $blogs->get_error_message();
|
203 |
+
} else {
|
204 |
+
$this->blogs = $blogs;
|
205 |
+
}
|
206 |
+
return;
|
207 |
+
}
|
208 |
+
|
209 |
+
function show_blogs($error=null) {
|
210 |
+
|
211 |
+
if ( !empty( $error ) )
|
212 |
+
echo "<div class='error'><p>{$error}</p></div>";
|
213 |
+
|
214 |
+
$authors = get_users( array('who' => 'authors') );
|
215 |
+
?>
|
216 |
+
<div class='wrap'><?php echo screen_icon(); ?>
|
217 |
+
<h2><?php _e('Import Tumblr', 'tumblr-importer'); ?></h2>
|
218 |
+
<p><?php _e('Please select the Tumblr blog you would like to import into your WordPress site and then click on the "Import this Blog" button to continue.'); ?></p>
|
219 |
+
<p><?php _e('If your import gets stuck for a long time or you would like to import from a different Tumblr account instead then click on the "Clear account information" button below to reset the importer.','tumblr-importer'); ?></p>
|
220 |
+
<?php if ( 1 < count( $authors ) ) : ?>
|
221 |
+
<p><?php _e('As Tumblr does not expose the "author", even from multi-author blogs you will need to select which WordPress user will be listed as the author of the imported posts.','tumblr-importer'); ?></p>
|
222 |
+
<?php endif; ?>
|
223 |
+
<table class="widefat" cellspacing="0"><thead>
|
224 |
+
<tr>
|
225 |
+
<th><?php _e('Tumblr Blog','tumblr-importer'); ?></th>
|
226 |
+
<th><?php _e('URL','tumblr-importer'); ?></th>
|
227 |
+
<th><?php _e('Posts Imported','tumblr-importer'); ?></th>
|
228 |
+
<th><?php _e('Drafts Imported','tumblr-importer'); ?></th>
|
229 |
+
<!--<th><?php _e('Queued Imported','tumblr-importer'); ?></th>-->
|
230 |
+
<th><?php _e('Pages Imported','tumblr-importer'); ?></th>
|
231 |
+
<th><?php _e('Author','tumblr-importer'); ?></th>
|
232 |
+
<th><?php _e('Action/Status','tumblr-importer'); ?></th>
|
233 |
+
</tr></thead>
|
234 |
+
<tbody>
|
235 |
+
<?php
|
236 |
+
$style = '';
|
237 |
+
$custom_domains = false;
|
238 |
+
foreach ($this->blogs as $blog) {
|
239 |
+
$url = $blog['url'];
|
240 |
+
$style = ( 'alternate' == $style ) ? '' : 'alternate';
|
241 |
+
if ( !isset( $this->blog[$url] ) ) {
|
242 |
+
$this->blog[$url]['posts_complete'] = 0;
|
243 |
+
$this->blog[$url]['drafts_complete'] = 0;
|
244 |
+
$this->blog[$url]['queued_complete'] = 0;
|
245 |
+
$this->blog[$url]['pages_complete'] = 0;
|
246 |
+
$this->blog[$url]['total_posts'] = $blog['posts'];
|
247 |
+
$this->blog[$url]['total_drafts'] = $blog['drafts'];
|
248 |
+
$this->blog[$url]['total_queued'] = $blog['queued'];
|
249 |
+
$this->blog[$url]['name'] = $blog['name'];
|
250 |
+
}
|
251 |
+
|
252 |
+
if ( empty( $this->blog[$url]['progress'] ) ) {
|
253 |
+
$submit = "<input type='submit' value='". __('Import this blog','tumblr-importer') ."' />";
|
254 |
+
} else if ( $this->blog[$url]['progress'] == 'finish' ) {
|
255 |
+
$submit = '<img src="' . admin_url( 'images/yes.png' ) . '" style="vertical-align: top; padding: 0 4px;" alt="' . __( 'Finished!', 'tumblr-importer' ) . '" title="' . __( 'Finished!', 'tumblr-importer' ) . '" /><span>' . __( 'Finished!', 'tumblr-importer' ) . '</span>';
|
256 |
+
} else {
|
257 |
+
$submit = '<img src="' . admin_url( 'images/loading.gif' ) . '" style="vertical-align: top; padding: 0 4px;" alt="' . __( 'In Progress', 'tumblr-importer' ) . '" title="' . __( 'In Progress', 'tumblr-importer' ) . '" /><span>' . __( 'In Progress', 'tumblr-importer' ) . '</span>';
|
258 |
+
// Just a little js page reload to show progress if we're in the in-progress phase of the import.
|
259 |
+
$submit .= "<script type='text/javascript'>setTimeout( 'window.location.href = window.location.href', 15000);</script>";
|
260 |
+
}
|
261 |
+
|
262 |
+
// Check to see if this url is a custom domain. The API doesn't play nicely with these
|
263 |
+
// (intermittently returns 408 status), so make the user disable the custom domain
|
264 |
+
// before importing.
|
265 |
+
if ( !preg_match( '|tumblr.com/$|', $url ) ) {
|
266 |
+
$submit = '<nobr><img src="' . admin_url( 'images/no.png' ) . '" style="vertical-align:top; padding: 0 4px;" alt="' . __( 'Tumblr Blogs with Custom Domains activated cannot be imported, please disable the custom domain first.', 'tumblr-importer' ) . '" title="' . __( 'Tumblr Blogs with Custom Domains activated cannot be imported, please disable the custom domain first.', 'tumblr-importer' ) . '" /><span style="cursor: pointer;" title="' . __( 'Tumblr Blogs with Custom Domains activated cannot be imported, please disable the custom domain first.' ) . '">' . __( 'Custom Domain', 'tumblr-importer' ) . '</nobr></span>';
|
267 |
+
$custom_domains = true;
|
268 |
+
}
|
269 |
+
|
270 |
+
// Build an author selector / static name depending on number
|
271 |
+
if ( 1 == count( $authors ) ) {
|
272 |
+
$author_selection = "<input type='hidden' value='{$authors[0]->ID}' name='post_author' />{$authors[0]->display_name}";
|
273 |
+
} else {
|
274 |
+
$args = array('who' => 'authors', 'name' => 'post_author', 'echo' => false );
|
275 |
+
if ( isset( $this->blog[$url]['post_author'] ) )
|
276 |
+
$args['selected'] = $this->blog[$url]['post_author'];
|
277 |
+
$author_selection = wp_dropdown_users( $args );
|
278 |
+
}
|
279 |
+
?>
|
280 |
+
<tr class="<?php echo $style; ?>">
|
281 |
+
<form action='?import=tumblr' method='post'>
|
282 |
+
<?php wp_nonce_field( 'tumblr-import' ); ?>
|
283 |
+
<input type='hidden' name='blogurl' value='<?php echo esc_attr($blog['url']); ?>' />
|
284 |
+
|
285 |
+
<td><?php echo esc_html($blog['title']); ?></td>
|
286 |
+
<td><?php echo esc_html($blog['url']); ?></td>
|
287 |
+
<td><?php echo $this->blog[$url]['posts_complete'] . ' / ' . $this->blog[$url]['total_posts']; ?></td>
|
288 |
+
<td><?php echo $this->blog[$url]['drafts_complete'] . ' / ' . $this->blog[$url]['total_drafts']; ?></td>
|
289 |
+
<!--<td><?php echo $this->blog[$url]['queued_complete']; ?></td>-->
|
290 |
+
<td><?php echo $this->blog[$url]['pages_complete']; ?></td>
|
291 |
+
<td><?php echo $author_selection ?></td>
|
292 |
+
<td><?php echo $submit; ?></td>
|
293 |
+
</form>
|
294 |
+
</tr>
|
295 |
+
<?php
|
296 |
+
}
|
297 |
+
?>
|
298 |
+
</tbody>
|
299 |
+
</table>
|
300 |
+
<?php if ( $custom_domains ) : ?>
|
301 |
+
<p><strong>
|
302 |
+
<?php _e( 'As one or more of your Tumblr blogs has a Custom Domain mapped to it. If you would like to import one of these sites you will need to temporarily remove the custom domain mapping and clear the account information from the importer to import. Once the import is completed you can re-enable the custom domain for your site.' ); ?>
|
303 |
+
</strong></p>
|
304 |
+
<?php endif; ?>
|
305 |
+
<p><?php _e("Importing your Tumblr blog can take a while so the importing process happens in the background and you may not see immediate results here. Come back to this page later to check on the importer's progress.",'tumblr-importer'); ?></p>
|
306 |
+
</div>
|
307 |
+
<?php
|
308 |
+
}
|
309 |
+
|
310 |
+
function start_blog_import() {
|
311 |
+
check_admin_referer( 'tumblr-import' );
|
312 |
+
$url = $_POST['blogurl'];
|
313 |
+
|
314 |
+
if ( !isset( $this->blog[$url] ) ) {
|
315 |
+
$this->error = __('The specified blog cannot be found.', 'tumblr-importer');
|
316 |
+
return;
|
317 |
+
}
|
318 |
+
|
319 |
+
if ( !empty($this->blog[$url]['progress']) ) {
|
320 |
+
$this->error = __('This blog is currently being imported.', 'tumblr-importer');
|
321 |
+
return;
|
322 |
+
}
|
323 |
+
|
324 |
+
$this->blog[$url]['progress'] = 'start';
|
325 |
+
$this->blog[$url]['post_author'] = (int) $_POST['post_author'];
|
326 |
+
|
327 |
+
$this->schedule_import_job( 'do_blog_import', array($url) );
|
328 |
+
}
|
329 |
+
|
330 |
+
function restart() {
|
331 |
+
delete_option(get_class($this));
|
332 |
+
wp_redirect('?import=tumblr');
|
333 |
+
}
|
334 |
+
|
335 |
+
function do_blog_import($url) {
|
336 |
+
|
337 |
+
// default to the done state
|
338 |
+
$done = true;
|
339 |
+
|
340 |
+
$this->error=null;
|
341 |
+
if ( !empty( $this->blog[$url]['progress'] ) ) {
|
342 |
+
$done = false;
|
343 |
+
do {
|
344 |
+
switch ($this->blog[$url]['progress']) {
|
345 |
+
case 'start':
|
346 |
+
case 'posts':
|
347 |
+
$this->do_posts_import($url);
|
348 |
+
break;
|
349 |
+
case 'drafts':
|
350 |
+
$this->do_drafts_import($url);
|
351 |
+
break;
|
352 |
+
case 'queued':
|
353 |
+
// TODO Tumblr's API is broken for queued posts
|
354 |
+
$this->blog[$url]['progress'] = 'pages';
|
355 |
+
//$this->do_queued_import($url);
|
356 |
+
break;
|
357 |
+
case 'pages':
|
358 |
+
// TODO Tumblr's new API has no way to retrieve pages that I can find
|
359 |
+
$this->blog[$url]['progress'] = 'finish';
|
360 |
+
//$this->do_pages_import($url);
|
361 |
+
break;
|
362 |
+
case 'finish':
|
363 |
+
default:
|
364 |
+
$done = true;
|
365 |
+
break;
|
366 |
+
}
|
367 |
+
$this->save_vars();
|
368 |
+
} while ( empty($this->error) && !$done && $this->have_time() );
|
369 |
+
}
|
370 |
+
|
371 |
+
return $done;
|
372 |
+
}
|
373 |
+
|
374 |
+
function do_posts_import($url) {
|
375 |
+
$start = $this->blog[$url]['posts_complete'];
|
376 |
+
$total = $this->blog[$url]['total_posts'];
|
377 |
+
|
378 |
+
// check for posts completion
|
379 |
+
if ( $start >= $total ) {
|
380 |
+
$this->blog[$url]['progress'] = 'drafts';
|
381 |
+
return;
|
382 |
+
}
|
383 |
+
|
384 |
+
// get the already imported posts to prevent dupes
|
385 |
+
$dupes = $this->get_imported_posts( 'tumblr', $this->blog[$url]['name'] );
|
386 |
+
|
387 |
+
if ($this->blog[$url]['posts_complete'] + TUMBLR_MAX_IMPORT > $total) $count = $total - $start;
|
388 |
+
else $count = TUMBLR_MAX_IMPORT;
|
389 |
+
|
390 |
+
$imported_posts = $this->fetch_posts($url, $start, $count, $this->email, $this->password );
|
391 |
+
|
392 |
+
if ( false === $imported_posts ) {
|
393 |
+
$this->error = __('Problem communicating with Tumblr, retrying later','tumblr-importer');
|
394 |
+
return;
|
395 |
+
}
|
396 |
+
|
397 |
+
if ( is_array($imported_posts) && !empty($imported_posts) ) {
|
398 |
+
reset($imported_posts);
|
399 |
+
$post = current($imported_posts);
|
400 |
+
do {
|
401 |
+
// skip dupes
|
402 |
+
if ( !empty( $dupes[$post['tumblr_url']] ) ) {
|
403 |
+
$this->blog[$url]['posts_complete']++;
|
404 |
+
$this->save_vars();
|
405 |
+
continue;
|
406 |
+
}
|
407 |
+
|
408 |
+
if ( isset( $post['private'] ) ) $post['post_status'] = 'private';
|
409 |
+
else $post['post_status']='publish';
|
410 |
+
|
411 |
+
$post['post_author'] = $this->blog[$url]['post_author'];
|
412 |
+
|
413 |
+
do_action( 'tumblr_importing_post', $post );
|
414 |
+
$id = wp_insert_post( $post );
|
415 |
+
|
416 |
+
if ( !is_wp_error( $id ) ) {
|
417 |
+
$post['ID'] = $id; // Allows for the media importing to wp_update_post()
|
418 |
+
if ( isset( $post['format'] ) ) set_post_format($id, $post['format']);
|
419 |
+
|
420 |
+
// @todo: Add basename of the permalink as a 404 redirect handler for when a custom domain has been brought accross
|
421 |
+
add_post_meta( $id, 'tumblr_'.$this->blog[$url]['name'].'_permalink', $post['tumblr_url'] );
|
422 |
+
add_post_meta( $id, 'tumblr_'.$this->blog[$url]['name'].'_id', $post['tumblr_id'] );
|
423 |
+
|
424 |
+
$import_result = $this->handle_sideload($post);
|
425 |
+
|
426 |
+
// Handle failed imports.. If empty content and failed to import media..
|
427 |
+
if ( is_wp_error($import_result) ) {
|
428 |
+
if ( empty($post['post_content']) ) {
|
429 |
+
wp_delete_post($id, true);
|
430 |
+
}
|
431 |
+
}
|
432 |
+
}
|
433 |
+
|
434 |
+
$this->blog[$url]['posts_complete']++;
|
435 |
+
$this->save_vars();
|
436 |
+
|
437 |
+
} while ( false != ($post = next($imported_posts) ) && $this->have_time() );
|
438 |
+
}
|
439 |
+
}
|
440 |
+
|
441 |
+
function get_draft_post_type( $post_type ) {
|
442 |
+
return 'draft';
|
443 |
+
}
|
444 |
+
|
445 |
+
function do_drafts_import($url) {
|
446 |
+
$start = $this->blog[$url]['drafts_complete'];
|
447 |
+
$total = $this->blog[$url]['total_drafts'];
|
448 |
+
|
449 |
+
// check for posts completion
|
450 |
+
if ( $start >= $total ) {
|
451 |
+
$this->blog[$url]['progress'] = 'queued';
|
452 |
+
return;
|
453 |
+
}
|
454 |
+
|
455 |
+
// get the already imported posts to prevent dupes
|
456 |
+
$dupes = $this->get_imported_posts( 'tumblr', $this->blog[$url]['name'] );
|
457 |
+
|
458 |
+
if ($this->blog[$url]['posts_complete'] + TUMBLR_MAX_IMPORT > $total) $count = $total - $start;
|
459 |
+
else $count = TUMBLR_MAX_IMPORT;
|
460 |
+
|
461 |
+
add_filter( 'tumblr_post_type', array( $this, 'get_draft_post_type' ) );
|
462 |
+
$imported_posts = $this->fetch_posts($url, $start, $count, $this->email, $this->password, 'draft' );
|
463 |
+
|
464 |
+
if ( empty($imported_posts) ) {
|
465 |
+
$this->error = __('Problem communicating with Tumblr, retrying later','tumblr-importer');
|
466 |
+
return;
|
467 |
+
}
|
468 |
+
|
469 |
+
if ( is_array($imported_posts) && !empty($imported_posts) ) {
|
470 |
+
reset($imported_posts);
|
471 |
+
$post = current($imported_posts);
|
472 |
+
do {
|
473 |
+
// skip dupes
|
474 |
+
if ( !empty( $dupes[$post['tumblr_url']] ) ) {
|
475 |
+
$this->blog[$url]['drafts_complete']++;
|
476 |
+
$this->save_vars();
|
477 |
+
continue;
|
478 |
+
}
|
479 |
+
|
480 |
+
$post['post_status'] = 'draft';
|
481 |
+
$post['post_author'] = $this->blog[$url]['post_author'];
|
482 |
+
|
483 |
+
do_action( 'tumblr_importing_post', $post );
|
484 |
+
$id = wp_insert_post( $post );
|
485 |
+
if ( !is_wp_error( $id ) ) {
|
486 |
+
$post['ID'] = $id;
|
487 |
+
if ( isset( $post['format'] ) ) set_post_format($id, $post['format']);
|
488 |
+
|
489 |
+
add_post_meta( $id, 'tumblr_'.$this->blog[$url]['name'].'_permalink', $post['tumblr_url'] );
|
490 |
+
add_post_meta( $id, 'tumblr_'.$this->blog[$url]['name'].'_id', $post['tumblr_id'] );
|
491 |
+
|
492 |
+
$this->handle_sideload($post);
|
493 |
+
}
|
494 |
+
|
495 |
+
$this->blog[$url]['drafts_complete']++;
|
496 |
+
$this->save_vars();
|
497 |
+
} while ( false != ($post = next($imported_posts) ) && $this->have_time() );
|
498 |
+
}
|
499 |
+
}
|
500 |
+
|
501 |
+
function do_pages_import($url) {
|
502 |
+
$start = $this->blog[$url]['pages_complete'];
|
503 |
+
|
504 |
+
// get the already imported posts to prevent dupes
|
505 |
+
$dupes = $this->get_imported_posts( 'tumblr', $this->blog[$url]['name'] );
|
506 |
+
|
507 |
+
$imported_pages = $this->fetch_pages($url, $this->email, $this->password );
|
508 |
+
|
509 |
+
if ( false === $imported_pages ) {
|
510 |
+
$this->error = __('Problem communicating with Tumblr, retrying later','tumblr-importer');
|
511 |
+
return;
|
512 |
+
}
|
513 |
+
|
514 |
+
if ( is_array($imported_pages) && !empty($imported_pages) ) {
|
515 |
+
reset($imported_pages);
|
516 |
+
$post = current($imported_pages);
|
517 |
+
do {
|
518 |
+
// skip dupes
|
519 |
+
if ( !empty( $dupes[$post['tumblr_url']] ) ) {
|
520 |
+
continue;
|
521 |
+
}
|
522 |
+
|
523 |
+
$post['post_type'] = 'page';
|
524 |
+
$post['post_status'] = 'publish';
|
525 |
+
$post['post_author'] = $this->blog[$url]['post_author'];
|
526 |
+
|
527 |
+
$id = wp_insert_post( $post );
|
528 |
+
if ( !is_wp_error( $id ) ) {
|
529 |
+
add_post_meta( $id, 'tumblr_'.$this->blog[$url]['name'].'_permalink', $post['tumblr_url'] );
|
530 |
+
$post['ID'] = $id;
|
531 |
+
$this->handle_sideload($post);
|
532 |
+
}
|
533 |
+
|
534 |
+
$this->blog[$url]['pages_complete']++;
|
535 |
+
$this->save_vars();
|
536 |
+
} while ( false != ($post = next($imported_pages) ) );
|
537 |
+
}
|
538 |
+
$this->blog[$url]['progress'] = 'finish';
|
539 |
+
}
|
540 |
+
|
541 |
+
function handle_sideload_import($post, $source, $description = '', $filename = false) {
|
542 |
+
// Make a HEAD request to get the filename:
|
543 |
+
if ( empty($filename) ) {
|
544 |
+
$head = wp_remote_request( $source, array('method' => 'HEAD') );
|
545 |
+
if ( !empty($head['headers']['location']) ) {
|
546 |
+
$source = $head['headers']['location'];
|
547 |
+
$filename = preg_replace('!\?.*!', '', basename($source) ); // Strip off the Query vars
|
548 |
+
}
|
549 |
+
}
|
550 |
+
|
551 |
+
// still empty? Darned inconsistent tumblr...
|
552 |
+
if ( empty($filename) ) {
|
553 |
+
$path = parse_url($source,PHP_URL_PATH);
|
554 |
+
$filename = basename($path);
|
555 |
+
}
|
556 |
+
// Download file to temp location
|
557 |
+
$tmp = download_url( $source );
|
558 |
+
if ( is_wp_error($tmp) )
|
559 |
+
return $tmp;
|
560 |
+
|
561 |
+
$file_array['name'] = !empty($filename) ? $filename : basename($tmp);
|
562 |
+
$file_array['tmp_name'] = $tmp;
|
563 |
+
// do the validation and storage stuff
|
564 |
+
$id = media_handle_sideload( $file_array, $post['ID'], $description, array( 'post_excerpt' => $description ) );
|
565 |
+
|
566 |
+
if ( $id && ! is_wp_error($id) ) {
|
567 |
+
// Update the date/time on the attachment to that of the Tumblr post.
|
568 |
+
$attachment = get_post($id, ARRAY_A);
|
569 |
+
foreach ( array('post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt') as $field ) {
|
570 |
+
if ( isset($post[ $field]) )
|
571 |
+
$attachment[ $field ] = $post[ $field ];
|
572 |
+
}
|
573 |
+
wp_update_post($attachment);
|
574 |
+
}
|
575 |
+
|
576 |
+
// If error storing permanently, unlink
|
577 |
+
if ( is_wp_error($id) )
|
578 |
+
@unlink($file_array['tmp_name']);
|
579 |
+
return $id;
|
580 |
+
}
|
581 |
+
|
582 |
+
function handle_sideload($post) {
|
583 |
+
|
584 |
+
if ( empty( $post['format'] ) )
|
585 |
+
return; // Nothing to import.
|
586 |
+
|
587 |
+
switch ( $post['format'] ) {
|
588 |
+
case 'gallery':
|
589 |
+
if ( !empty( $post['gallery'] ) ) {
|
590 |
+
foreach ( $post['gallery'] as $i => $photo ) {
|
591 |
+
$id = $this->handle_sideload_import( $post, (string)$photo['src'], (string)$photo['caption']);
|
592 |
+
if ( is_wp_error($id) )
|
593 |
+
return $id;
|
594 |
+
}
|
595 |
+
$post['post_content'] = "[gallery]\n" . $post['post_content'];
|
596 |
+
$post = apply_filters( 'tumblr_importer_format_post', $post );
|
597 |
+
do_action( 'tumblr_importer_metadata', $post );
|
598 |
+
wp_update_post($post);
|
599 |
+
break; // If we processed a gallery, break, otherwise let it fall through to the Image handler
|
600 |
+
}
|
601 |
+
|
602 |
+
case 'image':
|
603 |
+
if ( isset( $post['media']['src'] ) ) {
|
604 |
+
$id = $this->handle_sideload_import( $post, (string)$post['media']['src'], (string)$post['post_title']);
|
605 |
+
if ( is_wp_error($id) )
|
606 |
+
return $id;
|
607 |
+
|
608 |
+
$link = !empty($post['media']['link']) ? $post['media']['link'] : null;
|
609 |
+
// image_send_to_editor has a filter to wrap in a shortcode.
|
610 |
+
$post_content = $post['post_content'];
|
611 |
+
$post['post_content'] = get_image_send_to_editor($id, (string)$post['post_title'], (string)$post['post_title'], 'none', $link, true, 'full' );
|
612 |
+
$post['post_content'] .= $post_content;
|
613 |
+
$post['meta']['attribution'] = $link;
|
614 |
+
$post = apply_filters( 'tumblr_importer_format_post', $post );
|
615 |
+
do_action( 'tumblr_importer_metadata', $post );
|
616 |
+
//$post['post_content'] .= "\n" . $post['post_content']; // the [caption] shortcode doesn't allow HTML, but this might have some extra markup
|
617 |
+
wp_update_post($post);
|
618 |
+
}
|
619 |
+
|
620 |
+
break;
|
621 |
+
|
622 |
+
case 'audio':
|
623 |
+
// Handle Tumblr Hosted Audio
|
624 |
+
if ( isset( $post['media']['audio'] ) ) {
|
625 |
+
$id = $this->handle_sideload_import( $post, (string)$post['media']['audio'], $post['post_title'], (string)$post['media']['filename'] );
|
626 |
+
if ( is_wp_error($id) )
|
627 |
+
return $id;
|
628 |
+
$post['post_content'] = wp_get_attachment_link($id) . "\n" . $post['post_content'];
|
629 |
+
} else {
|
630 |
+
// Try to work out a "source" link to display Tumblr-style.
|
631 |
+
preg_match( '/(http[^ "<>\']+)/', $post['post_content'], $matches );
|
632 |
+
if ( isset( $matches[1] ) ) {
|
633 |
+
$url_parts = parse_url( $matches[1] );
|
634 |
+
$post['meta']['attribution'] = $url_parts['scheme'] . "://" . $url_parts['host'] . "/";
|
635 |
+
}
|
636 |
+
}
|
637 |
+
$post = apply_filters( 'tumblr_importer_format_post', $post );
|
638 |
+
do_action( 'tumblr_importer_metadata', $post );
|
639 |
+
wp_update_post($post);
|
640 |
+
break;
|
641 |
+
|
642 |
+
case 'video':
|
643 |
+
// Handle Tumblr hosted video
|
644 |
+
if ( isset( $post['media']['video'] ) ) {
|
645 |
+
$id = $this->handle_sideload_import( $post, (string)$post['media']['video'], $post['post_title'], (string)$post['media']['filename'] );
|
646 |
+
if ( is_wp_error($id) )
|
647 |
+
return $id;
|
648 |
+
|
649 |
+
// @TODO: Check/change this to embed the imported video.
|
650 |
+
$link = wp_get_attachment_link($id) . "\n" . $post['post_content'];
|
651 |
+
$post['post_content'] = $link;
|
652 |
+
$post['meta']['attribution'] = $link;
|
653 |
+
} else {
|
654 |
+
// Try to work out a "source" link to mimic Tumblr's post formatting.
|
655 |
+
preg_match( '/(http[^ "<>\']+)/', $post['post_content'], $matches );
|
656 |
+
if ( isset( $matches[1] ) ) {
|
657 |
+
$url_parts = parse_url( $matches[1] );
|
658 |
+
$post['meta']['attribution'] = $url_parts['scheme'] . "://" . $url_parts['host'] . "/";
|
659 |
+
}
|
660 |
+
}
|
661 |
+
$post = apply_filters( 'tumblr_importer_format_post', $post );
|
662 |
+
do_action( 'tumblr_importer_metadata', $post );
|
663 |
+
wp_update_post($post);
|
664 |
+
|
665 |
+
// Else, Check to see if the url embedded is handled by oEmbed (or not)
|
666 |
+
break;
|
667 |
+
}
|
668 |
+
|
669 |
+
return true; // all processed
|
670 |
+
}
|
671 |
+
|
672 |
+
|
673 |
+
/**
|
674 |
+
* Get a request token from the OAuth endpoint (also serves as a test)
|
675 |
+
*
|
676 |
+
*/
|
677 |
+
function oauth_get_request_token() {
|
678 |
+
if ( empty($this->consumerkey) || empty ($this->secretkey) )
|
679 |
+
return false;
|
680 |
+
|
681 |
+
$url = 'https://www.tumblr.com/oauth/request_token';
|
682 |
+
|
683 |
+
$params = array('oauth_callback' => self_admin_url('admin.php?import=tumblr'),
|
684 |
+
'oauth_consumer_key' => $this->consumerkey,
|
685 |
+
"oauth_version" => "1.0",
|
686 |
+
"oauth_nonce" => time(),
|
687 |
+
"oauth_timestamp" => time(),
|
688 |
+
"oauth_signature_method" => "HMAC-SHA1",
|
689 |
+
);
|
690 |
+
|
691 |
+
$params['oauth_signature'] = $this->oauth_signature(array($this->secretkey,''), 'POST', $url, $params);
|
692 |
+
|
693 |
+
$response = wp_remote_post( $url, array('body' => $params));
|
694 |
+
|
695 |
+
return $response;
|
696 |
+
}
|
697 |
+
|
698 |
+
/**
|
699 |
+
* Fetch a list of blogs for a user
|
700 |
+
*
|
701 |
+
* @param $email
|
702 |
+
* @param $password
|
703 |
+
* @returns array of blog info or a WP_Error
|
704 |
+
*/
|
705 |
+
function get_blogs() {
|
706 |
+
$url = 'https://api.tumblr.com/v2/user/info';
|
707 |
+
$response = $this->oauth_get_request($url);
|
708 |
+
|
709 |
+
switch ( $response->meta->status ) {
|
710 |
+
case 403: // Bad Username / Password
|
711 |
+
do_action( 'tumblr_importer_handle_error', 'get_blogs_403' );
|
712 |
+
return new WP_Error('tumblr_error', __('Tumblr says that the the app is not authorized. Please check the settings and try to connect again.', 'tumblr-importer' ) );
|
713 |
+
case 200: // OK
|
714 |
+
break;
|
715 |
+
default:
|
716 |
+
$_error = sprintf( __( 'Tumblr replied with an error: %s', 'tumblr-importer' ), $response->meta->msg );
|
717 |
+
do_action( 'tumblr_importer_handle_error', 'response_' . $response->meta->status );
|
718 |
+
return new WP_Error('tumblr_error', $_error );
|
719 |
+
}
|
720 |
+
|
721 |
+
$blogs = array();
|
722 |
+
foreach ( $response->response->user->blogs as $tblog ) {
|
723 |
+
$blog = array();
|
724 |
+
$blog['title'] = (string) $tblog->title;
|
725 |
+
$blog['posts'] = (int) $tblog->posts;
|
726 |
+
$blog['drafts'] = (int) $tblog->drafts;
|
727 |
+
$blog['queued'] = (int) $tblog->queue;
|
728 |
+
$blog['avatar'] = '';
|
729 |
+
$blog['url'] = (string) $tblog->url;
|
730 |
+
$blog['name'] = (string) $tblog->name;
|
731 |
+
|
732 |
+
$blogs[] = $blog;
|
733 |
+
}
|
734 |
+
$this->blogs = $blogs;
|
735 |
+
return $this->blogs;
|
736 |
+
}
|
737 |
+
|
738 |
+
function get_consumer_key() {
|
739 |
+
return $this->consumerkey;
|
740 |
+
}
|
741 |
+
|
742 |
+
/**
|
743 |
+
* Fetch a subset of posts from a tumblr blog
|
744 |
+
*
|
745 |
+
* @param $start index to start at
|
746 |
+
* @param $count how many posts to get (max 50)
|
747 |
+
* @param $state can be empty for normal posts, or "draft", "queue", or "submission" to get those posts
|
748 |
+
* @returns false on error, array of posts on success
|
749 |
+
*/
|
750 |
+
function fetch_posts($url, $start=0, $count = 50, $email = null, $password = null, $state = null ) {
|
751 |
+
$url = parse_url( $url, PHP_URL_HOST );
|
752 |
+
$post_type = apply_filters( 'tumblr_post_type', '' );
|
753 |
+
$url = trailingslashit( "https://api.tumblr.com/v2/blog/$url/posts/$post_type" );
|
754 |
+
|
755 |
+
do_action( 'tumblr_importer_pre_fetch_posts' );
|
756 |
+
|
757 |
+
// These extra params hose up the auth if passed for oauth requests e.g. for drafts, so use them only for normal posts.
|
758 |
+
if ( '' == $post_type ) {
|
759 |
+
$params = array(
|
760 |
+
'offset' => $start,
|
761 |
+
'limit' => $count,
|
762 |
+
'api_key' => apply_filters( 'tumblr_importer_get_consumer_key', '' ),
|
763 |
+
);
|
764 |
+
$url = add_query_arg( $params, $url );
|
765 |
+
}
|
766 |
+
|
767 |
+
$response = $this->oauth_get_request($url);
|
768 |
+
|
769 |
+
switch ( $response->meta->status ) {
|
770 |
+
case 200: // OK
|
771 |
+
break;
|
772 |
+
default:
|
773 |
+
$_error = sprintf( __( 'Tumblr replied with an error: %s', 'tumblr-importer' ), $response->meta->msg );
|
774 |
+
do_action( 'tumblr_importer_handle_error', 'response_' . $response->meta->status );
|
775 |
+
return new WP_Error('tumblr_error', $_error );
|
776 |
+
}
|
777 |
+
|
778 |
+
$posts = array();
|
779 |
+
$tposts = $response->response->posts;
|
780 |
+
foreach( $tposts as $tpost ) {
|
781 |
+
$post = array();
|
782 |
+
$post['tumblr_id'] = (string) $tpost->id;
|
783 |
+
$post['tumblr_url'] = (string) $tpost->post_url;
|
784 |
+
$post['post_date'] = date( 'Y-m-d H:i:s', strtotime ( (string) $tpost->date ) );
|
785 |
+
$post['post_date_gmt'] = date( 'Y-m-d H:i:s', strtotime ( (string) $tpost->date ) );
|
786 |
+
$post['post_name'] = (string) $tpost->slug;
|
787 |
+
if ( 'private' == $tpost->state )
|
788 |
+
$post['private'] = (string) $tpost->state;
|
789 |
+
if ( isset( $tpost->tags ) ) {
|
790 |
+
$post['tags_input'] = array();
|
791 |
+
foreach ( $tpost->tags as $tag )
|
792 |
+
$post['tags_input'][] = rtrim( (string) $tag, ','); // Strip trailing Commas off it too.
|
793 |
+
}
|
794 |
+
|
795 |
+
switch ( (string) $tpost->type ) {
|
796 |
+
case 'photo':
|
797 |
+
$post['format'] = 'image';
|
798 |
+
$post['media']['src'] = (string) $tpost->photos[0]->original_size->url;
|
799 |
+
$post['media']['link'] = '';//TODO: Find out what to use here.(string) $tpost->{'photo-link-url'};
|
800 |
+
$post['media']['width'] = (string) $tpost->photos[0]->original_size->width;
|
801 |
+
$post['media']['height'] = (string) $tpost->photos[0]->original_size->height;
|
802 |
+
$post['post_content'] = (string) $tpost->caption;
|
803 |
+
if ( ! empty( $tpost->photos ) ) {
|
804 |
+
$post['format'] = 'gallery';
|
805 |
+
foreach ( $tpost->photos as $photo ) {
|
806 |
+
$post['gallery'][] = array (
|
807 |
+
'src' => $photo->original_size->url,
|
808 |
+
'width' => $photo->original_size->width,
|
809 |
+
'height' => $photo->original_size->height,
|
810 |
+
'caption' => $photo->caption,
|
811 |
+
);
|
812 |
+
}
|
813 |
+
}
|
814 |
+
break;
|
815 |
+
case 'quote':
|
816 |
+
$post['format'] = 'quote';
|
817 |
+
$post['post_content'] = '<blockquote>' . (string) $tpost->text . '</blockquote>';
|
818 |
+
$post['post_content'] .= "\n\n<div class='attribution'>" . (string) $tpost->source . '</div>';
|
819 |
+
break;
|
820 |
+
case 'link':
|
821 |
+
$post['format'] = 'link';
|
822 |
+
$linkurl = (string) $tpost->url;
|
823 |
+
$linktext = (string) $tpost->title;
|
824 |
+
$post['post_content'] = "<a href='$linkurl'>$linktext</a>";
|
825 |
+
if ( ! empty( $tpost->description ) )
|
826 |
+
$post['post_content'] .= '<div class="link_description">' . (string) $tpost->description . '</div>';
|
827 |
+
$post['post_title'] = (string) $tpost->title;
|
828 |
+
break;
|
829 |
+
case 'chat':
|
830 |
+
$post['format'] = 'chat';
|
831 |
+
$post['post_title'] = (string) $tpost->title;
|
832 |
+
$post['post_content'] = (string) $tpost->body;
|
833 |
+
break;
|
834 |
+
case 'audio':
|
835 |
+
$post['format'] = 'audio';
|
836 |
+
$post['media']['filename'] = basename( (string) $tpost->audio_url );
|
837 |
+
// If no .mp3 extension, add one so that sideloading works.
|
838 |
+
if ( ! preg_match( '/\.mp3$/', $post['media']['filename'] ) )
|
839 |
+
$post['media']['filename'] .= '.mp3';
|
840 |
+
$post['media']['audio'] = (string) $tpost->audio_url .'?plead=please-dont-download-this-or-our-lawyers-wont-let-us-host-audio';
|
841 |
+
$post['post_content'] = (string) $tpost->player . "\n" . (string) $tpost->caption;
|
842 |
+
break;
|
843 |
+
case 'video':
|
844 |
+
$post['format'] = 'video';
|
845 |
+
$post['post_content'] = '';
|
846 |
+
|
847 |
+
$video = array_shift( $tpost->player );
|
848 |
+
|
849 |
+
if ( false !== strpos( (string) $video->embed_code, 'embed' ) ) {
|
850 |
+
if ( preg_match_all('/<embed (.+?)>/', (string) $video->embed_code, $matches) ) {
|
851 |
+
foreach ($matches[1] as $match) {
|
852 |
+
foreach ( wp_kses_hair( $match, array( 'http' ) ) as $attr )
|
853 |
+
$embed[ $attr['name'] ] = $attr['value'];
|
854 |
+
}
|
855 |
+
|
856 |
+
// special case for weird youtube vids
|
857 |
+
$embed['src'] = preg_replace( '|http://www.youtube.com/v/([a-zA-Z0-9_]+).*|i', 'http://www.youtube.com/watch?v=$1', $embed['src'] );
|
858 |
+
|
859 |
+
// TODO find other special cases, since tumblr is full of them
|
860 |
+
$post['post_content'] = $embed['src'];
|
861 |
+
}
|
862 |
+
|
863 |
+
// Sometimes, video-source contains iframe markup.
|
864 |
+
if ( preg_match( '/<iframe/', $video->embed_code ) ) {
|
865 |
+
$embed['src'] = preg_replace( '|<iframe.*src="http://www.youtube.com/embed/([a-zA-Z0-9_\-]+)\??.*".*</iframe>|', 'http://www.youtube.com/watch?v=$1', $video->embed_code );
|
866 |
+
$post['post_content'] = $embed['src'];
|
867 |
+
}
|
868 |
+
} elseif ( preg_match( '/<iframe.*vimeo/', $video->embed_code ) ) {
|
869 |
+
$embed['src'] = preg_replace( '|<iframe.*src="(http://player.vimeo.com/video/([a-zA-Z0-9_\-]+))\??.*".*</iframe>.*|', 'http://vimeo.com/$2', $video->embed_code );
|
870 |
+
$post['post_content'] = $embed['src'];
|
871 |
+
} else {
|
872 |
+
// @todo: See if the video source is going to be oEmbed'able before adding the flash player
|
873 |
+
$post['post_content'] .= $video->embed_code;
|
874 |
+
}
|
875 |
+
|
876 |
+
$post['post_content'] .= "\n" . (string) $tpost->caption;
|
877 |
+
break;
|
878 |
+
case 'answer':
|
879 |
+
// TODO: Include asking_name and asking_url values?
|
880 |
+
$post['post_title'] = (string) $tpost->question;
|
881 |
+
$post['post_content'] = (string) $tpost->answer;
|
882 |
+
break;
|
883 |
+
case 'regular':
|
884 |
+
case 'text':
|
885 |
+
default:
|
886 |
+
$post['post_title'] = (string) $tpost->title;
|
887 |
+
$post['post_content'] = (string) $tpost->body;
|
888 |
+
break;
|
889 |
+
}
|
890 |
+
$posts[] = $post;
|
891 |
+
}
|
892 |
+
|
893 |
+
return $posts;
|
894 |
+
}
|
895 |
+
|
896 |
+
/**
|
897 |
+
* Fetch the Pages from a tumblr blog
|
898 |
+
*
|
899 |
+
* @returns false on error, array of page contents on success
|
900 |
+
*/
|
901 |
+
function fetch_pages($url, $email = null, $password = null) {
|
902 |
+
$tumblrurl = trailingslashit($url).'api/pages';
|
903 |
+
$params = array(
|
904 |
+
'email'=>$email,
|
905 |
+
'password'=>$password,
|
906 |
+
);
|
907 |
+
$options = array( 'body' => $params );
|
908 |
+
|
909 |
+
// fetch the pages
|
910 |
+
$out = wp_remote_post($tumblrurl,$options);
|
911 |
+
if (wp_remote_retrieve_response_code($out) != 200) return false;
|
912 |
+
$body = wp_remote_retrieve_body($out);
|
913 |
+
|
914 |
+
// parse the XML into something useful
|
915 |
+
$xml = simplexml_load_string($body);
|
916 |
+
|
917 |
+
if (!isset($xml->pages)) return false;
|
918 |
+
|
919 |
+
$tpages = $xml->pages;
|
920 |
+
$pages = array();
|
921 |
+
foreach($tpages->page as $tpage) {
|
922 |
+
if ( !empty($tpage['title']) )
|
923 |
+
$page['post_title'] = (string) $tpage['title'];
|
924 |
+
else if (!empty($tpage['link-title']) )
|
925 |
+
$page['post_title'] = (string) $tpage['link-title'];
|
926 |
+
else
|
927 |
+
$page['post_title'] = '';
|
928 |
+
$page['post_name'] = str_replace( $url, '', (string) $tpage['url'] );
|
929 |
+
$page['post_content'] = (string) $tpage;
|
930 |
+
$page['tumblr_url'] = (string) $tpage['url'];
|
931 |
+
$pages[] = $page;
|
932 |
+
}
|
933 |
+
|
934 |
+
return $pages;
|
935 |
+
}
|
936 |
+
|
937 |
+
function filter_format_post( $_post ) {
|
938 |
+
if ( isset( $_post['meta']['attribution'] ) ) {
|
939 |
+
$attribution = $_post['meta']['attribution'];
|
940 |
+
if ( preg_match( '/^http[^ ]+$/', $_post['meta']['attribution'] ) )
|
941 |
+
$attribution = sprintf( '<a href="%s">%s</a>', $_post['meta']['attribution'], $_post['meta']['attribution'] );
|
942 |
+
$_post['post_content'] .= sprintf( '<div class="attribution">(<span>' . __( 'Source:', 'tumblr-importer' ) . '</span> %s)</div>', $attribution );
|
943 |
+
}
|
944 |
+
|
945 |
+
return $_post;
|
946 |
+
}
|
947 |
+
|
948 |
+
function tumblr_importer_metadata( $_post ) {
|
949 |
+
if ( isset( $_post['meta'] ) ) {
|
950 |
+
foreach ( $_post['meta'] as $key => $val ) {
|
951 |
+
add_post_meta( $_post['ID'], 'tumblr_' . $key, $val );
|
952 |
+
}
|
953 |
+
}
|
954 |
+
}
|
955 |
+
|
956 |
+
/*
|
957 |
+
* When galleries have no caption, the post_content field is empty, which
|
958 |
+
* along with empty title and excerpt causes the post not to insert.
|
959 |
+
* Here we override the default behavior.
|
960 |
+
*/
|
961 |
+
function filter_allow_empty_content( $maybe_empty, $_post ) {
|
962 |
+
if ( 'gallery' == $_post['format'] )
|
963 |
+
return false;
|
964 |
+
|
965 |
+
return $maybe_empty;
|
966 |
+
}
|
967 |
+
|
968 |
+
|
969 |
+
/**
|
970 |
+
* OAuth Signature creation
|
971 |
+
*/
|
972 |
+
function oauth_signature($secret, $method, $url, $params = array()) {
|
973 |
+
uksort($params, 'strcmp');
|
974 |
+
foreach ($params as $k => $v) {
|
975 |
+
$pairs[] = $this->_urlencode_rfc3986($k).'='.$this->_urlencode_rfc3986($v);
|
976 |
+
}
|
977 |
+
$concatenatedParams = implode('&', $pairs);
|
978 |
+
$baseString= $method."&". $this->_urlencode_rfc3986($url)."&".$this->_urlencode_rfc3986($concatenatedParams);
|
979 |
+
if (!is_array($secret)) {
|
980 |
+
$secret[0] = $secret;
|
981 |
+
$secret[1] = '';
|
982 |
+
}
|
983 |
+
$secret = $this->_urlencode_rfc3986($secret[0])."&".$this->_urlencode_rfc3986($secret[1]);
|
984 |
+
$oauth_signature = base64_encode(hash_hmac('sha1', $baseString, $secret, TRUE));
|
985 |
+
return $oauth_signature;
|
986 |
+
}
|
987 |
+
|
988 |
+
/**
|
989 |
+
* Helper function for OAuth Signature creation
|
990 |
+
*/
|
991 |
+
function _urlencode_rfc3986($input)
|
992 |
+
{
|
993 |
+
if (is_array($input)) {
|
994 |
+
return array_map(array($this, '_urlencode_rfc3986'), $input);
|
995 |
+
} else if (is_scalar($input)) {
|
996 |
+
return str_replace(array('+', '%7E'), array(' ', '~'), rawurlencode($input));
|
997 |
+
} else {
|
998 |
+
return '';
|
999 |
+
}
|
1000 |
+
}
|
1001 |
+
|
1002 |
+
/**
|
1003 |
+
* Do a GET request with the access tokens
|
1004 |
+
*/
|
1005 |
+
function oauth_get_request($url) {
|
1006 |
+
if ( empty( $this->access_tokens ) )
|
1007 |
+
return false;
|
1008 |
+
|
1009 |
+
$params = array('oauth_consumer_key' => $this->get_consumer_key(),
|
1010 |
+
"oauth_nonce" => time(),
|
1011 |
+
"oauth_timestamp" => time(),
|
1012 |
+
"oauth_token" => $this->access_tokens['oauth_token'],
|
1013 |
+
"oauth_signature_method" => "HMAC-SHA1",
|
1014 |
+
"oauth_version" => "1.0",
|
1015 |
+
);
|
1016 |
+
|
1017 |
+
$params['oauth_signature'] = $this->oauth_signature(array($this->secretkey,$this->access_tokens['oauth_token_secret']), 'GET', $url, $params);
|
1018 |
+
|
1019 |
+
$url = add_query_arg( array_map('urlencode', $params), $url);
|
1020 |
+
|
1021 |
+
$response = wp_remote_get( $url );
|
1022 |
+
|
1023 |
+
if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
|
1024 |
+
return false;
|
1025 |
+
} else {
|
1026 |
+
$body = wp_remote_retrieve_body( $response );
|
1027 |
+
return json_decode($body);
|
1028 |
+
}
|
1029 |
+
}
|
1030 |
+
|
1031 |
+
|
1032 |
+
}
|
1033 |
+
}
|