/** * * @global object $CFG * @param string $photo_id * @param string $file * @return string */ public function get_file($photo_id, $file = '') { global $CFG; $info = $this->flickr->photos_getInfo($photo_id); if ($info['owner']['realname']) { $author = $info['owner']['realname']; } else { $author = $info['owner']['username']; } $copyright = get_string('author', 'repository') . ': ' . $author; $result = $this->flickr->photos_getSizes($photo_id); // download link $source = ''; // flickr photo page $url = ''; if (!empty($result[4])) { $source = $result[4]['source']; $url = $result[4]['url']; } elseif (!empty($result[3])) { $source = $result[3]['source']; $url = $result[3]['url']; } elseif (!empty($result[2])) { $source = $result[2]['source']; $url = $result[2]['url']; } $path = $this->prepare_file($file); $fp = fopen($path, 'w'); $c = new curl(); $c->download(array(array('url' => $source, 'file' => $fp))); // must close file handler, otherwise gd lib will fail to process it fclose($fp); if (!empty($this->usewatermarks)) { $img = new moodle_image($path); $img->watermark($copyright, array(10, 10), array('ttf' => true, 'fontsize' => 12))->saveas($path); } return array('path' => $path, 'url' => $url, 'author' => $info['owner']['realname'], 'license' => $this->license4moodle($info['license'])); }
/** * * @global object $CFG * @param string $photoid * @param string $file * @return string */ 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); } $result = parent::get_file($source, $file); $path = $result['path']; if (!empty($this->usewatermarks)) { $img = new moodle_image($path); $img->watermark($copyright, array(10,10), array('ttf'=>true, 'fontsize'=>12))->saveas($path); } return array('path'=>$path, 'author'=>$info['owner']['realname'], 'license'=>$this->license4moodle($info['license'])); }
/** * * @global object $CFG * @param string $photo_id * @param string $file * @return string */ public function get_file($photo_id, $file = '') { global $CFG; $result = $this->flickr->photos_getSizes($photo_id); $url = ''; if (!empty($result[4])) { $url = $result[4]['source']; } elseif (!empty($result[3])) { $url = $result[3]['source']; } elseif (!empty($result[2])) { $url = $result[2]['source']; } $path = $this->prepare_file($file); $fp = fopen($path, 'w'); $c = new curl(); $c->download(array(array('url' => $url, 'file' => $fp))); $watermark = get_config('flickr_public', 'watermark'); if (!empty($watermark)) { $img = new moodle_image($path); $img->watermark($url, array(10, 10), array('ttf' => true, 'fontsize' => 9))->saveas($path); } return $path; }
} send_file($newfilepath, 'image', 'default', 0, false, true, $imageinfo['mime'], false); } break; } } else { //always give hub logo to anybody if ($filetype == HUB_HUBSCREENSHOT_FILE_TYPE) { $userdir = "hub/0"; $filepath = $CFG->dataroot . '/' . $userdir . '/hublogo'; $imageinfo = getimagesize($filepath, $info); //check if the screenshot exists in the requested size require_once $CFG->dirroot . "/repository/flickr_public/image.php"; $newfilepath = $filepath . "_" . HUBLOGOIMAGEWIDTH . "x" . HUBLOGOIMAGEHEIGHT; if (!file_exists($newfilepath) or filemtime($filepath) > filemtime($newfilepath)) { $image = new moodle_image($filepath); //scale to the max width/height dimension $imagewidth = $imageinfo[0]; $imageheight = $imageinfo[1]; if ($imagewidth > HUBLOGOIMAGEWIDTH) { $imagewidth = $imagewidth / ($imagewidth / HUBLOGOIMAGEWIDTH); $imageheight = $imageheight / ($imagewidth / HUBLOGOIMAGEWIDTH); } if ($imageheight > HUBLOGOIMAGEHEIGHT) { $imageheight = $imageheight / ($imageheight / HUBLOGOIMAGEWIDTH); $imagewidth = $imagewidth / ($imageheight / HUBLOGOIMAGEWIDTH); } $image->resize($imagewidth, $imageheight); $image->saveas($newfilepath); } send_file($newfilepath, 'image', 'default', 0, false, true, $imageinfo['mime'], false);