MDL-76230 block_tag_flickr: Change User-agent value for API calls

This commit is contained in:
Huong Nguyen
2022-11-14 09:35:29 +07:00
parent e4af35b9b8
commit 4fca1452d4
+17 -2
View File
@@ -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);