mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-74567 core: re-factor flickr libraries to use shared user-agent.
This commit is contained in:
parent
c4f95593a9
commit
8f375b3923
2 changed files with 23 additions and 7 deletions
|
@ -60,19 +60,31 @@ class flickr_client extends oauth_helper {
|
||||||
* @param moodle_url|string $callbackurl
|
* @param moodle_url|string $callbackurl
|
||||||
*/
|
*/
|
||||||
public function __construct($consumerkey, $consumersecret, $callbackurl = '') {
|
public function __construct($consumerkey, $consumersecret, $callbackurl = '') {
|
||||||
global $CFG;
|
|
||||||
$version = moodle_major_version();
|
|
||||||
$useragent = "MoodleSite/$version (+{$CFG->wwwroot})";
|
|
||||||
|
|
||||||
parent::__construct([
|
parent::__construct([
|
||||||
'api_root' => self::OAUTH_ROOT,
|
'api_root' => self::OAUTH_ROOT,
|
||||||
'oauth_consumer_key' => $consumerkey,
|
'oauth_consumer_key' => $consumerkey,
|
||||||
'oauth_consumer_secret' => $consumersecret,
|
'oauth_consumer_secret' => $consumersecret,
|
||||||
'oauth_callback' => $callbackurl,
|
'oauth_callback' => $callbackurl,
|
||||||
'http_options' => ['CURLOPT_USERAGENT' => $useragent]
|
'http_options' => [
|
||||||
|
'CURLOPT_USERAGENT' => static::user_agent(),
|
||||||
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return User-Agent string suitable for calls to Flickr endpoint, avoiding problems caused by the string returned by
|
||||||
|
* the {@see core_useragent::get_moodlebot_useragent} helper, which is often rejected due to presence of "Bot" within
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function user_agent(): string {
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
|
$version = moodle_major_version();
|
||||||
|
|
||||||
|
return "MoodleSite/{$version} (+{$CFG->wwwroot})";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Temporarily store the request token secret in the session.
|
* Temporarily store the request token secret in the session.
|
||||||
*
|
*
|
||||||
|
|
|
@ -32,6 +32,11 @@
|
||||||
* @subpackage 3rd-party
|
* @subpackage 3rd-party
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
global $CFG;
|
||||||
|
require_once("{$CFG->libdir}/flickrclient.php");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flickr Class
|
* Flickr Class
|
||||||
* @package moodlecore
|
* @package moodlecore
|
||||||
|
@ -81,9 +86,8 @@ class phpFlickr {
|
||||||
|
|
||||||
// Initialize curl helper, set custom user agent as Flickr blocks our "MoodleBot" agent string.
|
// Initialize curl helper, set custom user agent as Flickr blocks our "MoodleBot" agent string.
|
||||||
$this->curl = new curl(array('cache'=>true, 'module_cache'=>'repository'));
|
$this->curl = new curl(array('cache'=>true, 'module_cache'=>'repository'));
|
||||||
$version = moodle_major_version();
|
|
||||||
$this->curl->setopt([
|
$this->curl->setopt([
|
||||||
'CURLOPT_USERAGENT' => "MoodleSite/$version (+{$CFG->wwwroot})"
|
'CURLOPT_USERAGENT' => flickr_client::user_agent(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue