107 } |
106 } |
108 } |
107 } |
109 } |
108 } |
110 } while ( count( $results ) == $limit ); |
109 } while ( count( $results ) == $limit ); |
111 |
110 |
112 // unset to save memory |
111 // Unset to save memory. |
113 unset( $results, $r ); |
112 unset( $results, $r ); |
114 |
113 |
115 return $hashtable; |
114 return $hashtable; |
116 } |
115 } |
117 |
116 |
118 function set_blog( $blog_id ) { |
117 public function set_blog( $blog_id ) { |
119 if ( is_numeric( $blog_id ) ) { |
118 if ( is_numeric( $blog_id ) ) { |
120 $blog_id = (int) $blog_id; |
119 $blog_id = (int) $blog_id; |
121 } else { |
120 } else { |
122 $blog = 'http://' . preg_replace( '#^https?://#', '', $blog_id ); |
121 $blog = 'http://' . preg_replace( '#^https?://#', '', $blog_id ); |
123 if ( ( !$parsed = parse_url( $blog ) ) || empty( $parsed['host'] ) ) { |
122 if ( ( !$parsed = parse_url( $blog ) ) || empty( $parsed['host'] ) ) { |
175 * @param string $username |
174 * @param string $username |
176 * @param string $password |
175 * @param string $password |
177 * @param bool $head |
176 * @param bool $head |
178 * @return array |
177 * @return array |
179 */ |
178 */ |
180 function get_page( $url, $username = '', $password = '', $head = false ) { |
179 public function get_page( $url, $username = '', $password = '', $head = false ) { |
181 // Increase the timeout |
180 // Increase the timeout |
182 add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) ); |
181 add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) ); |
183 |
182 |
184 $headers = array(); |
183 $headers = array(); |
185 $args = array(); |
184 $args = array(); |
197 * Bump up the request timeout for http requests |
196 * Bump up the request timeout for http requests |
198 * |
197 * |
199 * @param int $val |
198 * @param int $val |
200 * @return int |
199 * @return int |
201 */ |
200 */ |
202 function bump_request_timeout( $val ) { |
201 public function bump_request_timeout( $val ) { |
203 return 60; |
202 return 60; |
204 } |
203 } |
205 |
204 |
206 /** |
205 /** |
207 * Check if user has exceeded disk quota |
206 * Check if user has exceeded disk quota |
208 * |
207 * |
209 * @return bool |
208 * @return bool |
210 */ |
209 */ |
211 function is_user_over_quota() { |
210 public function is_user_over_quota() { |
212 if ( function_exists( 'upload_is_user_over_quota' ) ) { |
211 if ( function_exists( 'upload_is_user_over_quota' ) ) { |
213 if ( upload_is_user_over_quota( 1 ) ) { |
212 if ( upload_is_user_over_quota() ) { |
214 echo "Sorry, you have used your upload quota.\n"; |
213 echo "Sorry, you have used your upload quota.\n"; |
215 return true; |
214 return true; |
216 } |
215 } |
217 } |
216 } |
218 |
217 |
223 * Replace newlines, tabs, and multiple spaces with a single space |
222 * Replace newlines, tabs, and multiple spaces with a single space |
224 * |
223 * |
225 * @param string $string |
224 * @param string $string |
226 * @return string |
225 * @return string |
227 */ |
226 */ |
228 function min_whitespace( $string ) { |
227 public function min_whitespace( $string ) { |
229 return preg_replace( '|[\r\n\t ]+|', ' ', $string ); |
228 return preg_replace( '|[\r\n\t ]+|', ' ', $string ); |
230 } |
229 } |
231 |
230 |
232 /** |
231 /** |
233 * Reset global variables that grow out of control during imports |
232 * Reset global variables that grow out of control during imports |
234 * |
233 * |
235 * @return void |
234 * @return void |
236 */ |
235 */ |
237 function stop_the_insanity() { |
236 public function stop_the_insanity() { |
238 global $wpdb, $wp_actions; |
237 global $wpdb, $wp_actions; |
239 // Or define( 'WP_IMPORTING', true ); |
238 // Or define( 'WP_IMPORTING', true ); |
240 $wpdb->queries = array(); |
239 $wpdb->queries = array(); |
241 // Reset $wp_actions to keep it from growing out of control |
240 // Reset $wp_actions to keep it from growing out of control |
242 $wp_actions = array(); |
241 $wp_actions = array(); |
271 } else { |
270 } else { |
272 $out[$key] = true; |
271 $out[$key] = true; |
273 } |
272 } |
274 |
273 |
275 $last_arg = $key; |
274 $last_arg = $key; |
276 } else if ( (bool) preg_match( "/^-([a-zA-Z0-9]+)/", $args[$i], $match ) ) { |
275 } elseif ( (bool) preg_match( "/^-([a-zA-Z0-9]+)/", $args[$i], $match ) ) { |
277 for ( $j = 0, $jl = strlen( $match[1] ); $j < $jl; $j++ ) { |
276 for ( $j = 0, $jl = strlen( $match[1] ); $j < $jl; $j++ ) { |
278 $key = $match[1]{$j}; |
277 $key = $match[1]{$j}; |
279 $out[$key] = true; |
278 $out[$key] = true; |
280 } |
279 } |
281 |
280 |
282 $last_arg = $key; |
281 $last_arg = $key; |
283 } else if ( $last_arg !== null ) { |
282 } elseif ( $last_arg !== null ) { |
284 $out[$last_arg] = $args[$i]; |
283 $out[$last_arg] = $args[$i]; |
285 } |
284 } |
286 } |
285 } |
287 |
286 |
288 // Check array for specified param |
287 // Check array for specified param |