Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
flickr_client Class Reference

Simple Flickr API client implementing the features needed by Moodle. More...

Inheritance diagram for flickr_client:
oauth_helper

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.
 

Detailed Description

Simple Flickr API client implementing the features needed by Moodle.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

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.

Parameters
string$consumerkey
string$consumersecret
moodle_url | string$callbackurl

Member Function Documentation

◆ call()

flickr_client::call ( $function,
array $params = [],
$method = 'GET' )

Call a Flickr API method.

Parameters
string$functionAPI function name like 'flickr.photos.getSizes' or just 'photos.getSizes'
array$paramsAdditional API call arguments.
string$methodHTTP method to use (GET or POST).
Return values
object|boolResponse as returned by the Flickr or false on invalid authentication

◆ get_access_token()

oauth_helper::get_access_token ( $token,
$secret,
$verifier = '' )
inherited

Request oauth access token from server.

Parameters
string$method
string$url
string$token
string$secret

◆ get_photo_url()

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.

Parameters
string$photoidFlickr photo identifier
Return values
stringURL

◆ get_request_token_secret()

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.

Parameters
array$identifiersIdentification of the call
Return values
string|boolFalse on error, string secret otherwise.

◆ get_signable_parameters()

oauth_helper::get_signable_parameters ( $params)
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".

Parameters
array$param
Return values
string

◆ parse_result()

oauth_helper::parse_result ( $str)
inherited

A method to parse oauth response to get oauth_token and oauth_token_secret.

Parameters
string$str
Return values
array

◆ prepare_oauth_parameters()

oauth_helper::prepare_oauth_parameters ( $url,
$params,
$http_method = 'POST' )
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.

Parameters
string$url
string$token
string$http_method
Return values
array

◆ request()

oauth_helper::request ( $method,
$url,
$params = array(),
$token = '',
$secret = '' )
inherited

Request oauth protected resources.

Parameters
string$method
string$url
string$token
string$secret

◆ request_token()

oauth_helper::request_token ( )
inherited

Request token for authentication This is the first step to use OAuth, it will return oauth_token and oauth_token_secret.

Return values
array

◆ reset_state()

flickr_client::reset_state ( )

Resets curl state.

Return values
void

◆ set_access_token()

oauth_helper::set_access_token ( $token,
$secret )
inherited

Set oauth access token for oauth request.

Parameters
string$token
string$secret

◆ set_request_token_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.

Parameters
array$identifiersIdentification of the call
string$secret

◆ setup_oauth_http_options()

oauth_helper::setup_oauth_http_options ( $options)
inherited

Sets the options for the next curl request.

Parameters
array$options

◆ sign()

oauth_helper::sign ( $http_method,
$url,
$params,
$secret )
inherited

Create signature for oauth request.

Parameters
string$url
string$secret
array$params
Return values
string

◆ upload()

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.

Parameters
stored_file$photostored in Moodle file pool
array$metaoptional meta information
Return values
int|boolphoto id, false on authentication failure

◆ user_agent()

static flickr_client::user_agent ( )
static

Return User-Agent string suitable for calls to Flickr endpoint, avoiding problems caused by the string returned by the {.

See also
core_useragent\get_moodlebot_useragent} helper, which is often rejected due to presence of "Bot" within
Return values
string

The documentation for this class was generated from the following file: