diff --git a/blocks/tag_flickr/block_tag_flickr.php b/blocks/tag_flickr/block_tag_flickr.php index affb9dea587..30aec42ec7d 100644 --- a/blocks/tag_flickr/block_tag_flickr.php +++ b/blocks/tag_flickr/block_tag_flickr.php @@ -22,9 +22,12 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); define('FLICKR_DEV_KEY', '4fddbdd7ff2376beec54d7f6afad425e'); define('DEFAULT_NUMBER_OF_PHOTOS', 6); +require_once("{$CFG->libdir}/flickrclient.php"); + class block_tag_flickr extends block_base { function init() { @@ -102,7 +105,11 @@ class block_tag_flickr extends block_base { $response = $this->fetch_request($request); - $search = unserialize($response); + $search = @unserialize($response); + if ($search === false && $search != serialize(false)) { + // The response didn't appear to be anything serialized, exit... + return; + } foreach ($search['photoset']['photo'] as $p){ $p['owner'] = $search['photoset']['owner']; @@ -123,7 +130,11 @@ class block_tag_flickr extends block_base { $response = $this->fetch_request($request); - $search = unserialize($response); + $search = @unserialize($response); + if ($search === false && $search != serialize(false)) { + // The response didn't appear to be anything serialized, exit... + return; + } $photos = array_values($search['photos']['photo']); } @@ -147,6 +158,10 @@ class block_tag_flickr extends block_base { function fetch_request($request){ $c = new curl(array('cache' => true, 'module_cache'=> 'tag_flickr')); + // Set custom user agent as Flickr blocks our "MoodleBot" agent string. + $c->setopt([ + 'CURLOPT_USERAGENT' => flickr_client::user_agent(), + ]); $response = $c->get($request);