MDL-71481 repository_flickr_public: return more file data.

A HTTP HEAD request is required to get the image filesize.
The remaining data can be obtained from existing calls to
the Flickr API.
This commit is contained in:
Paul Holden
2021-04-29 08:24:15 +01:00
parent a5f0b354e7
commit 643b0ccabe

View File

@@ -304,6 +304,7 @@ class repository_flickr_public extends repository {
'user_id' => $nsid,
'license' => $licenses,
'text' => $text,
'extras' => 'original_format,license,date_upload,last_update',
'media' => 'photos'
)
);
@@ -328,7 +329,8 @@ class repository_flickr_public extends repository {
public function get_listing($path = '', $page = 1) {
$people = $this->flickr->people_findByEmail($this->flickr_account);
$this->nsid = $people['nsid'];
$photos = $this->flickr->people_getPublicPhotos($people['nsid'], 'original_format', 24, $page);
$photos = $this->flickr->people_getPublicPhotos($people['nsid'], 'original_format,license,date_upload,last_update',
24, $page);
$ret = array();
return $this->build_list($photos, $page, $ret);
@@ -382,16 +384,27 @@ class repository_flickr_public extends repository {
// displaying broken thumbnails in the repository.
$thumbnailsource = $OUTPUT->image_url(file_extension_icon($p['title'], 90))->out(false);
}
// Perform a HEAD request to the image to obtain it's Content-Length.
$curl = new curl();
$curl->head($this->get_link($p['id']));
// The photo sizes are statically cached, so we can retrieve image dimensions without another API call.
$bestsize = $this->get_best_size($p['id']);
$ret['list'][] = array(
'title' => $p['title'],
'source' => $p['id'],
'id' => $p['id'],
'thumbnail' => $thumbnailsource,
'date' => '',
'size' => 'unknown',
'datecreated' => $p['dateupload'],
'datemodified' => $p['lastupdate'],
'size' => (int)($curl->get_info()['download_content_length']),
'image_width' => $bestsize['width'],
'image_height' => $bestsize['height'],
'url' => 'http://www.flickr.com/photos/' . $p['owner'] . '/' . $p['id'],
'haslicense' => true,
'hasauthor' => true
'license' => $this->license4moodle($p['license']),
'author' => $p['owner'],
);
}
}