Skip to content

Commit

Permalink
Merge branch 'MDL-68954-master' of git://github.com/mihailges/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Jun 10, 2020
2 parents 5364577 + e801749 commit 39885e3
Showing 1 changed file with 39 additions and 22 deletions.
61 changes: 39 additions & 22 deletions repository/flickr_public/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,15 @@ public function search($search_text, $page = 0) {
$text = !empty($SESSION->{$this->sess_text}) ? $SESSION->{$this->sess_text} : null;
$nsid = !empty($this->nsid) ? $this->nsid : null;

$photos = $this->flickr->photos_search(array(
'tags'=>$tag,
'page'=>$page,
'per_page'=>24,
'user_id'=>$nsid,
'license'=>$licenses,
'text'=>$text
$photos = $this->flickr->photos_search(
array(
'tags' => $tag,
'page' => $page,
'per_page' => 24,
'user_id' => $nsid,
'license' => $licenses,
'text' => $text,
'media' => 'photos'
)
);
$ret['total'] = $photos['total'];
Expand Down Expand Up @@ -340,6 +342,8 @@ public function get_listing($path = '', $page = 1) {
* @return array
*/
private function build_list($photos, $page = 1, &$ret) {
global $OUTPUT;

if (!empty($this->nsid)) {
$photos_url = $this->flickr->urls_getUserPhotos($this->nsid);
$ret['manage'] = $photos_url;
Expand Down Expand Up @@ -371,16 +375,23 @@ private function build_list($photos, $page = 1, &$ret) {
// append file extension
$p['title'] .= $format;
}
// Get the thumbnail source URL.
$thumbnailsource = $this->flickr->buildPhotoURL($p, 'Square');
if (!@getimagesize($thumbnailsource)) {
// Use the file extension icon as a thumbnail if the original thumbnail does not exist to avoid
// displaying broken thumbnails in the repository.
$thumbnailsource = $OUTPUT->image_url(file_extension_icon($p['title'], 90))->out(false);
}
$ret['list'][] = array(
'title'=>$p['title'],
'source'=>$p['id'],
'id'=>$p['id'],
'thumbnail'=>$this->flickr->buildPhotoURL($p, 'Square'),
'date'=>'',
'size'=>'unknown',
'url'=>'http://www.flickr.com/photos/'.$p['owner'].'/'.$p['id'],
'haslicense'=>true,
'hasauthor'=>true
'title' => $p['title'],
'source' => $p['id'],
'id' => $p['id'],
'thumbnail' => $thumbnailsource,
'date' => '',
'size' => 'unknown',
'url' => 'http://www.flickr.com/photos/' . $p['owner'] . '/' . $p['id'],
'haslicense' => true,
'hasauthor' => true
);
}
}
Expand Down Expand Up @@ -452,20 +463,26 @@ public function get_link($photoid) {
*/
public function get_file($photoid, $file = '') {
global $CFG;

$info = $this->flickr->photos_getInfo($photoid);
if ($info['owner']['realname']) {
$author = $info['owner']['realname'];
} else {
$author = $info['owner']['username'];
}
$copyright = get_string('author', 'repository') . ': ' . $author;

// If we can read the original secret, it means that we have access to the original picture.
if (isset($info['originalsecret'])) {
$source = $this->flickr->buildPhotoURL($info, 'original');
} else {
$source = $this->build_photo_url($photoid);
}
// Make sure the source image exists.
if (!@getimagesize($source)) {
throw new moodle_exception('cannotdownload', 'repository');
}

if ($info['owner']['realname']) {
$author = $info['owner']['realname'];
} else {
$author = $info['owner']['username'];
}
$copyright = get_string('author', 'repository') . ': ' . $author;

$result = parent::get_file($source, $file);
$path = $result['path'];
Expand Down

0 comments on commit 39885e3

Please sign in to comment.