From 643b0ccabed57ead6dbb2f8403c55a1426651f57 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 29 Apr 2021 08:24:15 +0100 Subject: [PATCH] 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. --- repository/flickr_public/lib.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/repository/flickr_public/lib.php b/repository/flickr_public/lib.php index adb2c2681ce..19f3a7178a4 100644 --- a/repository/flickr_public/lib.php +++ b/repository/flickr_public/lib.php @@ -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'], ); } }