Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
|
Simple Flickr API client implementing the features needed by Moodle. More...
Public Member Functions | |
__construct ($consumerkey, $consumersecret, $callbackurl='') | |
Set up OAuth and initialize the client. | |
call ($function, array $params=[], $method='GET') | |
Call a Flickr API method. | |
get ($url, $params=array(), $token='', $secret='') | |
shortcut to start http get request | |
get_access_token ($token, $secret, $verifier='') | |
Request oauth access token from server. | |
get_nonce () | |
Generate nonce for oauth request. | |
get_photo_url ($photoid) | |
Return the URL to fetch the given photo from. | |
get_request_token_secret (array $identifiers) | |
Returns previously stored request token secret. | |
get_signable_parameters ($params) | |
Build parameters list: oauth_consumer_key="0685bd9184jfhq22", oauth_nonce="4572616e48616d6d65724c61686176", oauth_token="ad180jjd733klru7", oauth_signature_method="HMAC-SHA1", oauth_signature="wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D", oauth_timestamp="137131200", oauth_version="1.0" oauth_verifier="1.0". | |
get_timestamp () | |
Generate timestamp. | |
parse_result ($str) | |
A method to parse oauth response to get oauth_token and oauth_token_secret. | |
post ($url, $params=array(), $token='', $secret='') | |
shortcut to start http post request | |
prepare_oauth_parameters ($url, $params, $http_method='POST') | |
Initilize oauth request parameters, including: oauth_consumer_key="0685bd9184jfhq22", oauth_token="ad180jjd733klru7", oauth_signature_method="HMAC-SHA1", oauth_signature="wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D", oauth_timestamp="137131200", oauth_nonce="4572616e48616d6d65724c61686176", oauth_version="1.0" To access protected resources, oauth_token should be defined. | |
request ($method, $url, $params=array(), $token='', $secret='') | |
Request oauth protected resources. | |
request_token () | |
Request token for authentication This is the first step to use OAuth, it will return oauth_token and oauth_token_secret. | |
reset_state () | |
Resets curl state. | |
set_access_token ($token, $secret) | |
Set oauth access token for oauth request. | |
set_nonce ($str) | |
Set nonce. | |
set_request_token_secret (array $identifiers, $secret) | |
Temporarily store the request token secret in the session. | |
set_timestamp ($time) | |
Set timestamp. | |
setup_oauth_http_header ($params) | |
setup_oauth_http_options ($options) | |
Sets the options for the next curl request. | |
sign ($http_method, $url, $params, $secret) | |
Create signature for oauth request. | |
upload (stored_file $photo, array $meta=[]) | |
Upload a photo from Moodle file pool to Flickr. | |
Static Public Member Functions | |
static | user_agent () |
Return User-Agent string suitable for calls to Flickr endpoint, avoiding problems caused by the string returned by the {. | |
Public Attributes | |
const | OAUTH_ROOT = 'https://www.flickr.com/services/oauth' |
Base URL for Flickr OAuth 1.0 API calls. | |
const | REST_ROOT = 'https://api.flickr.com/services/rest' |
Base URL for Flickr REST API calls. | |
const | UPLOAD_ROOT = 'https://up.flickr.com/services/upload/' |
Base URL for Flickr Upload API call. | |
Protected Attributes | |
string | $access_token |
access token. | |
string | $access_token_api |
string | $access_token_secret |
access secret token. | |
string | $api_root |
oauth root | |
string | $authorize_url |
authorize url | |
string | $consumer_key |
consumer key, issued by oauth provider | |
string | $consumer_secret |
consumer secret, issued by oauth provider | |
curl | $http |
$http_method | |
array | $http_options |
options to pass to the next curl request | |
string | $nonce |
nonce. | |
moodle_url | $oauth_callback |
oauth callback URL. | |
string | $request_token_api |
request token url | |
string | $sign_secret |
sign secret. | |
int | $timestamp |
timestamp. | |
Simple Flickr API client implementing the features needed by Moodle.
flickr_client::__construct | ( | $consumerkey, | |
$consumersecret, | |||
$callbackurl = '' ) |
Set up OAuth and initialize the client.
The callback URL specified here will override the one specified in the auth flow defined at Flickr Services.
string | $consumerkey | |
string | $consumersecret | |
moodle_url | string | $callbackurl |
flickr_client::call | ( | $function, | |
array | $params = [], | ||
$method = 'GET' ) |
Call a Flickr API method.
string | $function | API function name like 'flickr.photos.getSizes' or just 'photos.getSizes' |
array | $params | Additional API call arguments. |
string | $method | HTTP method to use (GET or POST). |
object|bool | Response as returned by the Flickr or false on invalid authentication |
|
inherited |
Request oauth access token from server.
string | $method | |
string | $url | |
string | $token | |
string | $secret |
flickr_client::get_photo_url | ( | $photoid | ) |
Return the URL to fetch the given photo from.
Flickr photos are distributed via farm servers staticflickr.com in various sizes (resolutions). The method tries to find the source URL of the photo in the highest possible resolution. Results are cached so that we do not need to query the Flickr API over and over again.
string | $photoid | Flickr photo identifier |
string | URL |
flickr_client::get_request_token_secret | ( | array | $identifiers | ) |
Returns previously stored request token secret.
See self::set_request_token_secret() for more details on the $identifiers argument.
array | $identifiers | Identification of the call |
string|bool | False on error, string secret otherwise. |
|
inherited |
Build parameters list: oauth_consumer_key="0685bd9184jfhq22", oauth_nonce="4572616e48616d6d65724c61686176", oauth_token="ad180jjd733klru7", oauth_signature_method="HMAC-SHA1", oauth_signature="wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D", oauth_timestamp="137131200", oauth_version="1.0" oauth_verifier="1.0".
array | $param |
string |
|
inherited |
A method to parse oauth response to get oauth_token and oauth_token_secret.
string | $str |
array |
|
inherited |
Initilize oauth request parameters, including: oauth_consumer_key="0685bd9184jfhq22", oauth_token="ad180jjd733klru7", oauth_signature_method="HMAC-SHA1", oauth_signature="wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D", oauth_timestamp="137131200", oauth_nonce="4572616e48616d6d65724c61686176", oauth_version="1.0" To access protected resources, oauth_token should be defined.
string | $url | |
string | $token | |
string | $http_method |
array |
|
inherited |
Request oauth protected resources.
string | $method | |
string | $url | |
string | $token | |
string | $secret |
|
inherited |
Request token for authentication This is the first step to use OAuth, it will return oauth_token and oauth_token_secret.
array |
flickr_client::reset_state | ( | ) |
Resets curl state.
void |
|
inherited |
Set oauth access token for oauth request.
string | $token | |
string | $secret |
flickr_client::set_request_token_secret | ( | array | $identifiers, |
$secret ) |
Temporarily store the request token secret in the session.
The request token secret is returned by the oauth request_token method. It needs to be stored in the session before the user is redirected to the Flickr to authorize the client. After redirecting back, this secret is used for exchanging the request token with the access token.
The identifiers help to avoid collisions between multiple calls to this method from different plugins in the same session. They are used as the session cache identifiers. Provide an associative array identifying the particular method call. At least, the array must contain the 'caller' with the caller's component name. Use additional items if needed.
array | $identifiers | Identification of the call |
string | $secret |
|
inherited |
Sets the options for the next curl request.
array | $options |
|
inherited |
Create signature for oauth request.
string | $url | |
string | $secret | |
array | $params |
string |
flickr_client::upload | ( | stored_file | $photo, |
array | $meta = [] ) |
Upload a photo from Moodle file pool to Flickr.
Optional meta information are title, description, tags, is_public, is_friend, is_family, safety_level, content_type and hidden. See .
Upload can't be asynchronous because then the query would not return the photo ID which we need to add the photo to a photoset (album) eventually.
stored_file | $photo | stored in Moodle file pool |
array | $meta | optional meta information |
int|bool | photo id, false on authentication failure |
|
static |
Return User-Agent string suitable for calls to Flickr endpoint, avoiding problems caused by the string returned by the {.
string |