Example #1
0
 /**
  *
  * @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;
 }
Example #2
0
 /**
  *
  * @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']));
 }
Example #3
0
    /**
     *
     * @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']));
    }