fix not using `file_get_contents` to get remote files

This commit is contained in:
vnmedeiros 2022-05-18 18:11:02 -03:00
parent 6199f89209
commit a7de746a6c
4 changed files with 41 additions and 14 deletions

View File

@ -1383,7 +1383,12 @@ class REST_Items_Controller extends REST_Controller {
], 400);
}
$secret_key = get_option("tnc_option_recaptch_secret_key");
$response = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secret_key&response=".$captcha_data."&remoteip=".$_SERVER['REMOTE_ADDR']));
$api_url = "https://www.google.com/recaptcha/api/siteverify?secret=$secret_key&response=".$captcha_data."&remoteip=".$_SERVER['REMOTE_ADDR'];
$response = wp_remote_get( $api_url );
$body = wp_remote_retrieve_body( $response );
$response = json_decode($body);
if ($response->success) {
return true;
} else {

View File

@ -188,7 +188,9 @@ class Flickr_Importer extends Importer {
$this->add_log('url ' . $api_url);
$json = json_decode(file_get_contents($api_url));
$response = wp_remote_get( $api_url );
$body = wp_remote_retrieve_body( $response );
$json = json_decode($body);
if( $json && isset($json->photoset) ){
return $json;
}
@ -203,7 +205,10 @@ class Flickr_Importer extends Importer {
$this->add_log('url ' . $api_url);
$json = json_decode(file_get_contents($api_url));
$response = wp_remote_get( $api_url );
$body = wp_remote_retrieve_body( $response );
$json = json_decode($body);
if( $json && isset($json->photos) ){
return $json;
@ -218,7 +223,9 @@ class Flickr_Importer extends Importer {
$this->add_log('url ' . $api_url);
$json = json_decode(file_get_contents($api_url));
$response = wp_remote_get( $api_url );
$body = wp_remote_retrieve_body( $response );
$json = json_decode($body);
if( $json && isset($json->photo) ){
return $json;
@ -428,8 +435,9 @@ class Flickr_Importer extends Importer {
. $id . $this->format;
$this->add_log('url ' . $api_url);
$json = json_decode(file_get_contents($api_url));
$response = wp_remote_get( $api_url );
$body = wp_remote_retrieve_body( $response );
$json = json_decode($body);
if( $json && isset($json->photo) ){
return $json;

View File

@ -649,8 +649,10 @@ class Test_Importer extends Importer {
$keyword = ( $this->get_option('keyword_images') ) ? $this->get_option('keyword_images') : '';
$url = "https://loremflickr.com/$horizontal_size/$vertical_size/$keyword";
$response = wp_remote_get( $url );
$content = wp_remote_retrieve_body( $response );
$id = $TainacanMedia->insert_attachment_from_blob(file_get_contents($url), time() . '.jpg', $inserted_item->get_id());
$id = $TainacanMedia->insert_attachment_from_blob($content, time() . '.jpg', $inserted_item->get_id());
if(!$id){
$this->add_error_log('Error in imported URL ' . $url);

View File

@ -231,7 +231,9 @@ class Youtube_Importer extends Importer {
$api_url = 'https://www.googleapis.com/youtube/v3/channels?part=statistics,snippet,contentDetails&id='
. $id . '&key=' . $api_key;
$json = json_decode(file_get_contents($api_url));
$response = wp_remote_get( $api_url );
$body = wp_remote_retrieve_body( $response );
$json = json_decode($body);
if( $json && isset($json->items) ){
$item = $json->items[0];
@ -239,7 +241,9 @@ class Youtube_Importer extends Importer {
. $pageToken . '&maxResults=1&playlistId='
. $item->contentDetails->relatedPlaylists->uploads . '&key=' . $api_key;
$json = json_decode(file_get_contents($api_url));
$response = wp_remote_get( $api_url );
$body = wp_remote_retrieve_body( $response );
$json = json_decode($body);
if( $json && isset($json->items) ){
return $json;
@ -251,8 +255,10 @@ class Youtube_Importer extends Importer {
case 'user':
$api_url = 'https://www.googleapis.com/youtube/v3/channels?part=statistics,snippet,contentDetails&forUsername='
. $id . '&key=' . $api_key;
$json = json_decode(file_get_contents($api_url));
$response = wp_remote_get( $api_url );
$body = wp_remote_retrieve_body( $response );
$json = json_decode($body);
if( $json && isset($json->items) ){
$item = $json->items[0];
@ -260,7 +266,9 @@ class Youtube_Importer extends Importer {
. $pageToken . '&maxResults=1&playlistId='
. $item->contentDetails->relatedPlaylists->uploads . '&key=' . $api_key;
$json = json_decode(file_get_contents($api_url));
$response = wp_remote_get( $api_url );
$body = wp_remote_retrieve_body( $response );
$json = json_decode($body);
if( $json && isset($json->items) ){
return $json;
@ -274,7 +282,9 @@ class Youtube_Importer extends Importer {
. $pageToken . '&maxResults=1&playlistId='
. $id . '&key=' . $api_key;
$json = json_decode(file_get_contents($api_url));
$response = wp_remote_get( $api_url );
$body = wp_remote_retrieve_body( $response );
$json = json_decode($body);
if( $json && isset($json->items) ){
return $json;
@ -285,7 +295,9 @@ class Youtube_Importer extends Importer {
$api_url = 'https://www.googleapis.com/youtube/v3/videos?part=snippet%2CcontentDetails&maxResults=1&id='
. $id . '&key=' . $api_key;
$json = json_decode(file_get_contents($api_url));
$response = wp_remote_get( $api_url );
$body = wp_remote_retrieve_body( $response );
$json = json_decode($body);
if( $json && isset($json->items) ){
return $json;