Skip to content

Commit

Permalink
MDL-76230 block_tag_flickr: Change User-agent value for API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
HuongNV13 committed Nov 14, 2022
1 parent 40c641e commit 0bfa6e4
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions blocks/tag_flickr/block_tag_flickr.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -102,7 +105,11 @@ function get_content() {

$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'];
Expand All @@ -123,7 +130,11 @@ function get_content() {

$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']);
}

Expand All @@ -147,6 +158,10 @@ function get_content() {

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);

Expand Down

0 comments on commit 0bfa6e4

Please sign in to comment.