10 public function __construct() {} |
10 public function __construct() {} |
11 |
11 |
12 /** |
12 /** |
13 * Returns array with imported permalinks from WordPress database |
13 * Returns array with imported permalinks from WordPress database |
14 * |
14 * |
|
15 * @global wpdb $wpdb WordPress database abstraction object. |
|
16 * |
|
17 * @param string $importer_name |
15 * @param string $bid |
18 * @param string $bid |
16 * @return array |
19 * @return array |
17 */ |
20 */ |
18 public function get_imported_posts( $importer_name, $bid ) { |
21 public function get_imported_posts( $importer_name, $bid ) { |
19 global $wpdb; |
22 global $wpdb; |
24 $offset = 0; |
27 $offset = 0; |
25 |
28 |
26 // Grab all posts in chunks |
29 // Grab all posts in chunks |
27 do { |
30 do { |
28 $meta_key = $importer_name . '_' . $bid . '_permalink'; |
31 $meta_key = $importer_name . '_' . $bid . '_permalink'; |
29 $sql = $wpdb->prepare( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '%s' LIMIT %d,%d", $meta_key, $offset, $limit ); |
32 $sql = $wpdb->prepare( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s LIMIT %d,%d", $meta_key, $offset, $limit ); |
30 $results = $wpdb->get_results( $sql ); |
33 $results = $wpdb->get_results( $sql ); |
31 |
34 |
32 // Increment offset |
35 // Increment offset |
33 $offset = ( $limit + $offset ); |
36 $offset = ( $limit + $offset ); |
34 |
37 |
112 unset( $results, $r ); |
120 unset( $results, $r ); |
113 |
121 |
114 return $hashtable; |
122 return $hashtable; |
115 } |
123 } |
116 |
124 |
|
125 /** |
|
126 * |
|
127 * @param int $blog_id |
|
128 * @return int|void |
|
129 */ |
117 public function set_blog( $blog_id ) { |
130 public function set_blog( $blog_id ) { |
118 if ( is_numeric( $blog_id ) ) { |
131 if ( is_numeric( $blog_id ) ) { |
119 $blog_id = (int) $blog_id; |
132 $blog_id = (int) $blog_id; |
120 } else { |
133 } else { |
121 $blog = 'http://' . preg_replace( '#^https?://#', '', $blog_id ); |
134 $blog = 'http://' . preg_replace( '#^https?://#', '', $blog_id ); |
122 if ( ( !$parsed = parse_url( $blog ) ) || empty( $parsed['host'] ) ) { |
135 if ( ( !$parsed = parse_url( $blog ) ) || empty( $parsed['host'] ) ) { |
123 fwrite( STDERR, "Error: can not determine blog_id from $blog_id\n" ); |
136 fwrite( STDERR, "Error: can not determine blog_id from $blog_id\n" ); |
124 exit(); |
137 exit(); |
125 } |
138 } |
126 if ( empty( $parsed['path'] ) ) |
139 if ( empty( $parsed['path'] ) ) { |
127 $parsed['path'] = '/'; |
140 $parsed['path'] = '/'; |
128 $blog = get_blog_details( array( 'domain' => $parsed['host'], 'path' => $parsed['path'] ) ); |
141 } |
129 if ( !$blog ) { |
142 $blogs = get_sites( array( 'domain' => $parsed['host'], 'number' => 1, 'path' => $parsed['path'] ) ); |
|
143 if ( ! $blogs ) { |
130 fwrite( STDERR, "Error: Could not find blog\n" ); |
144 fwrite( STDERR, "Error: Could not find blog\n" ); |
131 exit(); |
145 exit(); |
132 } |
146 } |
|
147 $blog = array_shift( $blogs ); |
133 $blog_id = (int) $blog->blog_id; |
148 $blog_id = (int) $blog->blog_id; |
134 } |
149 } |
135 |
150 |
136 if ( function_exists( 'is_multisite' ) ) { |
151 if ( function_exists( 'is_multisite' ) ) { |
137 if ( is_multisite() ) |
152 if ( is_multisite() ) |
171 * GET URL |
191 * GET URL |
172 * |
192 * |
173 * @param string $url |
193 * @param string $url |
174 * @param string $username |
194 * @param string $username |
175 * @param string $password |
195 * @param string $password |
176 * @param bool $head |
196 * @param bool $head |
177 * @return array |
197 * @return array |
178 */ |
198 */ |
179 public function get_page( $url, $username = '', $password = '', $head = false ) { |
199 public function get_page( $url, $username = '', $password = '', $head = false ) { |
180 // Increase the timeout |
200 // Increase the timeout |
181 add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) ); |
201 add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) ); |
227 public function min_whitespace( $string ) { |
246 public function min_whitespace( $string ) { |
228 return preg_replace( '|[\r\n\t ]+|', ' ', $string ); |
247 return preg_replace( '|[\r\n\t ]+|', ' ', $string ); |
229 } |
248 } |
230 |
249 |
231 /** |
250 /** |
232 * Reset global variables that grow out of control during imports |
251 * Resets global variables that grow out of control during imports. |
233 * |
252 * |
234 * @return void |
253 * @since 3.0.0 |
|
254 * |
|
255 * @global wpdb $wpdb WordPress database abstraction object. |
|
256 * @global array $wp_actions |
235 */ |
257 */ |
236 public function stop_the_insanity() { |
258 public function stop_the_insanity() { |
237 global $wpdb, $wp_actions; |
259 global $wpdb, $wp_actions; |
238 // Or define( 'WP_IMPORTING', true ); |
260 // Or define( 'WP_IMPORTING', true ); |
239 $wpdb->queries = array(); |
261 $wpdb->queries = array(); |
245 /** |
267 /** |
246 * Returns value of command line params. |
268 * Returns value of command line params. |
247 * Exits when a required param is not set. |
269 * Exits when a required param is not set. |
248 * |
270 * |
249 * @param string $param |
271 * @param string $param |
250 * @param bool $required |
272 * @param bool $required |
251 * @return mixed |
273 * @return mixed |
252 */ |
274 */ |
253 function get_cli_args( $param, $required = false ) { |
275 function get_cli_args( $param, $required = false ) { |
254 $args = $_SERVER['argv']; |
276 $args = $_SERVER['argv']; |
255 |
277 |