From 02300131b72fd873546ae67ce1b17c35a4d8a4d6 Mon Sep 17 00:00:00 2001 From: Huong Nguyen Date: Tue, 19 Mar 2024 09:47:29 +0700 Subject: [PATCH] MDL-77255 block_tag_flickr: Update to match with the new API Flickr dropped php_serial format, we need to change to JSON format --- blocks/tag_flickr/block_tag_flickr.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/blocks/tag_flickr/block_tag_flickr.php b/blocks/tag_flickr/block_tag_flickr.php index 30aec42ec7d..df1efb42a9d 100644 --- a/blocks/tag_flickr/block_tag_flickr.php +++ b/blocks/tag_flickr/block_tag_flickr.php @@ -101,13 +101,14 @@ class block_tag_flickr extends block_base { $request .= '&api_key='.FLICKR_DEV_KEY; $request .= '&photoset_id='.$this->config->photoset; $request .= '&per_page='.$numberofphotos; - $request .= '&format=php_serial'; + $request .= '&format=json'; + // We need to add nojsoncallback=? here, otherwise, Flickr will return the jsonFlickrApi object. + $request .= '&nojsoncallback=?'; $response = $this->fetch_request($request); - - $search = @unserialize($response); - if ($search === false && $search != serialize(false)) { - // The response didn't appear to be anything serialized, exit... + $search = @json_decode($response, true); + if (!is_array($search) || json_last_error() !== JSON_ERROR_NONE) { + // The response didn't appear to be in correct format. return; } @@ -126,13 +127,14 @@ class block_tag_flickr extends block_base { $request .= '&tags='.$tagscsv; $request .= '&per_page='.$numberofphotos; $request .= '&sort='.$sortby; - $request .= '&format=php_serial'; + $request .= '&format=json'; + // We need to add nojsoncallback=? here, otherwise, Flickr will return the jsonFlickrApi object. + $request .= '&nojsoncallback=?'; $response = $this->fetch_request($request); - - $search = @unserialize($response); - if ($search === false && $search != serialize(false)) { - // The response didn't appear to be anything serialized, exit... + $search = @json_decode($response, true); + if (!is_array($search) || json_last_error() !== JSON_ERROR_NONE) { + // The response didn't appear to be in correct format. return; } $photos = array_values($search['photos']['photo']);