function get_file_curl($url, $fullpath, $to_variable = false, $iteration = false) { if (!preg_match('%^(http|ftp)s?://%i', $url)) { return; } $response = wp_remote_get($url); if (!is_wp_error($response) and (!isset($response['response']['code']) or isset($response['response']['code']) and !in_array($response['response']['code'], array(401, 403, 404)))) { $rawdata = wp_remote_retrieve_body($response); if (empty($rawdata)) { $result = pmxi_curl_download($url, $fullpath, $to_variable); if (!$result and $iteration === false) { $new_url = wp_all_import_translate_uri($url); return $new_url !== $url ? get_file_curl($new_url, $fullpath, $to_variable, true) : $result; } return $result; } if (!@file_put_contents($fullpath, $rawdata)) { $fp = fopen($fullpath, 'w'); fwrite($fp, $rawdata); fclose($fp); } if (preg_match('%\\W(svg)$%i', basename($fullpath)) or preg_match('%\\W(jpg|jpeg|gif|png)$%i', basename($fullpath)) and (!($image_info = apply_filters('pmxi_getimagesize', @getimagesize($fullpath), $fullpath)) or !in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG)))) { $result = pmxi_curl_download($url, $fullpath, $to_variable); if (!$result and $iteration === false) { $new_url = wp_all_import_translate_uri($url); return $new_url !== $url ? get_file_curl($new_url, $fullpath, $to_variable, true) : $result; } return $result; } return $to_variable ? $rawdata : true; } else { $curl = pmxi_curl_download($url, $fullpath, $to_variable); if ($curl === false and $iteration === false) { $new_url = wp_all_import_translate_uri($url); return $new_url !== $url ? get_file_curl($new_url, $fullpath, $to_variable, true) : (is_wp_error($response) ? $response : false); } return $curl === false ? is_wp_error($response) ? $response : false : $curl; } }
function get_file_curl($url, $fullpath, $to_variable = false, $iteration = 0) { if (!preg_match('%^(http|ftp)s?://%i', $url)) { return; } $request = wp_remote_get($url); if (!is_wp_error($request)) { $rawdata = wp_remote_retrieve_body($request); if (empty($rawdata)) { $result = pmxi_curl_download($url, $fullpath, $to_variable); if (!$result and !$iteration) { $url = wp_all_import_translate_uri($url); return get_file_curl($url, $fullpath, $to_variable, 1); } return $result; } if (!@file_put_contents($fullpath, $rawdata)) { $fp = fopen($fullpath, 'w'); fwrite($fp, $rawdata); fclose($fp); } if (preg_match('%\\W(jpg|jpeg|gif|png)$%i', basename($fullpath)) and (!($image_info = @getimagesize($fullpath)) or !in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG)))) { $result = pmxi_curl_download($url, $fullpath, $to_variable); if (!$result and !$iteration) { $url = wp_all_import_translate_uri($url); return get_file_curl($url, $fullpath, $to_variable, 1); } return $result; } return $to_variable ? $rawdata : true; } else { $curl = pmxi_curl_download($url, $fullpath, $to_variable); if ($curl === false and !$iteration) { $url = wp_all_import_translate_uri($url); return get_file_curl($url, $fullpath, $to_variable, 1); } return $curl === false ? $request : $curl; } }