Version Description
- Fix edge cases for tumblr photos where tumblr isn't returning expected headers for filenames
Download this release
Release Info
Developer | nacin |
Plugin | Tumblr Importer |
Version | 0.5 |
Comparing to | |
See all releases |
Version 0.5
- class-wp-importer-cron.php +90 -0
- license.txt +281 -0
- readme.txt +48 -0
- tumblr-importer.php +787 -0
class-wp-importer-cron.php
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WP_Importer_Cron base class
|
4 |
+
*
|
5 |
+
* Adds cron based importing functionality to WP_Importer
|
6 |
+
*/
|
7 |
+
|
8 |
+
if ( !class_exists( 'WP_Importer_Cron' ) ) :
|
9 |
+
|
10 |
+
require_once ABSPATH . 'wp-admin/includes/import.php';
|
11 |
+
|
12 |
+
if ( !class_exists( 'WP_Importer' ) ) {
|
13 |
+
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
|
14 |
+
if ( file_exists( $class_wp_importer ) ) {
|
15 |
+
require_once $class_wp_importer;
|
16 |
+
} else {
|
17 |
+
return;
|
18 |
+
}
|
19 |
+
}
|
20 |
+
|
21 |
+
class WP_Importer_Cron extends WP_Importer {
|
22 |
+
|
23 |
+
function __construct() {
|
24 |
+
// start the clock
|
25 |
+
$this->_importer_started = time();
|
26 |
+
$this->_max_execution_time = 30; // default to 30 seconds of time on the clock
|
27 |
+
parent::__construct();
|
28 |
+
|
29 |
+
// add the importer schedule
|
30 |
+
add_filter( 'cron_schedules', array( $this, 'importer_schedule' ) );
|
31 |
+
|
32 |
+
// add the importer hook
|
33 |
+
add_action( 'wp_cron_importer_hook', array( $this, 'importer_callback' ) );
|
34 |
+
|
35 |
+
//load the variables
|
36 |
+
$options = get_option( get_class($this) );
|
37 |
+
|
38 |
+
if ( is_array($options) )
|
39 |
+
foreach ( $options as $key => $value )
|
40 |
+
$this->$key = $value;
|
41 |
+
}
|
42 |
+
|
43 |
+
// Check to see if you have time remaining on the clock
|
44 |
+
function have_time() {
|
45 |
+
if ( time() - $this->_importer_started > $this->_max_execution_time ) return false;
|
46 |
+
return true;
|
47 |
+
}
|
48 |
+
|
49 |
+
// add the once every three minute schedule
|
50 |
+
function importer_schedule( $schedules ) {
|
51 |
+
$schedules['everyminute'] = array( 'interval' => 60, 'display' => __('Every Minute') );
|
52 |
+
return $schedules;
|
53 |
+
}
|
54 |
+
|
55 |
+
// schedule an importer job
|
56 |
+
function schedule_import_job( $function_name, $args=array() ) {
|
57 |
+
$this->callback = $function_name;
|
58 |
+
wp_schedule_event(time(), 'everyminute', 'wp_cron_importer_hook' , $args);
|
59 |
+
}
|
60 |
+
|
61 |
+
// internal callback that checks for a finished import and clears old jobs out
|
62 |
+
function importer_callback( $args=array() ) {
|
63 |
+
$args = (array)$args;
|
64 |
+
|
65 |
+
if ( isset($this->callback) ) {
|
66 |
+
$complete = call_user_func_array( array( $this, $this->callback ), $args );
|
67 |
+
} else {
|
68 |
+
// no callback, force the cron job to end
|
69 |
+
$complete = true;
|
70 |
+
}
|
71 |
+
|
72 |
+
if ( $complete ) {
|
73 |
+
// importer is finished, stop the scheduler
|
74 |
+
wp_clear_scheduled_hook( 'wp_cron_importer_hook', $args);
|
75 |
+
}
|
76 |
+
}
|
77 |
+
|
78 |
+
// function to let the class save its own variables
|
79 |
+
function save_vars() {
|
80 |
+
$vars = get_object_vars($this);
|
81 |
+
foreach($vars as $var=>$val) {
|
82 |
+
if ($var[0] == "_") unset ($vars[$var]);
|
83 |
+
}
|
84 |
+
update_option( get_class($this), $vars );
|
85 |
+
|
86 |
+
return !empty($vars);
|
87 |
+
}
|
88 |
+
}
|
89 |
+
|
90 |
+
endif; // class_exists
|
license.txt
ADDED
@@ -0,0 +1,281 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GNU GENERAL PUBLIC LICENSE
|
2 |
+
Version 2, June 1991
|
3 |
+
|
4 |
+
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
5 |
+
51 Franklin St, Fifth Floor, Boston, MA 02110, USA
|
6 |
+
|
7 |
+
Everyone is permitted to copy and distribute verbatim copies
|
8 |
+
of this license document, but changing it is not allowed.
|
9 |
+
|
10 |
+
Preamble
|
11 |
+
|
12 |
+
The licenses for most software are designed to take away your
|
13 |
+
freedom to share and change it. By contrast, the GNU General Public
|
14 |
+
License is intended to guarantee your freedom to share and change free
|
15 |
+
software--to make sure the software is free for all its users. This
|
16 |
+
General Public License applies to most of the Free Software
|
17 |
+
Foundation's software and to any other program whose authors commit to
|
18 |
+
using it. (Some other Free Software Foundation software is covered by
|
19 |
+
the GNU Library General Public License instead.) You can apply it to
|
20 |
+
your programs, too.
|
21 |
+
|
22 |
+
When we speak of free software, we are referring to freedom, not
|
23 |
+
price. Our General Public Licenses are designed to make sure that you
|
24 |
+
have the freedom to distribute copies of free software (and charge for
|
25 |
+
this service if you wish), that you receive source code or can get it
|
26 |
+
if you want it, that you can change the software or use pieces of it
|
27 |
+
in new free programs; and that you know you can do these things.
|
28 |
+
|
29 |
+
To protect your rights, we need to make restrictions that forbid
|
30 |
+
anyone to deny you these rights or to ask you to surrender the rights.
|
31 |
+
These restrictions translate to certain responsibilities for you if you
|
32 |
+
distribute copies of the software, or if you modify it.
|
33 |
+
|
34 |
+
For example, if you distribute copies of such a program, whether
|
35 |
+
gratis or for a fee, you must give the recipients all the rights that
|
36 |
+
you have. You must make sure that they, too, receive or can get the
|
37 |
+
source code. And you must show them these terms so they know their
|
38 |
+
rights.
|
39 |
+
|
40 |
+
We protect your rights with two steps: (1) copyright the software, and
|
41 |
+
(2) offer you this license which gives you legal permission to copy,
|
42 |
+
distribute and/or modify the software.
|
43 |
+
|
44 |
+
Also, for each author's protection and ours, we want to make certain
|
45 |
+
that everyone understands that there is no warranty for this free
|
46 |
+
software. If the software is modified by someone else and passed on, we
|
47 |
+
want its recipients to know that what they have is not the original, so
|
48 |
+
that any problems introduced by others will not reflect on the original
|
49 |
+
authors' reputations.
|
50 |
+
|
51 |
+
Finally, any free program is threatened constantly by software
|
52 |
+
patents. We wish to avoid the danger that redistributors of a free
|
53 |
+
program will individually obtain patent licenses, in effect making the
|
54 |
+
program proprietary. To prevent this, we have made it clear that any
|
55 |
+
patent must be licensed for everyone's free use or not licensed at all.
|
56 |
+
|
57 |
+
The precise terms and conditions for copying, distribution and
|
58 |
+
modification follow.
|
59 |
+
|
60 |
+
GNU GENERAL PUBLIC LICENSE
|
61 |
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
62 |
+
|
63 |
+
0. This License applies to any program or other work which contains
|
64 |
+
a notice placed by the copyright holder saying it may be distributed
|
65 |
+
under the terms of this General Public License. The "Program", below,
|
66 |
+
refers to any such program or work, and a "work based on the Program"
|
67 |
+
means either the Program or any derivative work under copyright law:
|
68 |
+
that is to say, a work containing the Program or a portion of it,
|
69 |
+
either verbatim or with modifications and/or translated into another
|
70 |
+
language. (Hereinafter, translation is included without limitation in
|
71 |
+
the term "modification".) Each licensee is addressed as "you".
|
72 |
+
|
73 |
+
Activities other than copying, distribution and modification are not
|
74 |
+
covered by this License; they are outside its scope. The act of
|
75 |
+
running the Program is not restricted, and the output from the Program
|
76 |
+
is covered only if its contents constitute a work based on the
|
77 |
+
Program (independent of having been made by running the Program).
|
78 |
+
Whether that is true depends on what the Program does.
|
79 |
+
|
80 |
+
1. You may copy and distribute verbatim copies of the Program's
|
81 |
+
source code as you receive it, in any medium, provided that you
|
82 |
+
conspicuously and appropriately publish on each copy an appropriate
|
83 |
+
copyright notice and disclaimer of warranty; keep intact all the
|
84 |
+
notices that refer to this License and to the absence of any warranty;
|
85 |
+
and give any other recipients of the Program a copy of this License
|
86 |
+
along with the Program.
|
87 |
+
|
88 |
+
You may charge a fee for the physical act of transferring a copy, and
|
89 |
+
you may at your option offer warranty protection in exchange for a fee.
|
90 |
+
|
91 |
+
2. You may modify your copy or copies of the Program or any portion
|
92 |
+
of it, thus forming a work based on the Program, and copy and
|
93 |
+
distribute such modifications or work under the terms of Section 1
|
94 |
+
above, provided that you also meet all of these conditions:
|
95 |
+
|
96 |
+
a) You must cause the modified files to carry prominent notices
|
97 |
+
stating that you changed the files and the date of any change.
|
98 |
+
|
99 |
+
b) You must cause any work that you distribute or publish, that in
|
100 |
+
whole or in part contains or is derived from the Program or any
|
101 |
+
part thereof, to be licensed as a whole at no charge to all third
|
102 |
+
parties under the terms of this License.
|
103 |
+
|
104 |
+
c) If the modified program normally reads commands interactively
|
105 |
+
when run, you must cause it, when started running for such
|
106 |
+
interactive use in the most ordinary way, to print or display an
|
107 |
+
announcement including an appropriate copyright notice and a
|
108 |
+
notice that there is no warranty (or else, saying that you provide
|
109 |
+
a warranty) and that users may redistribute the program under
|
110 |
+
these conditions, and telling the user how to view a copy of this
|
111 |
+
License. (Exception: if the Program itself is interactive but
|
112 |
+
does not normally print such an announcement, your work based on
|
113 |
+
the Program is not required to print an announcement.)
|
114 |
+
|
115 |
+
These requirements apply to the modified work as a whole. If
|
116 |
+
identifiable sections of that work are not derived from the Program,
|
117 |
+
and can be reasonably considered independent and separate works in
|
118 |
+
themselves, then this License, and its terms, do not apply to those
|
119 |
+
sections when you distribute them as separate works. But when you
|
120 |
+
distribute the same sections as part of a whole which is a work based
|
121 |
+
on the Program, the distribution of the whole must be on the terms of
|
122 |
+
this License, whose permissions for other licensees extend to the
|
123 |
+
entire whole, and thus to each and every part regardless of who wrote it.
|
124 |
+
Thus, it is not the intent of this section to claim rights or contest
|
125 |
+
your rights to work written entirely by you; rather, the intent is to
|
126 |
+
exercise the right to control the distribution of derivative or
|
127 |
+
collective works based on the Program.
|
128 |
+
|
129 |
+
In addition, mere aggregation of another work not based on the Program
|
130 |
+
with the Program (or with a work based on the Program) on a volume of
|
131 |
+
a storage or distribution medium does not bring the other work under
|
132 |
+
the scope of this License.
|
133 |
+
|
134 |
+
3. You may copy and distribute the Program (or a work based on it,
|
135 |
+
under Section 2) in object code or executable form under the terms of
|
136 |
+
Sections 1 and 2 above provided that you also do one of the following:
|
137 |
+
|
138 |
+
a) Accompany it with the complete corresponding machine-readable
|
139 |
+
source code, which must be distributed under the terms of Sections
|
140 |
+
1 and 2 above on a medium customarily used for software interchange; or,
|
141 |
+
|
142 |
+
b) Accompany it with a written offer, valid for at least three
|
143 |
+
years, to give any third party, for a charge no more than your
|
144 |
+
cost of physically performing source distribution, a complete
|
145 |
+
machine-readable copy of the corresponding source code, to be
|
146 |
+
distributed under the terms of Sections 1 and 2 above on a medium
|
147 |
+
customarily used for software interchange; or,
|
148 |
+
|
149 |
+
c) Accompany it with the information you received as to the offer
|
150 |
+
to distribute corresponding source code. (This alternative is
|
151 |
+
allowed only for noncommercial distribution and only if you
|
152 |
+
received the program in object code or executable form with such
|
153 |
+
an offer, in accord with Subsection b above.)
|
154 |
+
|
155 |
+
The source code for a work means the preferred form of the work for
|
156 |
+
making modifications to it. For an executable work, complete source
|
157 |
+
code means all the source code for all modules it contains, plus any
|
158 |
+
associated interface definition files, plus the scripts used to
|
159 |
+
control compilation and installation of the executable. However, as a
|
160 |
+
special exception, the source code distributed need not include
|
161 |
+
anything that is normally distributed (in either source or binary
|
162 |
+
form) with the major components (compiler, kernel, and so on) of the
|
163 |
+
operating system on which the executable runs, unless that component
|
164 |
+
itself accompanies the executable.
|
165 |
+
|
166 |
+
If distribution of executable or object code is made by offering
|
167 |
+
access to copy from a designated place, then offering equivalent
|
168 |
+
access to copy the source code from the same place counts as
|
169 |
+
distribution of the source code, even though third parties are not
|
170 |
+
compelled to copy the source along with the object code.
|
171 |
+
|
172 |
+
4. You may not copy, modify, sublicense, or distribute the Program
|
173 |
+
except as expressly provided under this License. Any attempt
|
174 |
+
otherwise to copy, modify, sublicense or distribute the Program is
|
175 |
+
void, and will automatically terminate your rights under this License.
|
176 |
+
However, parties who have received copies, or rights, from you under
|
177 |
+
this License will not have their licenses terminated so long as such
|
178 |
+
parties remain in full compliance.
|
179 |
+
|
180 |
+
5. You are not required to accept this License, since you have not
|
181 |
+
signed it. However, nothing else grants you permission to modify or
|
182 |
+
distribute the Program or its derivative works. These actions are
|
183 |
+
prohibited by law if you do not accept this License. Therefore, by
|
184 |
+
modifying or distributing the Program (or any work based on the
|
185 |
+
Program), you indicate your acceptance of this License to do so, and
|
186 |
+
all its terms and conditions for copying, distributing or modifying
|
187 |
+
the Program or works based on it.
|
188 |
+
|
189 |
+
6. Each time you redistribute the Program (or any work based on the
|
190 |
+
Program), the recipient automatically receives a license from the
|
191 |
+
original licensor to copy, distribute or modify the Program subject to
|
192 |
+
these terms and conditions. You may not impose any further
|
193 |
+
restrictions on the recipients' exercise of the rights granted herein.
|
194 |
+
You are not responsible for enforcing compliance by third parties to
|
195 |
+
this License.
|
196 |
+
|
197 |
+
7. If, as a consequence of a court judgment or allegation of patent
|
198 |
+
infringement or for any other reason (not limited to patent issues),
|
199 |
+
conditions are imposed on you (whether by court order, agreement or
|
200 |
+
otherwise) that contradict the conditions of this License, they do not
|
201 |
+
excuse you from the conditions of this License. If you cannot
|
202 |
+
distribute so as to satisfy simultaneously your obligations under this
|
203 |
+
License and any other pertinent obligations, then as a consequence you
|
204 |
+
may not distribute the Program at all. For example, if a patent
|
205 |
+
license would not permit royalty-free redistribution of the Program by
|
206 |
+
all those who receive copies directly or indirectly through you, then
|
207 |
+
the only way you could satisfy both it and this License would be to
|
208 |
+
refrain entirely from distribution of the Program.
|
209 |
+
|
210 |
+
If any portion of this section is held invalid or unenforceable under
|
211 |
+
any particular circumstance, the balance of the section is intended to
|
212 |
+
apply and the section as a whole is intended to apply in other
|
213 |
+
circumstances.
|
214 |
+
|
215 |
+
It is not the purpose of this section to induce you to infringe any
|
216 |
+
patents or other property right claims or to contest validity of any
|
217 |
+
such claims; this section has the sole purpose of protecting the
|
218 |
+
integrity of the free software distribution system, which is
|
219 |
+
implemented by public license practices. Many people have made
|
220 |
+
generous contributions to the wide range of software distributed
|
221 |
+
through that system in reliance on consistent application of that
|
222 |
+
system; it is up to the author/donor to decide if he or she is willing
|
223 |
+
to distribute software through any other system and a licensee cannot
|
224 |
+
impose that choice.
|
225 |
+
|
226 |
+
This section is intended to make thoroughly clear what is believed to
|
227 |
+
be a consequence of the rest of this License.
|
228 |
+
|
229 |
+
8. If the distribution and/or use of the Program is restricted in
|
230 |
+
certain countries either by patents or by copyrighted interfaces, the
|
231 |
+
original copyright holder who places the Program under this License
|
232 |
+
may add an explicit geographical distribution limitation excluding
|
233 |
+
those countries, so that distribution is permitted only in or among
|
234 |
+
countries not thus excluded. In such case, this License incorporates
|
235 |
+
the limitation as if written in the body of this License.
|
236 |
+
|
237 |
+
9. The Free Software Foundation may publish revised and/or new versions
|
238 |
+
of the General Public License from time to time. Such new versions will
|
239 |
+
be similar in spirit to the present version, but may differ in detail to
|
240 |
+
address new problems or concerns.
|
241 |
+
|
242 |
+
Each version is given a distinguishing version number. If the Program
|
243 |
+
specifies a version number of this License which applies to it and "any
|
244 |
+
later version", you have the option of following the terms and conditions
|
245 |
+
either of that version or of any later version published by the Free
|
246 |
+
Software Foundation. If the Program does not specify a version number of
|
247 |
+
this License, you may choose any version ever published by the Free Software
|
248 |
+
Foundation.
|
249 |
+
|
250 |
+
10. If you wish to incorporate parts of the Program into other free
|
251 |
+
programs whose distribution conditions are different, write to the author
|
252 |
+
to ask for permission. For software which is copyrighted by the Free
|
253 |
+
Software Foundation, write to the Free Software Foundation; we sometimes
|
254 |
+
make exceptions for this. Our decision will be guided by the two goals
|
255 |
+
of preserving the free status of all derivatives of our free software and
|
256 |
+
of promoting the sharing and reuse of software generally.
|
257 |
+
|
258 |
+
NO WARRANTY
|
259 |
+
|
260 |
+
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
261 |
+
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
262 |
+
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
263 |
+
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
264 |
+
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
265 |
+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
266 |
+
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
267 |
+
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
268 |
+
REPAIR OR CORRECTION.
|
269 |
+
|
270 |
+
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
271 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
272 |
+
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
273 |
+
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
274 |
+
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
275 |
+
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
276 |
+
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
277 |
+
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
278 |
+
POSSIBILITY OF SUCH DAMAGES.
|
279 |
+
|
280 |
+
END OF TERMS AND CONDITIONS
|
281 |
+
|
readme.txt
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Tumblr Importer ===
|
2 |
+
Contributors: Otto42, wordpressdotorg, dd32, westi
|
3 |
+
Tags: tumblr, import
|
4 |
+
Requires at least: 3.2
|
5 |
+
Tested up to: 3.4
|
6 |
+
Stable tag: trunk
|
7 |
+
|
8 |
+
== Description ==
|
9 |
+
|
10 |
+
Imports a Tumblr blog into a WordPress blog.
|
11 |
+
|
12 |
+
* Correctly handles post formats
|
13 |
+
* WP-Cron based background importing: start it up, then come back later to see how far it's gotten
|
14 |
+
* Duplicate checking, will not create duplicate imported posts
|
15 |
+
* Imports posts, drafts, and pages
|
16 |
+
* Media Sideloading (for audio, video, and image posts)
|
17 |
+
|
18 |
+
== Installation ==
|
19 |
+
|
20 |
+
1. Upload the files to the `/wp-content/plugins/tumblr-importer/` directory.
|
21 |
+
1. Activate the plugin through the 'Plugins' menu in WordPress.
|
22 |
+
1. Go to Tools->Import and use the new importer.
|
23 |
+
|
24 |
+
== Upgrade Notice ==
|
25 |
+
|
26 |
+
== Changelog ==
|
27 |
+
= 0.5 =
|
28 |
+
* Fix edge cases for tumblr photos where tumblr isn't returning expected headers for filenames
|
29 |
+
|
30 |
+
= 0.4 =
|
31 |
+
* Map multi-image posts to Gallery post format
|
32 |
+
* Import Tags
|
33 |
+
* Import Media to server (Images, Audio, Custom uploaded Video's)
|
34 |
+
* Set the date on Media imports for easier management
|
35 |
+
|
36 |
+
= 0.3 =
|
37 |
+
* Handle multi-image posts
|
38 |
+
* Handle question/answer posts
|
39 |
+
* Handle video posts somewhat better
|
40 |
+
* Speedup (reduce importer delay from 3 minutes to 1 minute)
|
41 |
+
|
42 |
+
= 0.2 =
|
43 |
+
* 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.
|
44 |
+
* Minor debug error cleanup.
|
45 |
+
* Sideloading now done on drafts and pages as well.
|
46 |
+
|
47 |
+
= 0.1 =
|
48 |
+
* First version, not meant to be used except for testing.
|
tumblr-importer.php
ADDED
@@ -0,0 +1,787 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.5
|
9 |
+
License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
10 |
+
*/
|
11 |
+
|
12 |
+
if ( !defined('WP_LOAD_IMPORTERS') && !defined('DOING_CRON') )
|
13 |
+
return;
|
14 |
+
|
15 |
+
require_once ABSPATH . 'wp-admin/includes/import.php';
|
16 |
+
require_once ABSPATH . 'wp-admin/includes/admin.php';
|
17 |
+
|
18 |
+
require_once 'class-wp-importer-cron.php';
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Tumblr Importer Initialisation routines
|
22 |
+
*
|
23 |
+
* @package WordPress
|
24 |
+
* @subpackage Importer
|
25 |
+
*/
|
26 |
+
function tumblr_importer_init() {
|
27 |
+
global $tumblr_import;
|
28 |
+
load_plugin_textdomain( 'tumblr-importer', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
|
29 |
+
|
30 |
+
$tumblr_import = new Tumblr_Import();
|
31 |
+
register_importer('tumblr', __('Tumblr', 'tumblr-importer'), __('Import posts from a Tumblr blog.', 'tumblr-importer'), array ($tumblr_import, 'start'));
|
32 |
+
if ( !defined('TUMBLR_MAX_IMPORT') )
|
33 |
+
define ('TUMBLR_MAX_IMPORT', 20);
|
34 |
+
}
|
35 |
+
add_action( 'init', 'tumblr_importer_init' );
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Tumblr Importer
|
39 |
+
*
|
40 |
+
* @package WordPress
|
41 |
+
* @subpackage Importer
|
42 |
+
*/
|
43 |
+
if ( class_exists( 'WP_Importer_Cron' ) ) {
|
44 |
+
class Tumblr_Import extends WP_Importer_Cron {
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Constructor
|
48 |
+
*/
|
49 |
+
function __construct() {
|
50 |
+
parent::__construct();
|
51 |
+
}
|
52 |
+
|
53 |
+
// Figures out what to do, then does it.
|
54 |
+
function start() {
|
55 |
+
if ( isset($_POST['restart']) )
|
56 |
+
$this->restart();
|
57 |
+
|
58 |
+
if ( !isset($this->error) ) $this->error = null;
|
59 |
+
|
60 |
+
if ( isset( $_POST['email'] ) && isset( $_POST['password'] ) ) {
|
61 |
+
$this->check_credentials();
|
62 |
+
}
|
63 |
+
|
64 |
+
if ( isset( $_POST['blogurl'] ) ) {
|
65 |
+
$this->start_blog_import();
|
66 |
+
}
|
67 |
+
|
68 |
+
if ( isset( $this->blogs ) ) {
|
69 |
+
$this->show_blogs($this->error);
|
70 |
+
} else {
|
71 |
+
$this->greet($this->error);
|
72 |
+
}
|
73 |
+
|
74 |
+
unset ($this->error);
|
75 |
+
|
76 |
+
if ( !isset($_POST['restart']) ) $saved = $this->save_vars();
|
77 |
+
|
78 |
+
if ( $saved && !isset($_GET['noheader']) ) {
|
79 |
+
?>
|
80 |
+
<div class='wrap'>
|
81 |
+
<h2><?php _e('Restart', 'tumblr-importer'); ?></h2>
|
82 |
+
<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>
|
83 |
+
<p><?php _e('Note: This will stop any import currently in progress.', 'tumblr-importer'); ?></p>
|
84 |
+
<form method='post' action='?import=tumblr&noheader=true'>
|
85 |
+
<p class='submit' style='text-align:left;'>
|
86 |
+
<input type='submit' class='button' value='<?php esc_attr_e('Clear account information', 'tumblr-importer'); ?>' name='restart' />
|
87 |
+
</p>
|
88 |
+
</form>
|
89 |
+
</div>
|
90 |
+
<?php
|
91 |
+
}
|
92 |
+
}
|
93 |
+
|
94 |
+
function greet($error=null) {
|
95 |
+
|
96 |
+
if ( !empty( $error ) ) echo "<div class='error'>{$error}</div>";
|
97 |
+
?>
|
98 |
+
|
99 |
+
<div class='wrap'><?php echo screen_icon(); ?>
|
100 |
+
<h2><?php _e('Import Tumblr', 'tumblr-importer'); ?></h2>
|
101 |
+
<p><?php _e('Howdy! This importer allows you to import posts from your Tumblr account into your WordPress site.', 'tumblr-importer'); ?></p>
|
102 |
+
<p><?php _e('First, you need to do is provide your email and password for Tumblr, so that WordPress can access your account.', 'tumblr-importer'); ?></p>
|
103 |
+
<form action='?import=tumblr' method='post'>
|
104 |
+
<?php wp_nonce_field( 'tumblr-import' ) ?>
|
105 |
+
<table class="form-table">
|
106 |
+
<tr>
|
107 |
+
<th scope="row"><label for='email'><?php _e('Email:','tumblr-importer'); ?></label></label></th>
|
108 |
+
<td><input type='text' class="regular-text" name='email' value='<?php if (isset($this->email)) echo esc_attr($this->email); ?>' /></td>
|
109 |
+
</tr>
|
110 |
+
<tr>
|
111 |
+
<th scope="row"><label for='email'><?php _e('Password:','tumblr-importer'); ?></label></label></th>
|
112 |
+
<td><input type='password' class="regular-text" name='password' value='<?php if (isset($this->password)) echo esc_attr($this->password); ?>' /></td>
|
113 |
+
</tr>
|
114 |
+
</table>
|
115 |
+
<p class='submit'>
|
116 |
+
<input type='submit' class='button' value="<?php _e('Connect to Tumblr','tumblr-importer'); ?>" />
|
117 |
+
</p>
|
118 |
+
</form>
|
119 |
+
</div>
|
120 |
+
<?php
|
121 |
+
}
|
122 |
+
|
123 |
+
function check_credentials() {
|
124 |
+
check_admin_referer( 'tumblr-import' );
|
125 |
+
|
126 |
+
$this->email = $_POST['email'];
|
127 |
+
$this->password = $_POST['password'];
|
128 |
+
|
129 |
+
if ( !is_email( $_POST['email'] ) ) {
|
130 |
+
$error = __("This doesn't appear to be a valid email address. Please check it and try again.",'tumblr-importer');
|
131 |
+
$this->error = $error;
|
132 |
+
}
|
133 |
+
|
134 |
+
$blogs = $this->get_blogs($this->email, $this->password);
|
135 |
+
if ( is_wp_error ($blogs) ) {
|
136 |
+
$this->error = $blogs->get_error_message();
|
137 |
+
} else {
|
138 |
+
$this->blogs = $blogs;
|
139 |
+
}
|
140 |
+
}
|
141 |
+
|
142 |
+
function show_blogs($error=null) {
|
143 |
+
|
144 |
+
if ( !empty( $error ) ) echo "<div class='error'>{$error}</div>";
|
145 |
+
?>
|
146 |
+
<div class='wrap'><?php echo screen_icon(); ?>
|
147 |
+
<h2><?php _e('Import Tumblr', 'tumblr-importer'); ?></h2>
|
148 |
+
<p><?php _e('Tumblr does not have such a concept as "author", even on multi-author blogs. Therefore you will need to select which WordPress user will be listed as the author of the imported posts.','tumblr-importer'); ?></p>
|
149 |
+
<p><a href="?import=tumblr"><?php _e('Refresh view','tumblr-importer'); ?></a></p>
|
150 |
+
<table class="widefat" cellspacing="0"><thead>
|
151 |
+
<tr>
|
152 |
+
<th><?php _e('Tumblr Blog','tumblr-importer'); ?></th>
|
153 |
+
<th><?php _e('URL','tumblr-importer'); ?></th>
|
154 |
+
<th><?php _e('Posts Imported','tumblr-importer'); ?></th>
|
155 |
+
<th><?php _e('Drafts Imported','tumblr-importer'); ?></th>
|
156 |
+
<!--<th><?php _e('Queued Imported','tumblr-importer'); ?></th>-->
|
157 |
+
<th><?php _e('Pages Imported','tumblr-importer'); ?></th>
|
158 |
+
<th><?php _e('Author Selection','tumblr-importer'); ?></th>
|
159 |
+
<th><?php _e('Action','tumblr-importer'); ?></th>
|
160 |
+
</tr></thead>
|
161 |
+
<tbody>
|
162 |
+
<?php
|
163 |
+
$style = '';
|
164 |
+
foreach ($this->blogs as $blog) {
|
165 |
+
$url = $blog['url'];
|
166 |
+
$style = ( 'alternate' == $style ) ? '' : 'alternate';
|
167 |
+
if ( !isset( $this->blog[$url] ) ) {
|
168 |
+
$this->blog[$url]['posts_complete'] = 0;
|
169 |
+
$this->blog[$url]['drafts_complete'] = 0;
|
170 |
+
$this->blog[$url]['queued_complete'] = 0;
|
171 |
+
$this->blog[$url]['pages_complete'] = 0;
|
172 |
+
$this->blog[$url]['total_posts'] = $blog['posts'];
|
173 |
+
$this->blog[$url]['total_drafts'] = $blog['drafts'];
|
174 |
+
$this->blog[$url]['total_queued'] = $blog['queued'];
|
175 |
+
$this->blog[$url]['name'] = $blog['name'];
|
176 |
+
}
|
177 |
+
|
178 |
+
if ( empty( $this->blog[$url]['progress'] ) ) {
|
179 |
+
$submit = "<input type='submit' value='". __('Import this blog','tumblr-importer') ."' />";
|
180 |
+
} else if ( $this->blog[$url]['progress'] == 'finish' ) {
|
181 |
+
$submit = "<input type='button' disabled='disabled' value='". __('Finished!','tumblr-importer') ."' />";
|
182 |
+
} else {
|
183 |
+
$submit = "<input type='button' disabled='disabled' value='". __('In Progress','tumblr-importer') ."' />";
|
184 |
+
}
|
185 |
+
?>
|
186 |
+
<tr class="<?php echo $style; ?>">
|
187 |
+
<form action='?import=tumblr' method='post'>
|
188 |
+
<?php wp_nonce_field( 'tumblr-import' ); ?>
|
189 |
+
<input type='hidden' name='blogurl' value='<?php echo esc_attr($blog['url']); ?>' />
|
190 |
+
|
191 |
+
<td><?php echo esc_html($blog['title']); ?></td>
|
192 |
+
<td><?php echo esc_html($blog['url']); ?></td>
|
193 |
+
<td><?php echo $this->blog[$url]['posts_complete']; ?></td>
|
194 |
+
<td><?php echo $this->blog[$url]['drafts_complete']; ?></td>
|
195 |
+
<!--<td><?php echo $this->blog[$url]['queued_complete']; ?></td>-->
|
196 |
+
<td><?php echo $this->blog[$url]['pages_complete']; ?></td>
|
197 |
+
<td><?php wp_dropdown_users( array('who' => 'authors', 'name' => 'post_author' ) ); ?></td>
|
198 |
+
<td><?php echo $submit; ?></td>
|
199 |
+
</form>
|
200 |
+
</tr>
|
201 |
+
<?php
|
202 |
+
}
|
203 |
+
?>
|
204 |
+
</tbody>
|
205 |
+
</table>
|
206 |
+
<p><?php _e("Because Tumblr's servers are often overloaded, the importing process happens in the background. Thus, you will not see immediate results here. Come back to this page later to check on the importer's progress.",'tumblr-importer'); ?></p>
|
207 |
+
</div>
|
208 |
+
<?php
|
209 |
+
}
|
210 |
+
|
211 |
+
function start_blog_import() {
|
212 |
+
check_admin_referer( 'tumblr-import' );
|
213 |
+
|
214 |
+
$url = $_POST['blogurl'];
|
215 |
+
|
216 |
+
if ( !isset( $this->blog[$url] ) ) {
|
217 |
+
$this->error = __('The specified blog cannot be found.', 'tumblr-importer');
|
218 |
+
return;
|
219 |
+
}
|
220 |
+
|
221 |
+
if ( !empty($this->blog[$url]['progress']) ) {
|
222 |
+
$this->error = __('This blog is currently being imported.', 'tumblr-importer');
|
223 |
+
return;
|
224 |
+
}
|
225 |
+
|
226 |
+
$this->blog[$url]['progress'] = 'start';
|
227 |
+
$this->blog[$url]['post_author'] = (int) $_POST['post_author'];
|
228 |
+
|
229 |
+
$this->schedule_import_job( 'do_blog_import', array($url) );
|
230 |
+
}
|
231 |
+
|
232 |
+
function restart() {
|
233 |
+
delete_option(get_class($this));
|
234 |
+
wp_redirect('?import=tumblr');
|
235 |
+
}
|
236 |
+
|
237 |
+
function do_blog_import($url) {
|
238 |
+
|
239 |
+
// default to the done state
|
240 |
+
$done = true;
|
241 |
+
|
242 |
+
$this->error=null;
|
243 |
+
|
244 |
+
if ( !empty( $this->blog[$url]['progress'] ) ) {
|
245 |
+
$done = false;
|
246 |
+
do {
|
247 |
+
switch ($this->blog[$url]['progress']) {
|
248 |
+
case 'start':
|
249 |
+
case 'posts':
|
250 |
+
$this->do_posts_import($url);
|
251 |
+
break;
|
252 |
+
case 'drafts':
|
253 |
+
$this->do_drafts_import($url);
|
254 |
+
break;
|
255 |
+
case 'queued':
|
256 |
+
// TODO Tumblr's API is broken for queued posts
|
257 |
+
$this->blog[$url]['progress'] = 'pages';
|
258 |
+
//$this->do_queued_import($url);
|
259 |
+
break;
|
260 |
+
case 'pages':
|
261 |
+
$this->do_pages_import($url);
|
262 |
+
break;
|
263 |
+
case 'finish':
|
264 |
+
default:
|
265 |
+
$done = true;
|
266 |
+
break;
|
267 |
+
}
|
268 |
+
$this->save_vars();
|
269 |
+
} while ( empty($this->error) && !$done && $this->have_time() );
|
270 |
+
}
|
271 |
+
|
272 |
+
return $done;
|
273 |
+
}
|
274 |
+
|
275 |
+
function do_posts_import($url) {
|
276 |
+
$start = $this->blog[$url]['posts_complete'];
|
277 |
+
$total = $this->blog[$url]['total_posts'];
|
278 |
+
|
279 |
+
// check for posts completion
|
280 |
+
if ( $start == $total ) {
|
281 |
+
$this->blog[$url]['progress'] = 'drafts';
|
282 |
+
return;
|
283 |
+
}
|
284 |
+
|
285 |
+
// get the already imported posts to prevent dupes
|
286 |
+
$dupes = $this->get_imported_posts( 'tumblr', $this->blog[$url]['name'] );
|
287 |
+
|
288 |
+
if ($this->blog[$url]['posts_complete'] + TUMBLR_MAX_IMPORT > $total) $count = $total - $start;
|
289 |
+
else $count = TUMBLR_MAX_IMPORT;
|
290 |
+
|
291 |
+
$imported_posts = $this->fetch_posts($url, $start, $count, $this->email, $this->password );
|
292 |
+
|
293 |
+
if ( empty($imported_posts) ) {
|
294 |
+
$this->error = __('Problem communicating with Tumblr, retrying later','tumblr-importer');
|
295 |
+
return;
|
296 |
+
}
|
297 |
+
|
298 |
+
if ( is_array($imported_posts) && !empty($imported_posts) ) {
|
299 |
+
reset($imported_posts);
|
300 |
+
$post = current($imported_posts);
|
301 |
+
do {
|
302 |
+
// skip dupes
|
303 |
+
if ( !empty( $dupes[$post['tumblr_url']] ) ) {
|
304 |
+
$this->blog[$url]['posts_complete']++;
|
305 |
+
$this->save_vars();
|
306 |
+
continue;
|
307 |
+
}
|
308 |
+
|
309 |
+
if ( isset( $post['private'] ) ) $post['post_status'] = 'private';
|
310 |
+
else $post['post_status']='publish';
|
311 |
+
|
312 |
+
$post['post_author'] = $this->blog[$url]['post_author'];
|
313 |
+
|
314 |
+
if ( empty($post['post_title']) ) {
|
315 |
+
// for empty titles, Attempt to use 100char of the content
|
316 |
+
$content_excerpt = wp_html_excerpt($post['post_content'], 100);
|
317 |
+
if ( ! empty($content_excerpt) ) {
|
318 |
+
$post['post_title'] = $content_excerpt;
|
319 |
+
// And failing the content, use the slug.
|
320 |
+
} elseif ( ! empty($post['post_name']) ) {
|
321 |
+
$post['post_title'] = $post['post_name'];
|
322 |
+
}
|
323 |
+
}
|
324 |
+
|
325 |
+
$id = wp_insert_post( $post );
|
326 |
+
|
327 |
+
if ( !is_wp_error( $id ) ) {
|
328 |
+
$post['ID'] = $id; // Allows for the media importing to wp_update_post()
|
329 |
+
if ( isset( $post['format'] ) ) set_post_format($id, $post['format']);
|
330 |
+
|
331 |
+
// @todo: Add basename of the permalink as a 404 redirect handler for when a custom domain has been brought accross
|
332 |
+
add_post_meta( $id, 'tumblr_'.$this->blog[$url]['name'].'_permalink', $post['tumblr_url'] );
|
333 |
+
add_post_meta( $id, 'tumblr_'.$this->blog[$url]['name'].'_id', $post['tumblr_id'] );
|
334 |
+
$import_result = $this->handle_sideload($post);
|
335 |
+
|
336 |
+
// Handle failed imports.. If empty content and failed to import media..
|
337 |
+
if ( is_wp_error($import_result) ) {
|
338 |
+
if ( empty($post['post_content']) ) {
|
339 |
+
wp_delete_post($id, true);
|
340 |
+
}
|
341 |
+
}
|
342 |
+
}
|
343 |
+
|
344 |
+
$this->blog[$url]['posts_complete']++;
|
345 |
+
$this->save_vars();
|
346 |
+
|
347 |
+
} while ( false != ($post = next($imported_posts) ) && $this->have_time() );
|
348 |
+
}
|
349 |
+
}
|
350 |
+
|
351 |
+
function do_drafts_import($url) {
|
352 |
+
$start = $this->blog[$url]['drafts_complete'];
|
353 |
+
$total = $this->blog[$url]['total_drafts'];
|
354 |
+
|
355 |
+
// check for posts completion
|
356 |
+
if ( $start == $total ) {
|
357 |
+
$this->blog[$url]['progress'] = 'queued';
|
358 |
+
return;
|
359 |
+
}
|
360 |
+
|
361 |
+
// get the already imported posts to prevent dupes
|
362 |
+
$dupes = $this->get_imported_posts( 'tumblr', $this->blog[$url]['name'] );
|
363 |
+
|
364 |
+
if ($this->blog[$url]['posts_complete'] + TUMBLR_MAX_IMPORT > $total) $count = $total - $start;
|
365 |
+
else $count = TUMBLR_MAX_IMPORT;
|
366 |
+
|
367 |
+
$imported_posts = $this->fetch_posts($url, $start, $count, $this->email, $this->password, 'draft' );
|
368 |
+
|
369 |
+
if ( empty($imported_posts) ) {
|
370 |
+
$this->error = __('Problem communicating with Tumblr, retrying later','tumblr-importer');
|
371 |
+
return;
|
372 |
+
}
|
373 |
+
|
374 |
+
if ( is_array($imported_posts) && !empty($imported_posts) ) {
|
375 |
+
reset($imported_posts);
|
376 |
+
$post = current($imported_posts);
|
377 |
+
do {
|
378 |
+
// skip dupes
|
379 |
+
if ( !empty( $dupes[$post['tumblr_url']] ) ) {
|
380 |
+
$this->blog[$url]['drafts_complete']++;
|
381 |
+
$this->save_vars();
|
382 |
+
continue;
|
383 |
+
}
|
384 |
+
|
385 |
+
$post['post_status'] = 'draft';
|
386 |
+
$post['post_author'] = $this->blog[$url]['post_author'];
|
387 |
+
|
388 |
+
$id = wp_insert_post( $post );
|
389 |
+
if ( !is_wp_error( $id ) ) {
|
390 |
+
$post['ID'] = $id;
|
391 |
+
if ( isset( $post['format'] ) ) set_post_format($id, $post['format']);
|
392 |
+
|
393 |
+
add_post_meta( $id, 'tumblr_'.$this->blog[$url]['name'].'_permalink', $post['tumblr_url'] );
|
394 |
+
add_post_meta( $id, 'tumblr_'.$this->blog[$url]['name'].'_id', $post['tumblr_id'] );
|
395 |
+
|
396 |
+
$this->handle_sideload($post);
|
397 |
+
}
|
398 |
+
|
399 |
+
$this->blog[$url]['drafts_complete']++;
|
400 |
+
$this->save_vars();
|
401 |
+
} while ( false != ($post = next($imported_posts) ) && $this->have_time() );
|
402 |
+
}
|
403 |
+
}
|
404 |
+
|
405 |
+
function do_pages_import($url) {
|
406 |
+
$start = $this->blog[$url]['pages_complete'];
|
407 |
+
|
408 |
+
// get the already imported posts to prevent dupes
|
409 |
+
$dupes = $this->get_imported_posts( 'tumblr', $this->blog[$url]['name'] );
|
410 |
+
|
411 |
+
$imported_pages = $this->fetch_pages($url, $this->email, $this->password );
|
412 |
+
|
413 |
+
if ( empty($imported_pages) ) {
|
414 |
+
$this->error = __('Problem communicating with Tumblr, retrying later','tumblr-importer');
|
415 |
+
return;
|
416 |
+
}
|
417 |
+
|
418 |
+
if ( is_array($imported_pages) && !empty($imported_pages) ) {
|
419 |
+
reset($imported_pages);
|
420 |
+
$post = current($imported_pages);
|
421 |
+
do {
|
422 |
+
// skip dupes
|
423 |
+
if ( !empty( $dupes[$post['tumblr_url']] ) ) {
|
424 |
+
continue;
|
425 |
+
}
|
426 |
+
|
427 |
+
$post['post_type'] = 'page';
|
428 |
+
$post['post_status'] = 'publish';
|
429 |
+
$post['post_author'] = $this->blog[$url]['post_author'];
|
430 |
+
|
431 |
+
$id = wp_insert_post( $post );
|
432 |
+
if ( !is_wp_error( $id ) ) {
|
433 |
+
add_post_meta( $id, 'tumblr_'.$this->blog[$url]['name'].'_permalink', $post['tumblr_url'] );
|
434 |
+
$post['ID'] = $id;
|
435 |
+
$this->handle_sideload($post);
|
436 |
+
}
|
437 |
+
|
438 |
+
$this->blog[$url]['pages_complete']++;
|
439 |
+
$this->save_vars();
|
440 |
+
} while ( false != ($post = next($imported_pages) ) );
|
441 |
+
}
|
442 |
+
$this->blog[$url]['progress'] = 'finish';
|
443 |
+
}
|
444 |
+
|
445 |
+
function handle_sideload_import($post, $source, $description = '', $filename = false) {
|
446 |
+
// Make a HEAD request to get the filename:
|
447 |
+
if ( empty($filename) ) {
|
448 |
+
$head = wp_remote_request( $source, array('method' => 'HEAD') );
|
449 |
+
if ( !empty($head['headers']['location']) ) {
|
450 |
+
$source = $head['headers']['location'];
|
451 |
+
$filename = preg_replace('!\?.*!', '', basename($source) ); // Strip off the Query vars
|
452 |
+
}
|
453 |
+
}
|
454 |
+
|
455 |
+
// still empty? Darned inconsistent tumblr...
|
456 |
+
if ( empty($filename) ) {
|
457 |
+
$path = parse_url($source,PHP_URL_PATH);
|
458 |
+
$filename = basename($path);
|
459 |
+
}
|
460 |
+
|
461 |
+
// Download file to temp location
|
462 |
+
$tmp = download_url( $source );
|
463 |
+
if ( is_wp_error($tmp) )
|
464 |
+
return $tmp;
|
465 |
+
|
466 |
+
$file_array['name'] = !empty($filename) ? $filename : basename($tmp);
|
467 |
+
$file_array['tmp_name'] = $tmp;
|
468 |
+
// do the validation and storage stuff
|
469 |
+
$id = media_handle_sideload( $file_array, $post['ID'], $description, array( 'post_excerpt' => $description ) );
|
470 |
+
|
471 |
+
if ( $id && ! is_wp_error($id) ) {
|
472 |
+
// Update the date/time on the attachment to that of the Tumblr post.
|
473 |
+
$attachment = get_post($id, ARRAY_A);
|
474 |
+
foreach ( array('post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt') as $field ) {
|
475 |
+
if ( isset($post[ $field]) )
|
476 |
+
$attachment[ $field ] = $post[ $field ];
|
477 |
+
}
|
478 |
+
wp_update_post($attachment);
|
479 |
+
}
|
480 |
+
|
481 |
+
// If error storing permanently, unlink
|
482 |
+
if ( is_wp_error($id) )
|
483 |
+
@unlink($file_array['tmp_name']);
|
484 |
+
return $id;
|
485 |
+
}
|
486 |
+
|
487 |
+
function handle_sideload($post) {
|
488 |
+
|
489 |
+
if ( empty( $post['format'] ) )
|
490 |
+
return; // Nothing to import.
|
491 |
+
|
492 |
+
switch ( $post['format'] ) {
|
493 |
+
case 'gallery':
|
494 |
+
if ( !empty( $post['gallery'] ) ) {
|
495 |
+
foreach ( $post['gallery'] as $i => $photo ) {
|
496 |
+
$id = $this->handle_sideload_import( $post, (string)$photo['src'], (string)$photo['caption']);
|
497 |
+
if ( is_wp_error($id) )
|
498 |
+
return $id;
|
499 |
+
}
|
500 |
+
$post['post_content'] = "[gallery]\n" . $post['post_content'];
|
501 |
+
wp_update_post($post);
|
502 |
+
break; // If we processed a gallery, break, otherwise let it fall through to the Image handler
|
503 |
+
}
|
504 |
+
|
505 |
+
case 'image':
|
506 |
+
if ( isset( $post['media']['src'] ) ) {
|
507 |
+
$id = $this->handle_sideload_import( $post, (string)$post['media']['src'], (string)$post['post_title']);
|
508 |
+
if ( is_wp_error($id) )
|
509 |
+
return $id;
|
510 |
+
|
511 |
+
$link = !empty($post['media']['link']) ? $post['media']['link'] : null;
|
512 |
+
// image_send_to_editor has a filter to wrap in a shortcode.
|
513 |
+
$post['post_content'] = get_image_send_to_editor($id, (string)$post['post_title'], (string)$post['post_title'], 'none', $link, true, 'large' );
|
514 |
+
//$post['post_content'] .= "\n" . $post['post_content']; // the [caption] shortcode doesn't allow HTML, but this might have some extra markup
|
515 |
+
wp_update_post($post);
|
516 |
+
}
|
517 |
+
|
518 |
+
break;
|
519 |
+
|
520 |
+
case 'audio':
|
521 |
+
// Handle Tumblr Hosted Audio
|
522 |
+
if ( isset( $post['media']['audio'] ) ) {
|
523 |
+
$id = $this->handle_sideload_import( $post, (string)$post['media']['audio'], $post['post_title'], (string)$post['media']['filename'] );
|
524 |
+
if ( is_wp_error($id) )
|
525 |
+
return $id;
|
526 |
+
$post['post_content'] = wp_get_attachment_link($id) . "\n" . $post['post_content'];
|
527 |
+
wp_update_post($post);
|
528 |
+
}
|
529 |
+
break;
|
530 |
+
|
531 |
+
case 'video':
|
532 |
+
// Handle Tumblr hosted video
|
533 |
+
if ( isset( $post['media']['video'] ) ) {
|
534 |
+
$id = $this->handle_sideload_import( $post, (string)$post['media']['video'], $post['post_title'], (string)$post['media']['filename'] );
|
535 |
+
if ( is_wp_error($id) )
|
536 |
+
return $id;
|
537 |
+
|
538 |
+
// @TODO: Check/change this to embed the imported video.
|
539 |
+
$post['post_content'] = wp_get_attachment_link($id) . "\n" . $post['post_content'];
|
540 |
+
wp_update_post($post);
|
541 |
+
}
|
542 |
+
// Else, Check to see if the url embedded is handled by oEmbed (or not)
|
543 |
+
break;
|
544 |
+
}
|
545 |
+
|
546 |
+
return true; // all processed
|
547 |
+
}
|
548 |
+
|
549 |
+
/**
|
550 |
+
* Fetch a list of blogs for a user
|
551 |
+
*
|
552 |
+
* @param $email
|
553 |
+
* @param $password
|
554 |
+
* @returns array of blog info or a WP_Error
|
555 |
+
*/
|
556 |
+
function get_blogs($email, $password) {
|
557 |
+
$url = 'http://www.tumblr.com/api/authenticate';
|
558 |
+
|
559 |
+
$params = array(
|
560 |
+
'email'=>$email,
|
561 |
+
'password'=>$password,
|
562 |
+
);
|
563 |
+
$options = array( 'body' => $params );
|
564 |
+
|
565 |
+
// fetch the list
|
566 |
+
$out = wp_remote_post($url,$options);
|
567 |
+
if (wp_remote_retrieve_response_code($out) != 200) {
|
568 |
+
return new WP_Error('tumblr_error', __('Tumblr replied with an error: ', 'tumblr-importer' ) . wp_remote_retrieve_body($out));
|
569 |
+
}
|
570 |
+
$body = wp_remote_retrieve_body($out);
|
571 |
+
|
572 |
+
// parse the XML into something useful
|
573 |
+
$xml = simplexml_load_string($body);
|
574 |
+
|
575 |
+
$blogs = array();
|
576 |
+
|
577 |
+
if (!isset($xml->tumblelog)) new WP_Error('tumblr_error', __('No blog information found for this account. ', 'tumblr-importer' ));
|
578 |
+
|
579 |
+
$tblogs = $xml->tumblelog;
|
580 |
+
foreach ($tblogs as $tblog) {
|
581 |
+
$blog = array();
|
582 |
+
|
583 |
+
if ((string) $tblog['is-admin'] != '1') continue; // we'll only allow admins to import their blogs
|
584 |
+
|
585 |
+
$blog['title'] = (string) $tblog['title'];
|
586 |
+
$blog['posts'] = (int) $tblog['posts'];
|
587 |
+
$blog['drafts'] = (int) $tblog['draft-count'];
|
588 |
+
$blog['queued'] = (int) $tblog['queue-count'];
|
589 |
+
$blog['avatar'] = (string) $tblog['avatar-url'];
|
590 |
+
$blog['url'] = (string) $tblog['url'];
|
591 |
+
$blog['name'] = (string) $tblog['name'];
|
592 |
+
|
593 |
+
$blogs[] = $blog;
|
594 |
+
}
|
595 |
+
|
596 |
+
return $blogs;
|
597 |
+
}
|
598 |
+
|
599 |
+
/**
|
600 |
+
* Fetch a subset of posts from a tumblr blog
|
601 |
+
*
|
602 |
+
* @param $start index to start at
|
603 |
+
* @param $count how many posts to get (max 50)
|
604 |
+
* @param $state can be empty for normal posts, or "draft", "queue", or "submission" to get those posts
|
605 |
+
* @returns false on error, array of posts on success
|
606 |
+
*/
|
607 |
+
function fetch_posts($url, $start=0, $count = 50, $email = null, $password = null, $state = null) {
|
608 |
+
$url = trailingslashit($url).'api/read';
|
609 |
+
$params = array(
|
610 |
+
'start'=>$start,
|
611 |
+
'num'=>$count,
|
612 |
+
);
|
613 |
+
if ( !empty($email) && !empty($password) ) {
|
614 |
+
$params['email'] = $email;
|
615 |
+
$params['password'] = $password;
|
616 |
+
}
|
617 |
+
|
618 |
+
if ( !empty($state) ) $params['state'] = $state;
|
619 |
+
|
620 |
+
$options = array( 'body' => $params );
|
621 |
+
|
622 |
+
// fetch the posts
|
623 |
+
$out = wp_remote_post($url,$options);
|
624 |
+
if (wp_remote_retrieve_response_code($out) != 200) return false;
|
625 |
+
$body = wp_remote_retrieve_body($out);
|
626 |
+
|
627 |
+
// parse the XML into something useful
|
628 |
+
$xml = simplexml_load_string($body);
|
629 |
+
|
630 |
+
if (!isset($xml->posts->post)) return false;
|
631 |
+
|
632 |
+
$tposts = $xml->posts;
|
633 |
+
$posts = array();
|
634 |
+
foreach($tposts->post as $tpost) {
|
635 |
+
$post = array();
|
636 |
+
$post['tumblr_id'] = (string) $tpost['id'];
|
637 |
+
$post['tumblr_url'] = (string) $tpost['url-with-slug'];
|
638 |
+
$post['post_date'] = date( 'Y-m-d H:i:s', strtotime ( (string) $tpost['date'] ) );
|
639 |
+
$post['post_date_gmt'] = date( 'Y-m-d H:i:s', strtotime ( (string) $tpost['date-gmt'] ) );
|
640 |
+
$post['post_name'] = (string) $tpost['slug'];
|
641 |
+
if ( isset($tpost['private']) ) $post['private'] = (string) $tpost['private'];
|
642 |
+
if ( isset($tpost->{'tag'}) ) {
|
643 |
+
$post['tags_input'] = array();
|
644 |
+
foreach ( $tpost->{'tag'} as $tag )
|
645 |
+
$post['tags_input'][] = rtrim( (string) $tag, ','); // Strip trailing Commas off it too.
|
646 |
+
}
|
647 |
+
|
648 |
+
// set the various post info for each special format tumblr offers
|
649 |
+
// TODO reorg this as needed
|
650 |
+
switch ((string) $tpost['type']) {
|
651 |
+
case 'photo':
|
652 |
+
$post['format'] = 'image';
|
653 |
+
$post['media']['src'] = (string) $tpost->{'photo-url'}[0];
|
654 |
+
$post['media']['link'] =(string) $tpost->{'photo-link-url'};
|
655 |
+
$post['media']['width'] = (string) $tpost['width'];
|
656 |
+
$post['media']['height'] = (string) $tpost['height'];
|
657 |
+
$post['post_content'] = (string) $tpost->{'photo-caption'};
|
658 |
+
if ( !empty( $tpost->{'photoset'} ) ) {
|
659 |
+
$post['format'] = 'gallery';
|
660 |
+
foreach ( $tpost->{'photoset'}->{'photo'} as $photo ) {
|
661 |
+
$post['gallery'][] = array (
|
662 |
+
'src'=>$photo->{'photo-url'}[0],
|
663 |
+
'width'=>$photo['width'],
|
664 |
+
'height'=>$photo['height'],
|
665 |
+
'caption'=>$photo['caption'],
|
666 |
+
);
|
667 |
+
}
|
668 |
+
}
|
669 |
+
break;
|
670 |
+
case 'quote':
|
671 |
+
$post['format'] = 'quote';
|
672 |
+
$post['post_content'] = (string) $tpost->{'quote-text'};
|
673 |
+
$post['post_title'] = (string) $tpost->{'quote-source'};
|
674 |
+
break;
|
675 |
+
case 'link':
|
676 |
+
$post['format'] = 'link';
|
677 |
+
$linkurl = (string) $tpost->{'link-url'};
|
678 |
+
$linktext = (string) $tpost->{'link-text'};
|
679 |
+
$post['post_content'] = "<a href='{$linkurl}'>{$linktext}</a>";
|
680 |
+
$post['post_title'] = (string) $tpost->{'link-description'};
|
681 |
+
break;
|
682 |
+
case 'conversation':
|
683 |
+
$post['format'] = 'chat';
|
684 |
+
$post['post_title'] = (string) $tpost->{'conversation-title'};
|
685 |
+
$post['post_content'] = (string) $tpost->{'conversation-text'};
|
686 |
+
break;
|
687 |
+
case 'audio':
|
688 |
+
$post['format'] = 'audio';
|
689 |
+
$post['media']['filename'] = basename( (string) $tpost->{'authorized-download-url'} ) . '.mp3';
|
690 |
+
$post['media']['audio'] = (string) $tpost->{'authorized-download-url'} .'?plead=please-dont-download-this-or-our-lawyers-wont-let-us-host-audio';
|
691 |
+
$post['post_content'] = (string) $tpost->{'audio-player'} . "\n" . (string) $tpost->{'audio-caption'};
|
692 |
+
if ( !empty($tpost->{'id3-artist'}) )
|
693 |
+
$post['post_title'] = $tpost->{'id3-artist'} . ' - ' . $tpost->{'id3-title'};
|
694 |
+
break;
|
695 |
+
case 'video':
|
696 |
+
$post['format'] = 'video';
|
697 |
+
$post['post_content'] = '';
|
698 |
+
if ( is_serialized( (string) $tpost->{'video-source'} ) ) {
|
699 |
+
if ( preg_match('|\'(http://.*video_file.*)\'|U', $tpost->{'video-player'}[0], $matches) ) {
|
700 |
+
$post['media']['video'] = $matches[1];
|
701 |
+
$val = unserialize( (string) $tpost->{'video-source'} );
|
702 |
+
$vidmeta = $val['o1'];
|
703 |
+
$post['media']['filename'] = basename($post['media']['video']) . '.' . $vidmeta['extension'];
|
704 |
+
$post['media']['width'] = $vidmeta['width'];
|
705 |
+
$post['media']['height'] = $vidmeta['height'];
|
706 |
+
}
|
707 |
+
} else if ( false !== strpos( (string) $tpost->{'video-source'}, 'embed' ) ) {
|
708 |
+
if ( preg_match_all('/<embed (.+?)>/', (string) $tpost->{'video-source'}, $matches) ) {
|
709 |
+
foreach ($matches[1] as $match) {
|
710 |
+
foreach ( wp_kses_hair($match, array('http')) as $attr)
|
711 |
+
$embed[$attr['name']] = $attr['value'];
|
712 |
+
}
|
713 |
+
|
714 |
+
// special case for weird youtube vids
|
715 |
+
$embed['src'] = preg_replace('|http://www.youtube.com/v/([a-zA-Z0-9_]+).*|i', 'http://www.youtube.com/watch?v=$1', $embed['src']);
|
716 |
+
|
717 |
+
// TODO find other special cases, since tumblr is full of them
|
718 |
+
|
719 |
+
$post['post_content'] = $embed['src'];
|
720 |
+
}
|
721 |
+
|
722 |
+
} else {
|
723 |
+
// @todo: See if the video-source is going to be oEmbed'able before adding the flash player
|
724 |
+
// 1 Seems to be "original" size, with 0 being set otherwise.
|
725 |
+
$post['post_content'] .= isset($tpost->{'video-player'}[1]) ? $tpost->{'video-player'}[1] : (string) $tpost->{'video-player'}[0];
|
726 |
+
$post['post_content'] .= (string) $tpost->{'video-source'};
|
727 |
+
}
|
728 |
+
$post['post_content'] .= "\n" . (string) $tpost->{'video-caption'};
|
729 |
+
break;
|
730 |
+
case 'answer':
|
731 |
+
$post['post_title'] = (string) $tpost->{'question'};
|
732 |
+
$post['post_content'] = (string) $tpost->{'answer'};
|
733 |
+
break;
|
734 |
+
case 'regular':
|
735 |
+
default:
|
736 |
+
$post['post_title'] = (string) $tpost->{'regular-title'};
|
737 |
+
$post['post_content'] = (string) $tpost->{'regular-body'};
|
738 |
+
break;
|
739 |
+
}
|
740 |
+
$posts[] = $post;
|
741 |
+
}
|
742 |
+
|
743 |
+
return $posts;
|
744 |
+
}
|
745 |
+
|
746 |
+
/**
|
747 |
+
* Fetch the Pages from a tumblr blog
|
748 |
+
*
|
749 |
+
* @returns false on error, array of page contents on success
|
750 |
+
*/
|
751 |
+
function fetch_pages($url, $email = null, $password = null) {
|
752 |
+
$tumblrurl = trailingslashit($url).'api/pages';
|
753 |
+
$params = array(
|
754 |
+
'email'=>$email,
|
755 |
+
'password'=>$password,
|
756 |
+
);
|
757 |
+
$options = array( 'body' => $params );
|
758 |
+
|
759 |
+
// fetch the pages
|
760 |
+
$out = wp_remote_post($tumblrurl,$options);
|
761 |
+
if (wp_remote_retrieve_response_code($out) != 200) return false;
|
762 |
+
$body = wp_remote_retrieve_body($out);
|
763 |
+
|
764 |
+
// parse the XML into something useful
|
765 |
+
$xml = simplexml_load_string($body);
|
766 |
+
|
767 |
+
if (!isset($xml->pages)) return false;
|
768 |
+
|
769 |
+
$tpages = $xml->pages;
|
770 |
+
$pages = array();
|
771 |
+
foreach($tpages->page as $tpage) {
|
772 |
+
if ( !empty($tpage['title']) )
|
773 |
+
$page['post_title'] = (string) $tpage['title'];
|
774 |
+
else if (!empty($tpage['link-title']) )
|
775 |
+
$page['post_title'] = (string) $tpage['link-title'];
|
776 |
+
else
|
777 |
+
$page['post_title'] = '';
|
778 |
+
$page['post_name'] = str_replace( $url, '', (string) $tpage['url'] );
|
779 |
+
$page['post_content'] = (string) $tpage;
|
780 |
+
$page['tumblr_url'] = (string) $tpage['url'];
|
781 |
+
$pages[] = $page;
|
782 |
+
}
|
783 |
+
|
784 |
+
return $pages;
|
785 |
+
}
|
786 |
+
}
|
787 |
+
}
|