Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 39 and 402]

Provides {@link flickr_client} class.

Copyright: 2017 David Mudrák <david@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 282 lines (10 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

flickr_client:: (8 methods):
  __construct()
  user_agent()
  set_request_token_secret()
  get_request_token_secret()
  call()
  get_photo_url()
  upload()
  reset_state()


Class: flickr_client  - X-Ref

Simple Flickr API client implementing the features needed by Moodle

__construct($consumerkey, $consumersecret, $callbackurl = '')   X-Ref
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.

param: string $consumerkey
param: string $consumersecret
param: moodle_url|string $callbackurl

user_agent()   X-Ref
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

set_request_token_secret(array $identifiers, $secret)   X-Ref
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.

param: array $identifiers Identification of the call
param: string $secret

get_request_token_secret(array $identifiers)   X-Ref
Returns previously stored request token secret.

See {@link self::set_request_token_secret()} for more details on the
$identifiers argument.

param: array $identifiers Identification of the call
return: string|bool False on error, string secret otherwise.

call($function, array $params = [], $method = 'GET')   X-Ref
Call a Flickr API method.

param: string $function API function name like 'flickr.photos.getSizes' or just 'photos.getSizes'
param: array $params Additional API call arguments.
param: string $method HTTP method to use (GET or POST).
return: object|bool Response as returned by the Flickr or false on invalid authentication

get_photo_url($photoid)   X-Ref
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.

param: string $photoid Flickr photo identifier
return: string URL

upload(stored_file $photo, array $meta = [])   X-Ref
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 {@link https://www.flickr.com/services/api/upload.api.html}.

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.

param: stored_file $photo stored in Moodle file pool
param: array $meta optional meta information
return: int|bool photo id, false on authentication failure

reset_state()   X-Ref
Resets curl state.

return: void